Skip to content

Commit e77988b

Browse files
authored
Merge pull request #1247 from jacwright/behaviors
Adds actions to components
2 parents d4dd015 + 04f5d5c commit e77988b

File tree

33 files changed

+1025
-132
lines changed

33 files changed

+1025
-132
lines changed

src/generators/Generator.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export default class Generator {
9191
components: Set<string>;
9292
events: Set<string>;
9393
transitions: Set<string>;
94+
actions: Set<string>;
9495
importedComponents: Map<string, string>;
9596
namespace: string;
9697
hasComponents: boolean;
@@ -134,6 +135,7 @@ export default class Generator {
134135
this.components = new Set();
135136
this.events = new Set();
136137
this.transitions = new Set();
138+
this.actions = new Set();
137139
this.importedComponents = new Map();
138140
this.slots = new Set();
139141

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

455-
['helpers', 'events', 'components', 'transitions'].forEach(key => {
457+
['helpers', 'events', 'components', 'transitions', 'actions'].forEach(key => {
456458
if (templateProperties[key]) {
457459
templateProperties[key].value.properties.forEach((prop: Node) => {
458460
this[key].add(getName(prop.key));
@@ -636,6 +638,12 @@ export default class Generator {
636638
addDeclaration(getName(property.key), property.value, 'transitions');
637639
});
638640
}
641+
642+
if (templateProperties.actions) {
643+
templateProperties.actions.value.properties.forEach((property: Node) => {
644+
addDeclaration(getName(property.key), property.value, 'actions');
645+
});
646+
}
639647
}
640648

641649
if (indentationLevel) {
@@ -824,6 +832,16 @@ export default class Generator {
824832
this.skip();
825833
}
826834

835+
if (node.type === 'Action' && node.expression) {
836+
node.metadata = contextualise(node.expression, contextDependencies, indexes, false);
837+
if (node.expression.type === 'CallExpression') {
838+
node.expression.arguments.forEach((arg: Node) => {
839+
arg.metadata = contextualise(arg, contextDependencies, indexes, true);
840+
});
841+
}
842+
this.skip();
843+
}
844+
827845
if (node.type === 'Component' && node.name === ':Component') {
828846
node.metadata = contextualise(node.expression, contextDependencies, indexes, false);
829847
}

src/generators/nodes/Action.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Node from './shared/Node';
2+
3+
export default class Action extends Node {
4+
name: string;
5+
value: Node[]
6+
expression: Node
7+
}

0 commit comments

Comments
 (0)