Skip to content

Commit

Permalink
Merge pull request #1247 from jacwright/behaviors
Browse files Browse the repository at this point in the history
Adds actions to components
  • Loading branch information
Rich-Harris authored Mar 24, 2018
2 parents d4dd015 + 04f5d5c commit e77988b
Show file tree
Hide file tree
Showing 33 changed files with 1,025 additions and 132 deletions.
20 changes: 19 additions & 1 deletion src/generators/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default class Generator {
components: Set<string>;
events: Set<string>;
transitions: Set<string>;
actions: Set<string>;
importedComponents: Map<string, string>;
namespace: string;
hasComponents: boolean;
Expand Down Expand Up @@ -134,6 +135,7 @@ export default class Generator {
this.components = new Set();
this.events = new Set();
this.transitions = new Set();
this.actions = new Set();
this.importedComponents = new Map();
this.slots = new Set();

Expand Down Expand Up @@ -452,7 +454,7 @@ export default class Generator {
templateProperties[getName(prop.key)] = prop;
});

['helpers', 'events', 'components', 'transitions'].forEach(key => {
['helpers', 'events', 'components', 'transitions', 'actions'].forEach(key => {
if (templateProperties[key]) {
templateProperties[key].value.properties.forEach((prop: Node) => {
this[key].add(getName(prop.key));
Expand Down Expand Up @@ -636,6 +638,12 @@ export default class Generator {
addDeclaration(getName(property.key), property.value, 'transitions');
});
}

if (templateProperties.actions) {
templateProperties.actions.value.properties.forEach((property: Node) => {
addDeclaration(getName(property.key), property.value, 'actions');
});
}
}

if (indentationLevel) {
Expand Down Expand Up @@ -824,6 +832,16 @@ export default class Generator {
this.skip();
}

if (node.type === 'Action' && node.expression) {
node.metadata = contextualise(node.expression, contextDependencies, indexes, false);
if (node.expression.type === 'CallExpression') {
node.expression.arguments.forEach((arg: Node) => {
arg.metadata = contextualise(arg, contextDependencies, indexes, true);
});
}
this.skip();
}

if (node.type === 'Component' && node.name === ':Component') {
node.metadata = contextualise(node.expression, contextDependencies, indexes, false);
}
Expand Down
7 changes: 7 additions & 0 deletions src/generators/nodes/Action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Node from './shared/Node';

export default class Action extends Node {
name: string;
value: Node[]
expression: Node
}
Loading

0 comments on commit e77988b

Please sign in to comment.