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

Fix duplicate call to child FSM factory function in a config object #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/machina.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/machina.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/machina.min.js.map

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions spec/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,47 @@ describe( "Machina Namespace Events", function() {
console.log = log;
} );
} );

after( function() {
machina.off( "*" );
} );
} );
describe( "when specifying a factory function", function() {
it( "should only be called once when specified as a function", function() {
var counter = 0;
var child = new machina.Fsm( { states: { uninitialized: {} } } );

new machina.Fsm( {
states: {
uninitialized: {
_child: function() {
counter += 1;
return child;
}
}
}
} );

counter.should.equal( 1 );
} );
it( "should only be called once when specified in a configuration object", function() {
var counter = 0;
var child = new machina.Fsm( { states: { uninitialized: {} } } );

new machina.Fsm( {
states: {
uninitialized: {
_child: {
factory: function() {
counter += 1;
return child;
}
}
}
}
} );

counter.should.equal( 1 );
} );
} );
} );
1 change: 0 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function getChildFsmInstance( config ) {
// is this a config object with a factory?
if ( config.factory ) {
childFsmDefinition = config;
childFsmDefinition.instance = childFsmDefinition.factory();
} else {
// assuming this is a machina instance
childFsmDefinition.factory = function() {
Expand Down