-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachina.js
737 lines (667 loc) · 22.5 KB
/
machina.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/*!
* * machina - A library for creating powerful and flexible finite state machines. Loosely inspired by Erlang/OTP's gen_fsm behavior.
* * Author: Jim Cowart (http://ifandelse.com)
* * Version: v2.0.2
* * Url: http://machina-js.org/
* * License(s):
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("lodash"));
else if(typeof define === 'function' && define.amd)
define(["lodash"], factory);
else if(typeof exports === 'object')
exports["machina"] = factory(require("lodash"));
else
root["machina"] = factory(root["_"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
var _ = __webpack_require__( 1 );
var emitter = __webpack_require__( 2 );
module.exports = _.merge( emitter.instance, {
Fsm: __webpack_require__( 5 ),
BehavioralFsm: __webpack_require__( 6 ),
utils: __webpack_require__( 3 ),
eventListeners: {
newFsm: []
}
} );
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
var utils = __webpack_require__( 3 );
var _ = __webpack_require__( 1 );
function getInstance() {
return {
emit: function( eventName ) {
var args = utils.getLeaklessArgs( arguments );
if ( this.eventListeners[ "*" ] ) {
_.each( this.eventListeners[ "*" ], function( callback ) {
if ( !this.useSafeEmit ) {
callback.apply( this, args );
} else {
try {
callback.apply( this, args );
} catch ( exception ) {
/* istanbul ignore else */
if ( console && typeof console.log !== "undefined" ) {
console.log( exception.stack );
}
}
}
}, this );
}
if ( this.eventListeners[ eventName ] ) {
_.each( this.eventListeners[ eventName ], function( callback ) {
if ( !this.useSafeEmit ) {
callback.apply( this, args.slice( 1 ) );
} else {
try {
callback.apply( this, args.slice( 1 ) );
} catch ( exception ) {
/* istanbul ignore else */
if ( console && typeof console.log !== "undefined" ) {
console.log( exception.stack );
}
}
}
}, this );
}
},
on: function( eventName, callback ) {
var self = this;
self.eventListeners = self.eventListeners || { "*": [] };
if ( !self.eventListeners[ eventName ] ) {
self.eventListeners[ eventName ] = [];
}
self.eventListeners[ eventName ].push( callback );
return {
eventName: eventName,
callback: callback,
off: function() {
self.off( eventName, callback );
}
};
},
off: function( eventName, callback ) {
this.eventListeners = this.eventListeners || { "*": [] };
if ( !eventName ) {
this.eventListeners = {};
} else {
if ( callback ) {
this.eventListeners[ eventName ] = _.without( this.eventListeners[ eventName ], callback );
} else {
this.eventListeners[ eventName ] = [];
}
}
}
};
}
module.exports = {
getInstance: getInstance,
instance: getInstance()
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
var slice = [].slice;
var events = __webpack_require__( 4 );
var _ = __webpack_require__( 1 );
var makeFsmNamespace = ( function() {
var machinaCount = 0;
return function() {
return "fsm." + machinaCount++;
};
} )();
function getDefaultBehavioralOptions() {
return {
initialState: "uninitialized",
eventListeners: {
"*": []
},
states: {},
namespace: makeFsmNamespace(),
useSafeEmit: false,
hierarchy: {},
pendingDelegations: {}
};
}
function getDefaultClientMeta() {
return {
inputQueue: [],
targetReplayState: "",
state: undefined,
priorState: undefined,
priorAction: "",
currentAction: "",
currentActionArgs: undefined,
inExitHandler: false
};
}
function getLeaklessArgs( args, startIdx ) {
var result = [];
for ( var i = ( startIdx || 0 ); i < args.length; i++ ) {
result[ i ] = args[ i ];
}
return result;
}
/*
handle ->
child = stateObj._child && stateObj._child.instance;
transition ->
newStateObj._child = getChildFsmInstance( newStateObj._child );
child = newStateObj._child && newStateObj._child.instance;
*/
function getChildFsmInstance( config ) {
if ( !config ) {
return;
}
var childFsmDefinition = {};
if ( typeof config === "object" ) {
// 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() {
return config;
};
}
} else if ( typeof config === "function" ) {
childFsmDefinition.factory = config;
}
childFsmDefinition.instance = childFsmDefinition.factory();
return childFsmDefinition;
}
function listenToChild( fsm, child ) {
// Need to investigate potential for discarded event
// listener memory leak in long-running, deeply-nested hierarchies.
return child.on( "*", function( eventName, data ) {
switch ( eventName ) {
case events.NO_HANDLER:
if ( !data.ticket && !data.delegated && data.namespace !== fsm.namespace ) {
// Ok - we're dealing w/ a child handling input that should bubble up
data.args[ 1 ].bubbling = true;
}
// we do NOT bubble _reset inputs up to the parent
if ( data.inputType !== "_reset" ) {
fsm.handle.apply( fsm, data.args );
}
break;
case events.HANDLING :
var ticket = data.ticket;
if ( ticket && fsm.pendingDelegations[ ticket ] ) {
delete fsm.pendingDelegations[ ticket ];
}
fsm.emit( eventName, data ); // possibly transform payload?
break;
default:
fsm.emit( eventName, data ); // possibly transform payload?
break;
}
} );
}
// _machKeys are members we want to track across the prototype chain of an extended FSM constructor
// Since we want to eventually merge the aggregate of those values onto the instance so that FSMs
// that share the same extended prototype won't share state *on* those prototypes.
var _machKeys = [ "states", "initialState" ];
var extend = function( protoProps, staticProps ) {
var parent = this;
var fsm; // placeholder for instance constructor
var machObj = {}; // object used to hold initialState & states from prototype for instance-level merging
var Ctor = function() {}; // placeholder ctor function used to insert level in prototype chain
// The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent's constructor.
if ( protoProps && protoProps.hasOwnProperty( "constructor" ) ) {
fsm = protoProps.constructor;
} else {
// The default machina constructor (when using inheritance) creates a
// deep copy of the states/initialState values from the prototype and
// extends them over the instance so that they'll be instance-level.
// If an options arg (args[0]) is passed in, a states or intialState
// value will be preferred over any data pulled up from the prototype.
fsm = function() {
var args = slice.call( arguments, 0 );
args[ 0 ] = args[ 0 ] || {};
var blendedState;
var instanceStates = args[ 0 ].states || {};
blendedState = _.merge( _.cloneDeep( machObj ), { states: instanceStates } );
blendedState.initialState = args[ 0 ].initialState || this.initialState;
_.extend( args[ 0 ], blendedState );
parent.apply( this, args );
};
}
// Inherit class (static) properties from parent.
_.merge( fsm, parent );
// Set the prototype chain to inherit from `parent`, without calling
// `parent`'s constructor function.
Ctor.prototype = parent.prototype;
fsm.prototype = new Ctor();
// Add prototype properties (instance properties) to the subclass,
// if supplied.
if ( protoProps ) {
_.extend( fsm.prototype, protoProps );
_.merge( machObj, _.transform( protoProps, function( accum, val, key ) {
if ( _machKeys.indexOf( key ) !== -1 ) {
accum[ key ] = val;
}
} ) );
}
// Add static properties to the constructor function, if supplied.
if ( staticProps ) {
_.merge( fsm, staticProps );
}
// Correctly set child's `prototype.constructor`.
fsm.prototype.constructor = fsm;
// Set a convenience property in case the parent's prototype is needed later.
fsm.__super__ = parent.prototype;
return fsm;
};
function createUUID() {
var s = [];
var hexDigits = "0123456789abcdef";
for ( var i = 0; i < 36; i++ ) {
s[ i ] = hexDigits.substr( Math.floor( Math.random() * 0x10 ), 1 );
}
s[ 14 ] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
/* jshint ignore:start */
s[ 19 ] = hexDigits.substr( ( s[ 19 ] & 0x3 ) | 0x8, 1 ); // bits 6-7 of the clock_seq_hi_and_reserved to 01
/* jshint ignore:end */
s[ 8 ] = s[ 13 ] = s[ 18 ] = s[ 23 ] = "-";
return s.join( "" );
}
module.exports = {
createUUID: createUUID,
extend: extend,
getDefaultBehavioralOptions: getDefaultBehavioralOptions,
getDefaultOptions: getDefaultBehavioralOptions,
getDefaultClientMeta: getDefaultClientMeta,
getChildFsmInstance: getChildFsmInstance,
getLeaklessArgs: getLeaklessArgs,
listenToChild: listenToChild,
makeFsmNamespace: makeFsmNamespace
};
/***/ }),
/* 4 */
/***/ (function(module, exports) {
module.exports = {
NEXT_TRANSITION: "transition",
HANDLING: "handling",
HANDLED: "handled",
NO_HANDLER: "nohandler",
TRANSITION: "transition",
TRANSITIONED: "transitioned",
INVALID_STATE: "invalidstate",
DEFERRED: "deferred",
NEW_FSM: "newfsm"
};
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
var BehavioralFsm = __webpack_require__( 6 );
var utils = __webpack_require__( 3 );
var _ = __webpack_require__( 1 );
var Fsm = {
constructor: function() {
BehavioralFsm.apply( this, arguments );
this.ensureClientMeta();
},
initClient: function initClient() {
var initialState = this.initialState;
if ( !initialState ) {
throw new Error( "You must specify an initial state for this FSM" );
}
if ( !this.states[ initialState ] ) {
throw new Error( "The initial state specified does not exist in the states object." );
}
this.transition( initialState );
},
ensureClientMeta: function ensureClientMeta() {
if ( !this._stamped ) {
this._stamped = true;
_.defaults( this, _.cloneDeep( utils.getDefaultClientMeta() ) );
this.initClient();
}
return this;
},
ensureClientArg: function( args ) {
var _args = args;
// we need to test the args and verify that if a client arg has
// been passed, it must be this FSM instance (this isn't a behavioral FSM)
if ( typeof _args[ 0 ] === "object" && !( "inputType" in _args[ 0 ] ) && _args[ 0 ] !== this ) {
_args.splice( 0, 1, this );
} else if ( typeof _args[ 0 ] !== "object" || ( typeof _args[ 0 ] === "object" && ( "inputType" in _args[ 0 ] ) ) ) {
_args.unshift( this );
}
return _args;
},
getHandlerArgs: function( args, isCatchAll ) {
// index 0 is the client, index 1 is inputType
// if we're in a catch-all handler, input type needs to be included in the args
// inputType might be an object, so we need to just get the inputType string if so
var _args = args;
var input = _args[ 1 ];
if ( typeof inputType === "object" ) {
_args.splice( 1, 1, input.inputType );
}
return isCatchAll ?
_args.slice( 1 ) :
_args.slice( 2 );
},
getSystemHandlerArgs: function( args, client ) {
return args;
},
// "classic" machina FSM do not emit the client property on events (which would be the FSM itself)
buildEventPayload: function() {
var args = this.ensureClientArg( utils.getLeaklessArgs( arguments ) );
var data = args[ 1 ];
if ( _.isPlainObject( data ) ) {
return _.extend( data, { namespace: this.namespace } );
} else {
return { data: data || null, namespace: this.namespace };
}
}
};
_.each( [
"handle",
"transition",
"deferUntilTransition",
"processQueue",
"clearQueue"
], function( methodWithClientInjected ) {
Fsm[ methodWithClientInjected ] = function() {
var args = this.ensureClientArg( utils.getLeaklessArgs( arguments ) );
return BehavioralFsm.prototype[ methodWithClientInjected ].apply( this, args );
};
} );
Fsm = BehavioralFsm.extend( Fsm );
module.exports = Fsm;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
var _ = __webpack_require__( 1 );
var utils = __webpack_require__( 3 );
var emitter = __webpack_require__( 2 );
var topLevelEmitter = emitter.instance;
var events = __webpack_require__( 4 );
var MACHINA_PROP = "__machina__";
function BehavioralFsm( options ) {
_.extend( this, options );
_.defaults( this, utils.getDefaultBehavioralOptions() );
this.initialize.apply( this, arguments );
topLevelEmitter.emit( events.NEW_FSM, this );
}
_.extend( BehavioralFsm.prototype, {
initialize: function() {},
initClient: function initClient( client ) {
var initialState = this.initialState;
if ( !initialState ) {
throw new Error( "You must specify an initial state for this FSM" );
}
if ( !this.states[ initialState ] ) {
throw new Error( "The initial state specified does not exist in the states object." );
}
this.transition( client, initialState );
},
configForState: function configForState( newState ) {
var newStateObj = this.states[ newState ];
var child;
_.each( this.hierarchy, function( childListener, key ) {
if ( childListener && typeof childListener.off === "function" ) {
childListener.off();
}
} );
if ( newStateObj._child ) {
newStateObj._child = utils.getChildFsmInstance( newStateObj._child );
child = newStateObj._child && newStateObj._child.instance;
this.hierarchy[ child.namespace ] = utils.listenToChild( this, child );
}
return child;
},
ensureClientMeta: function ensureClientMeta( client ) {
if ( typeof client !== "object" ) {
throw new Error( "An FSM client must be an object." );
}
client[ MACHINA_PROP ] = client[ MACHINA_PROP ] || {};
if ( !client[ MACHINA_PROP ][ this.namespace ] ) {
client[ MACHINA_PROP ][ this.namespace ] = _.cloneDeep( utils.getDefaultClientMeta() );
this.initClient( client );
}
return client[ MACHINA_PROP ][ this.namespace ];
},
buildEventPayload: function( client, data ) {
if ( _.isPlainObject( data ) ) {
return _.extend( data, { client: client, namespace: this.namespace } );
} else {
return { client: client, data: data || null, namespace: this.namespace };
}
},
getHandlerArgs: function( args, isCatchAll ) {
// index 0 is the client, index 1 is inputType
// if we're in a catch-all handler, input type needs to be included in the args
// inputType might be an object, so we need to just get the inputType string if so
var _args = args.slice( 0 );
var input = _args[ 1 ];
if ( typeof input === "object" ) {
_args.splice( 1, 1, input.inputType );
}
return isCatchAll ?
_args :
[ _args[ 0 ] ].concat( _args.slice( 2 ) );
},
getSystemHandlerArgs: function( args, client ) {
return [ client ].concat( args );
},
handle: function( client, input ) {
var inputDef = input;
if ( typeof input === "undefined" ) {
throw new Error( "The input argument passed to the FSM's handle method is undefined. Did you forget to pass the input name?" );
}
if ( typeof input === "string" ) {
inputDef = { inputType: input, delegated: false, ticket: undefined };
}
var clientMeta = this.ensureClientMeta( client );
var args = utils.getLeaklessArgs( arguments );
if ( typeof input !== "object" ) {
args.splice( 1, 1, inputDef );
}
clientMeta.currentActionArgs = args.slice( 1 );
var currentState = clientMeta.state;
var stateObj = this.states[ currentState ];
var handlerName;
var handler;
var isCatchAll = false;
var child;
var result;
var action;
if ( !clientMeta.inExitHandler ) {
child = this.configForState( currentState );
if ( child && !this.pendingDelegations[ inputDef.ticket ] && !inputDef.bubbling ) {
inputDef.ticket = ( inputDef.ticket || utils.createUUID() );
inputDef.delegated = true;
this.pendingDelegations[ inputDef.ticket ] = { delegatedTo: child.namespace };
// WARNING - returning a value from `handle` on child FSMs is not really supported.
// If you need to return values from child FSM input handlers, use events instead.
result = child.handle.apply( child, args );
} else {
if ( inputDef.ticket && this.pendingDelegations[ inputDef.ticket ] ) {
delete this.pendingDelegations[ inputDef.ticket ];
}
handlerName = stateObj[ inputDef.inputType ] ? inputDef.inputType : "*";
isCatchAll = ( handlerName === "*" );
handler = ( stateObj[ handlerName ] || this[ handlerName ] ) || this[ "*" ];
action = clientMeta.state + "." + handlerName;
clientMeta.currentAction = action;
var eventPayload = this.buildEventPayload(
client,
{ inputType: inputDef.inputType, delegated: inputDef.delegated, ticket: inputDef.ticket }
);
if ( !handler ) {
this.emit( events.NO_HANDLER, _.extend( { args: args }, eventPayload ) );
} else {
this.emit( events.HANDLING, eventPayload );
if ( typeof handler === "function" ) {
result = handler.apply( this, this.getHandlerArgs( args, isCatchAll ) );
} else {
result = handler;
this.transition( client, handler );
}
this.emit( events.HANDLED, eventPayload );
}
clientMeta.priorAction = clientMeta.currentAction;
clientMeta.currentAction = "";
clientMeta.currentActionArgs = undefined;
}
}
return result;
},
transition: function( client, newState ) {
var clientMeta = this.ensureClientMeta( client );
var curState = clientMeta.state;
var curStateObj = this.states[ curState ];
var newStateObj = this.states[ newState ];
var child;
var args = utils.getLeaklessArgs( arguments ).slice( 2 );
if ( !clientMeta.inExitHandler && newState !== curState ) {
if ( newStateObj ) {
child = this.configForState( newState );
if ( curStateObj && curStateObj._onExit ) {
clientMeta.inExitHandler = true;
curStateObj._onExit.call( this, client );
clientMeta.inExitHandler = false;
}
clientMeta.targetReplayState = newState;
clientMeta.priorState = curState;
clientMeta.state = newState;
var eventPayload = this.buildEventPayload( client, {
fromState: clientMeta.priorState,
action: clientMeta.currentAction,
toState: newState
} );
this.emit( events.TRANSITION, eventPayload );
if ( newStateObj._onEnter ) {
newStateObj._onEnter.apply( this, this.getSystemHandlerArgs( args, client ) );
}
this.emit( events.TRANSITIONED, eventPayload );
if ( child ) {
child.handle( client, "_reset" );
}
if ( clientMeta.targetReplayState === newState ) {
this.processQueue( client, events.NEXT_TRANSITION );
}
return;
}
this.emit( events.INVALID_STATE, this.buildEventPayload( client, {
state: clientMeta.state,
attemptedState: newState
} ) );
}
},
deferUntilTransition: function( client, stateName ) {
var clientMeta = this.ensureClientMeta( client );
if ( clientMeta.currentActionArgs ) {
var queued = {
type: events.NEXT_TRANSITION,
untilState: stateName,
args: clientMeta.currentActionArgs
};
clientMeta.inputQueue.push( queued );
var eventPayload = this.buildEventPayload( client, {
state: clientMeta.state,
queuedArgs: queued
} );
this.emit( events.DEFERRED, eventPayload );
}
},
deferAndTransition: function( client, stateName ) {
this.deferUntilTransition( client, stateName );
this.transition( client, stateName );
},
processQueue: function( client ) {
var clientMeta = this.ensureClientMeta( client );
var filterFn = function( item ) {
return ( ( !item.untilState ) || ( item.untilState === clientMeta.state ) );
};
var toProcess = _.filter( clientMeta.inputQueue, filterFn );
clientMeta.inputQueue = _.difference( clientMeta.inputQueue, toProcess );
_.each( toProcess, function( item ) {
this.handle.apply( this, [ client ].concat( item.args ) );
}.bind( this ) );
},
clearQueue: function( client, name ) {
var clientMeta = this.ensureClientMeta( client );
if ( !name ) {
clientMeta.inputQueue = [];
} else {
var filter = function( evnt ) {
return ( name ? evnt.untilState !== name : true );
};
clientMeta.inputQueue = _.filter( clientMeta.inputQueue, filter );
}
},
compositeState: function( client ) {
var clientMeta = this.ensureClientMeta( client );
var state = clientMeta.state;
var child = this.states[state]._child && this.states[state]._child.instance;
if ( child ) {
state += "." + child.compositeState( client );
}
return state;
}
}, emitter.getInstance() );
BehavioralFsm.extend = utils.extend;
module.exports = BehavioralFsm;
/***/ })
/******/ ])
});
;