Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
Added support for <foreach>. Tested and works.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeard4 committed Jul 20, 2012
1 parent 134d158 commit ec8108c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/core/util/action-code-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var codeGenerators = {
},

"assign" : function(attributes,children){
return attributes.location + " = " + attributes.expr;
return attributes.location + " = " + attributes.expr + ";";
},

"if" : function(attributes,children){
Expand Down Expand Up @@ -108,6 +108,20 @@ var codeGenerators = {
"delay: " + (attributes.delayexpr ? attributes.delayexpr : getDelayInMs(attributes.delay)) + ",\n" +
"sendId: " + (attributes.idlocation ? attributes.idlocation : JSON.stringify(attributes.id)) + "\n" +
"});";
},

"foreach" : function(attributes,children){
var isIndexDefined = attributes.index,
index = attributes.index || "$i", //FIXME: the index variable could shadow the datamodel. We should pick a unique temperorary variable name
item = attributes.item,
arr = attributes.array;

return "(function(){\n" +
"for(" + (isIndexDefined ? "" : "var " + index + " = 0") + "; " + index + " < " + arr + ".length; " + index + "++){\n" +
item + " = " + arr + "[" + index + "];\n" +
children.filter(Array.isArray).map(_generateCode).join("\n;;\n") +
"\n}\n" +
"})();";
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/scxml-test-framework
Submodule scxml-test-framework updated 2 files
+12 −0 test/foreach/test1.json
+51 −0 test/foreach/test1.scxml

0 comments on commit ec8108c

Please sign in to comment.