This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from bcoe/independent-functions
Merging Independent Functions Feature
- Loading branch information
Showing
7 changed files
with
222 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var fs = require('fs'); | ||
var SandCastle = require('../lib').SandCastle; | ||
|
||
var sandcastle = new SandCastle({ | ||
api: './stateApi.js' | ||
}); | ||
|
||
var script = sandcastle.createScript("\ | ||
exports.main = {\ | ||
foo: function() {\ | ||
setState({ fooName: name });\ | ||
exit('Hello ' + name + '!');\ | ||
},\ | ||
bar: function() {\ | ||
var state = getState();\ | ||
state.barName = name;\ | ||
setState(state);\ | ||
\ | ||
exit('Hello ' + name + '! Your old name was: ' + state.fooName);\ | ||
},\ | ||
hello: function() {\ | ||
var state = getState();\ | ||
exit('Hey ' + name + '! You changed your name from ' + state.fooName + ' to ' + state.barName + '!');\ | ||
}\ | ||
}\ | ||
"); | ||
|
||
script.on('exit', function (err, output, methodName) { | ||
console.log(output); | ||
|
||
run(); | ||
}); | ||
|
||
var start = 0; | ||
var methodsToCall = [ | ||
{ | ||
method: 'foo', | ||
name: 'Foo' | ||
}, | ||
{ | ||
method: 'bar', | ||
name: 'Bar' | ||
}, | ||
{ | ||
method: 'hello', | ||
name: 'Hello' | ||
} | ||
]; | ||
var run = function() { | ||
if (start < methodsToCall.length) { | ||
script.run('main.' + methodsToCall[start].method, { name: methodsToCall[start].name }); | ||
start++; | ||
} | ||
}; | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
exports.api = { | ||
_state: {}, | ||
|
||
getState: function () { | ||
return _state; | ||
}, | ||
|
||
setState: function (state) { | ||
_state = state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.