Skip to content
Browse files

Removed unncessary use of _.bind in calls to forEach and map.

  • Loading branch information...
1 parent ae05b89 commit b09442a2e9f93138a8a6bdeb7f5050c4294c9398 @jbeard4 committed Apr 1, 2012
Showing with 42 additions and 42 deletions.
  1. +36 −36 lib/scxml/SCXML.js
  2. +6 −6 lib/scxml/set/ArraySet.js
View
72 lib/scxml/SCXML.js
@@ -80,11 +80,11 @@ SCXMLInterpreter.prototype = {
//eval top-level scripts
//we treat these differently than other scripts. they get evaled in global scope, and without explicit scripting interface
//this is necessary in order to, e.g., allow js function declarations that are visible to scxml script tags later.
- _(this.model.scripts).forEach(_.bind(function(script){
+ _(this.model.scripts).each(function(script){
/*jsl:ignore*/
with(this._datamodel){ this.opts.globalEval.call(null,script) };
/*jsl:end*/
- },this));
+ },this);
//initialize top-level datamodel expressions. simple eval
for(var k in this._datamodel){
@@ -101,7 +101,7 @@ SCXMLInterpreter.prototype = {
getFullConfiguration : function() {
return _.chain(this._configuration.iter()).
- map(_.bind(function(s){ return [s].concat(this.opts.model.getAncestors(s));},this)).
+ map(function(s){ return [s].concat(this.opts.model.getAncestors(s));},this).
flatten().
map(function(s){return s.id;}).
uniq().
@@ -160,13 +160,13 @@ SCXMLInterpreter.prototype = {
//update history states
if (this.opts.printTrace) console.log("executing state exit actions");
- _.forEach(statesExited,_.bind(function(state){
+ _.each(statesExited,function(state){
if (this.opts.printTrace) console.log("exiting ", state);
- _.forEach(state.onexit,_.bind(function(action){
+ _.each(state.onexit,function(action){
this._evaluateAction(action, eventSet, datamodelForNextStep, eventsToAddToInnerQueue);
- },this));
+ },this);
var f;
if (state.history) {
@@ -182,7 +182,7 @@ SCXMLInterpreter.prototype = {
//update history
this._historyValue[state.history.id] = _.filter(statesExited,f);
}
- },this));
+ },this);
// -> Concurrency: Number of transitions: Multiple
@@ -194,19 +194,19 @@ SCXMLInterpreter.prototype = {
if (this.opts.printTrace) console.log("executing transitition actions");
- _.forEach(sortedTransitions,_.bind(function(transition){
- _.forEach(transition.actions,_.bind(function(action){
+ _.each(sortedTransitions,function(transition){
+ _.each(transition.actions,function(action){
this._evaluateAction(action, eventSet, datamodelForNextStep, eventsToAddToInnerQueue);
- },this));
- },this));
+ },this);
+ },this);
if (this.opts.printTrace) console.log("executing state enter actions");
- _.forEach(statesEntered,_.bind(function(state){
- _.forEach(state.onentry,_.bind(function(action){
+ _.each(statesEntered,function(state){
+ _.each(state.onentry,function(action){
this._evaluateAction(action, eventSet, datamodelForNextStep, eventsToAddToInnerQueue);
- },this));
- },this));
+ },this);
+ },this);
if (this.opts.printTrace) console.log("updating configuration ");
if (this.opts.printTrace) console.log("old configuration ", this._configuration);
@@ -253,19 +253,19 @@ SCXMLInterpreter.prototype = {
}else{
//namelist
if (action.namelist) {
- _.forEach(action.namelist,_.bind(function(name){
+ _.each(action.namelist,function(name){
data[name] = this._datamodel[name];
- },this));
+ },this);
}
//params
- _.forEach(action.params,_.bind(function(param){
+ _.each(action.params,function(param){
if(param.expr){
data[param.name] = this._eval(param.expr, datamodelForNextStep, eventSet);
}else if(param.location){
data[param.name] = this._datamodel[param.location];
}
- },this));
+ },this);
}
return data;
@@ -331,20 +331,20 @@ SCXMLInterpreter.prototype = {
var statesExited = new this.opts.StateSet();
var basicStatesExited = new this.opts.BasicStateSet();
- _.forEach(transitions.iter(),_.bind(function(transition){
+ _.each(transitions.iter(),function(transition){
var lca = this.opts.model.getLCA(transition);
var desc = this.opts.model.getDescendants(lca);
- _.forEach(this._configuration.iter(),_.bind(function(state){
+ _.each(this._configuration.iter(),function(state){
if(_.contains(desc,state)){
basicStatesExited.add(state);
statesExited.add(state);
- _.forEach(this.opts.model.getAncestors(state, lca),function(anc){
+ _.each(this.opts.model.getAncestors(state, lca),function(anc){
statesExited.add(anc);
});
}
- },this));
- },this));
+ },this);
+ },this);
var sortedStatesExited = statesExited.iter().sort(_.bind(function(s1, s2) {
return this.opts.model.getDepth(s2) - this.opts.model.getDepth(s1);
@@ -366,9 +366,9 @@ SCXMLInterpreter.prototype = {
var statesToEnter = new this.opts.StateSet();
var basicStatesToEnter = new this.opts.BasicStateSet();
while (statesToRecursivelyAdd.length) {
- _.forEach(statesToRecursivelyAdd,_.bind(function(state){
+ _.each(statesToRecursivelyAdd,function(state){
this._recursiveAddStatesToEnter(state, statesToEnter, basicStatesToEnter);
- },this));
+ },this);
//add children of parallel states that are not already in statesToEnter to statesToRecursivelyAdd
var childrenOfParallelStatesInStatesToEnter =
@@ -391,9 +391,9 @@ SCXMLInterpreter.prototype = {
_recursiveAddStatesToEnter : function(s, statesToEnter, basicStatesToEnter) {
if (s.kind === stateKinds.HISTORY) {
if (s.id in this._historyValue) {
- _.forEach(this._historyValue[s.id],_.bind(function(historyState){
+ _.each(this._historyValue[s.id],function(historyState){
this._recursiveAddStatesToEnter(historyState, statesToEnter, basicStatesToEnter);
- },this));
+ },this);
} else {
statesToEnter.add(s);
basicStatesToEnter.add(s);
@@ -402,11 +402,11 @@ SCXMLInterpreter.prototype = {
statesToEnter.add(s);
if (s.kind === stateKinds.PARALLEL) {
- _.forEach(s.children,_.bind(function(child){
+ _.each(s.children,function(child){
if(child.kind !== stateKinds.HISTORY){ //don't enter history by default
this._recursiveAddStatesToEnter(child, statesToEnter, basicStatesToEnter);
}
- },this));
+ },this);
} else if (s.kind === stateKinds.COMPOSITE) {
this._recursiveAddStatesToEnter(s.initial, statesToEnter, basicStatesToEnter);
} else if (s.kind === stateKinds.INITIAL || s.kind === stateKinds.BASIC || s.kind === stateKinds.FINAL) {
@@ -424,12 +424,12 @@ SCXMLInterpreter.prototype = {
//get full configuration, unordered
//this means we may select transitions from parents before children
- _.forEach(this._configuration.iter(),_.bind(function(basicState){
+ _.each(this._configuration.iter(),function(basicState){
statesAndParents.add(basicState);
- _.forEach(this.opts.model.getAncestors(basicState),function(ancestor){
+ _.each(this.opts.model.getAncestors(basicState),function(ancestor){
statesAndParents.add(ancestor);
});
- },this));
+ },this);
states = statesAndParents.iter();
}
@@ -445,8 +445,8 @@ SCXMLInterpreter.prototype = {
var transitionSelector = usePrefixMatchingAlgorithm ? scxmlPrefixTransitionSelector : this.opts.transitionSelector;
var enabledTransitions = new this.opts.TransitionSet();
- _.forEach(states,function(state){
- _.forEach(transitionSelector(state,eventNames,e),function(t){
+ _.each(states,function(state){
+ _.each(transitionSelector(state,eventNames,e),function(t){
enabledTransitions.add(t);
});
});
@@ -476,7 +476,7 @@ SCXMLInterpreter.prototype = {
enabledTransitions = new this.opts.TransitionSet(
_.map(
inconsistentTransitionsPairs.iter(),
- _.bind(function(t){return this.opts.priorityComparisonFn(t);},this)));
+ function(t){return this.opts.priorityComparisonFn(t);},this));
tuple = this._getInconsistentTransitions(enabledTransitions);
consistentTransitions = tuple[0];
View
12 lib/scxml/set/ArraySet.js
@@ -18,9 +18,9 @@ module.exports = function(l) {
l = l || [];
this.o = [];
- _.forEach(l,_.bind(function(x){
+ _.each(l,function(x){
this.add(x);
- },this));
+ },this);
};
//TODO: delegate to underscore's union and difference
@@ -42,18 +42,18 @@ module.exports.prototype = {
union : function(l) {
l = l.iter ? l.iter() : l;
- _.forEach(l,_.bind(function(x){
+ _.each(l,function(x){
this.add(x);
- },this));
+ },this);
return this;
},
difference : function(l) {
l = l.iter ? l.iter() : l;
- _.forEach(l,_.bind(function(x){
+ _.each(l,function(x){
this.remove(x);
- },this));
+ },this);
return this;
},

0 comments on commit b09442a

Please sign in to comment.
Something went wrong with that request. Please try again.