Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jden
committed
Dec 4, 2015
1 parent
9fd5285
commit ead0915
Showing
3 changed files
with
41 additions
and
1 deletion.
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,30 @@ | ||
var StateMachine = require('javascript-state-machine') | ||
// var bind = require('lodash.bind') | ||
|
||
var bind = function (fn, context) { | ||
return function () { | ||
// parameters: event, from, to, ...args | ||
var args = Array.prototype.slice.call(arguments, 3) | ||
return fn.apply(context, args) | ||
} | ||
} | ||
|
||
module.exports.create = function createClientSessionStateMachine (clientSession) { | ||
return StateMachine.create({ | ||
initial: 'initializing', | ||
events: [ | ||
{name: 'initialize', from: 'initializing', to: 'ready'}, | ||
{name: 'leave', from: 'ready', to: 'not ready'}, | ||
{name: 'comeback', from: 'not ready', to: 'ready'}, | ||
{name: 'end', from: ['ready', 'not ready'], to: 'ended'}, | ||
{name: 'abort', from: 'initializing', to: 'ended'} | ||
], | ||
callbacks: { | ||
oninitialize: bind(oninitialize, clientSession) | ||
} | ||
}) | ||
} | ||
|
||
function oninitialize () { | ||
console.log('oninitialize', arguments) | ||
} |
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