Skip to content

[POC] Add resolveDemoImports#29733

Closed
Janpot wants to merge 2 commits intomasterfrom
live-demos
Closed

[POC] Add resolveDemoImports#29733
Janpot wants to merge 2 commits intomasterfrom
live-demos

Conversation

@Janpot
Copy link
Member

@Janpot Janpot commented Nov 17, 2021

Alternative strategy to handle demo imports from #24640
We could generate a resolveImports function that can be directly consumed by jarle. It's probably good enough to have one function for the whole docs page. alternatively we could generate one per demo, but I'm not sure how much that would confuse webpack.

@mui-pr-bot
Copy link

mui-pr-bot commented Nov 17, 2021

No bundle size changes

Generated by 🚫 dangerJS against dda1420

module: moduleID,
raw: await fs.readFile(moduleFilepath, { encoding: 'utf-8' }),
};
const raw = await fs.readFile(moduleFilepath, { encoding: 'utf-8' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Janpot Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assigning the demo source to a variable so that I can analyse it later for import statements. That way I don't have to read it twice from the file system.

})
.join('\n')}};

export async function resolveDemoImports(requests) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Janpot From what I understood, this function will dynamically import the modules for each demo when called (presumably in the resolveImports prop, like this?).

I'm not sure what the value of the requests parameter will be when the function is called - is it the list of imports of that demo? If yes, should we also add a an export const imports = ${JSON.stringify(Array.from(demoImportedModuleIDs)};?

Copy link
Member Author

@Janpot Janpot Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can have two signatures. You can see here: https://jquense.github.io/jarle/#resolveImports
requests is just an array of module identifiers that jarle wants to have resolved.

You can just import that function here and pass it down to MarkdownDocs to get it in the demo component where you can directly pass it to jarle

@bharatkashyap bharatkashyap mentioned this pull request Nov 25, 2021
20 tasks
@Janpot Janpot closed this Nov 25, 2021
@Janpot Janpot deleted the live-demos branch November 25, 2021 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants