Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dynamic components #971

Merged
merged 11 commits into from
Dec 7, 2017
4 changes: 4 additions & 0 deletions src/generators/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ export default class Generator {
node.metadata = contextualise(node.expression, contextDependencies, indexes);
this.skip();
}

if (node.type === 'Element' && node.name === ':Component') {
node.metadata = contextualise(node.expression, contextDependencies, indexes);
}
},

leave(node: Node, parent: Node) {
Expand Down
9 changes: 7 additions & 2 deletions src/generators/dom/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ const preprocessors = {
) => {
cannotUseInnerHTML(node);
node.var = block.getUniqueName(`each`);
node.iterations = block.getUniqueName(`${node.var}_blocks`);

const { dependencies } = node.metadata;
block.addDependencies(dependencies);
Expand Down Expand Up @@ -436,13 +437,17 @@ const preprocessors = {
}

const isComponent =
generator.components.has(node.name) || node.name === ':Self';
generator.components.has(node.name) || node.name === ':Self' || node.name === ':Component';

if (isComponent) {
cannotUseInnerHTML(node);

node.var = block.getUniqueName(
(node.name === ':Self' ? generator.name : node.name).toLowerCase()
(
node.name === ':Self' ? generator.name :
node.name === ':Component' ? 'switch_instance' :
node.name
).toLowerCase()
);

node._state = getChildState(state, {
Expand Down
Loading