@scion-scxml/core-legacy 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/scion.js CHANGED
@@ -49,198 +49,6 @@
49
49
  s(r[o]);
50
50
  }return s;
51
51
  }({ 1: [function (require, module, exports) {
52
- "use strict";
53
-
54
- var _createClass = function () {
55
- function defineProperties(target, props) {
56
- for (var i = 0; i < props.length; i++) {
57
- var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
58
- }
59
- }return function (Constructor, protoProps, staticProps) {
60
- if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
61
- };
62
- }();
63
-
64
- function _classCallCheck(instance, Constructor) {
65
- if (!(instance instanceof Constructor)) {
66
- throw new TypeError("Cannot call a class as a function");
67
- }
68
- }
69
-
70
- function _possibleConstructorReturn(self, call) {
71
- if (!self) {
72
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
73
- }return call && ((typeof call === "undefined" ? "undefined" : _typeof2(call)) === "object" || typeof call === "function") ? call : self;
74
- }
75
-
76
- function _inherits(subClass, superClass) {
77
- if (typeof superClass !== "function" && superClass !== null) {
78
- throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === "undefined" ? "undefined" : _typeof2(superClass)));
79
- }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
80
- }
81
-
82
- var base = require('@scion-scxml/core-base'),
83
- helpers = base.helpers,
84
- query = base.query,
85
- transitionComparator = base.helpers.transitionComparator;
86
-
87
- /**
88
- * @description Implements SCION legacy semantics. See {@link scion.BaseInterpreter} for information on the constructor arguments.
89
- * @class Statechart
90
- * @extends BaseInterpreter
91
- */
92
-
93
- var Statechart = function (_base$BaseInterpreter) {
94
- _inherits(Statechart, _base$BaseInterpreter);
95
-
96
- function Statechart(modelOrModelFactory, opts) {
97
- _classCallCheck(this, Statechart);
98
-
99
- opts = opts || {};
100
- opts.legacySemantics = true;
101
-
102
- return _possibleConstructorReturn(this, (Statechart.__proto__ || Object.getPrototypeOf(Statechart)).call(this, modelOrModelFactory, opts));
103
- }
104
-
105
- /** @private */
106
-
107
- _createClass(Statechart, [{
108
- key: "_selectTransitions",
109
- value: function _selectTransitions(currentEvent, selectEventlessTransitions) {
110
- if (this.opts.onlySelectFromBasicStates) {
111
- var states = this._configuration.iter();
112
- } else {
113
- var statesAndParents = new this.opts.Set();
114
-
115
- //get full configuration, unordered
116
- //this means we may select transitions from parents before states
117
- var configList = this._configuration.iter();
118
- for (var idx = 0, len = configList.length; idx < len; idx++) {
119
- var basicState = configList[idx];
120
- statesAndParents.add(basicState);
121
- var ancestors = query.getAncestors(basicState);
122
- for (var ancIdx = 0, ancLen = ancestors.length; ancIdx < ancLen; ancIdx++) {
123
- statesAndParents.add(ancestors[ancIdx]);
124
- }
125
- }
126
-
127
- states = statesAndParents.iter();
128
- }
129
-
130
- var transitionSelector = this.opts.transitionSelector;
131
- var enabledTransitions = new this.opts.Set();
132
-
133
- var e = this._evaluateAction.bind(this, currentEvent);
134
-
135
- for (var stateIdx = 0, stateLen = states.length; stateIdx < stateLen; stateIdx++) {
136
- var transitions = states[stateIdx].transitions;
137
- for (var txIdx = 0, len = transitions.length; txIdx < len; txIdx++) {
138
- var t = transitions[txIdx];
139
- if (transitionSelector(t, currentEvent, e, selectEventlessTransitions)) {
140
- enabledTransitions.add(t);
141
- }
142
- }
143
- }
144
-
145
- var priorityEnabledTransitions = this._selectPriorityEnabledTransitions(enabledTransitions);
146
-
147
- this._log("priorityEnabledTransitions", priorityEnabledTransitions);
148
-
149
- return priorityEnabledTransitions;
150
- }
151
-
152
- /** @private */
153
-
154
- }, {
155
- key: "_selectPriorityEnabledTransitions",
156
- value: function _selectPriorityEnabledTransitions(enabledTransitions) {
157
- var priorityEnabledTransitions = new this.opts.Set();
158
-
159
- var tuple = this._getInconsistentTransitions(enabledTransitions),
160
- consistentTransitions = tuple[0],
161
- inconsistentTransitionsPairs = tuple[1];
162
-
163
- priorityEnabledTransitions.union(consistentTransitions);
164
-
165
- this._log("enabledTransitions", enabledTransitions);
166
- this._log("consistentTransitions", consistentTransitions);
167
- this._log("inconsistentTransitionsPairs", inconsistentTransitionsPairs);
168
- this._log("priorityEnabledTransitions", priorityEnabledTransitions);
169
-
170
- while (!inconsistentTransitionsPairs.isEmpty()) {
171
- enabledTransitions = new this.opts.Set(inconsistentTransitionsPairs.iter().map(function (t) {
172
- return this.opts.priorityComparisonFn(t);
173
- }, this));
174
-
175
- tuple = this._getInconsistentTransitions(enabledTransitions);
176
- consistentTransitions = tuple[0];
177
- inconsistentTransitionsPairs = tuple[1];
178
-
179
- priorityEnabledTransitions.union(consistentTransitions);
180
-
181
- this._log("enabledTransitions", enabledTransitions);
182
- this._log("consistentTransitions", consistentTransitions);
183
- this._log("inconsistentTransitionsPairs", inconsistentTransitionsPairs);
184
- this._log("priorityEnabledTransitions", priorityEnabledTransitions);
185
- }
186
- return priorityEnabledTransitions;
187
- }
188
-
189
- /** @private */
190
-
191
- }, {
192
- key: "_getInconsistentTransitions",
193
- value: function _getInconsistentTransitions(transitions) {
194
- var allInconsistentTransitions = new this.opts.Set();
195
- var inconsistentTransitionsPairs = new this.opts.Set();
196
- var transitionList = transitions.iter();
197
-
198
- this._log("transitions", transitions);
199
-
200
- for (var i = 0; i < transitionList.length; i++) {
201
- for (var j = i + 1; j < transitionList.length; j++) {
202
- var t1 = transitionList[i];
203
- var t2 = transitionList[j];
204
- if (this._conflicts(t1, t2)) {
205
- allInconsistentTransitions.add(t1);
206
- allInconsistentTransitions.add(t2);
207
- inconsistentTransitionsPairs.add([t1, t2]);
208
- }
209
- }
210
- }
211
-
212
- var consistentTransitions = transitions.difference(allInconsistentTransitions);
213
- return [consistentTransitions, inconsistentTransitionsPairs];
214
- }
215
- }, {
216
- key: "_conflicts",
217
- value: function _conflicts(t1, t2) {
218
- return !this._isArenaOrthogonal(t1, t2);
219
- }
220
-
221
- /** @private */
222
-
223
- }, {
224
- key: "_isArenaOrthogonal",
225
- value: function _isArenaOrthogonal(t1, t2) {
226
-
227
- this._log("transition scopes", t1.scope, t2.scope);
228
-
229
- var isOrthogonal;
230
- isOrthogonal = query.isOrthogonalTo(t1.scope || t1.source, t2.scope || t2.source);
231
-
232
- this._log("transition scopes are orthogonal?", isOrthogonal);
233
-
234
- return isOrthogonal;
235
- }
236
- }]);
237
-
238
- return Statechart;
239
- }(base.BaseInterpreter);
240
-
241
- base.Statechart = Statechart;
242
- module.exports = base;
243
- }, { "@scion-scxml/core-base": 6 }], 2: [function (require, module, exports) {
244
52
  'use strict';
245
53
 
246
54
  /* begin ArraySet */
@@ -377,7 +185,7 @@
377
185
  };
378
186
 
379
187
  module.exports = ArraySet;
380
- }, {}], 3: [function (require, module, exports) {
188
+ }, {}], 2: [function (require, module, exports) {
381
189
  'use strict';
382
190
 
383
191
  var STATE_TYPES = {
@@ -399,7 +207,7 @@
399
207
  HTTP_IOPROCESSOR_TYPE: HTTP_IOPROCESSOR_TYPE,
400
208
  RX_TRAILING_WILDCARD: RX_TRAILING_WILDCARD
401
209
  };
402
- }, {}], 4: [function (require, module, exports) {
210
+ }, {}], 3: [function (require, module, exports) {
403
211
  'use strict';
404
212
 
405
213
  var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {
@@ -480,7 +288,8 @@
480
288
  transitions: [{
481
289
  target: state
482
290
  }]
483
- }, state]
291
+ }, state],
292
+ modelFnName: state.modelFnName
484
293
  };
485
294
  }
486
295
 
@@ -835,7 +644,9 @@
835
644
  }
836
645
 
837
646
  function initializeModelGeneratorFn(modelFn, opts, interpreter) {
838
- return modelFn.call(interpreter, opts._x, opts._x._sessionid, opts._x._ioprocessors, interpreter.isIn.bind(interpreter));
647
+ var model = modelFn.call(interpreter, opts._x, opts._x._sessionid, opts._x._ioprocessors, interpreter.isIn.bind(interpreter));
648
+ model.modelFnName = modelFn.name;
649
+ return model;
839
650
  }
840
651
 
841
652
  function deserializeSerializedConfiguration(serializedConfiguration, idToStateMap) {
@@ -857,7 +668,7 @@
857
668
  });
858
669
  return o;
859
670
  }
860
- }, { "./constants": 3 }], 5: [function (require, module, exports) {
671
+ }, { "./constants": 2 }], 4: [function (require, module, exports) {
861
672
  'use strict';
862
673
 
863
674
  var constants = require('./constants');
@@ -901,7 +712,7 @@
901
712
  };
902
713
 
903
714
  module.exports = query;
904
- }, { "./constants": 3 }], 6: [function (require, module, exports) {
715
+ }, { "./constants": 2 }], 5: [function (require, module, exports) {
905
716
  (function (process) {
906
717
  // Copyright 2012-2012 Jacob Beard, INFICON, and other SCION contributors
907
718
  //
@@ -1123,6 +934,7 @@
1123
934
  _this._isStepping = false;
1124
935
 
1125
936
  _this._scriptingContext = _this.opts.interpreterScriptingContext || (_this.opts.InterpreterScriptingContext ? new _this.opts.InterpreterScriptingContext(_this) : {});
937
+ _this._scriptingContext._invokeMap = _this.opts._invokeMap || _this._scriptingContext._invokeMap;
1126
938
 
1127
939
  _this.opts.generateSessionid = _this.opts.generateSessionid || BaseInterpreter.generateSessionid;
1128
940
  _this.opts.sessionid = _this.opts.sessionid || _this.opts.generateSessionid();
@@ -1206,7 +1018,11 @@
1206
1018
  _createClass(BaseInterpreter, [{
1207
1019
  key: 'cancel',
1208
1020
  value: function cancel() {
1209
- delete this.opts.parentSession;
1021
+ var _this2 = this;
1022
+
1023
+ setImmediate(function () {
1024
+ return delete _this2.opts.parentSession;
1025
+ }); // run this asynchronously, as we still need a reference to the parent session to send the final <done> event
1210
1026
  if (this._isInFinalState) return;
1211
1027
  this._isInFinalState = true;
1212
1028
  this._log('session cancelled ' + this.opts.invokeid);
@@ -1215,7 +1031,7 @@
1215
1031
  }, {
1216
1032
  key: '_exitInterpreter',
1217
1033
  value: function _exitInterpreter(event) {
1218
- var _this2 = this;
1034
+ var _this3 = this;
1219
1035
 
1220
1036
  //TODO: cancel invoked sessions
1221
1037
  //cancel all delayed sends when we enter into a final state.
@@ -1243,7 +1059,7 @@
1243
1059
 
1244
1060
  //cancel invoked session
1245
1061
  if (stateExited.invokes) stateExited.invokes.forEach(function (invoke) {
1246
- _this2._scriptingContext.cancelInvoke(invoke.id);
1062
+ _this3._scriptingContext.cancelInvoke(invoke.id);
1247
1063
  });
1248
1064
 
1249
1065
  //if he is a top-level <final> state, then return the done event
@@ -1327,7 +1143,7 @@
1327
1143
  }, {
1328
1144
  key: '_initStart',
1329
1145
  value: function _initStart(cb) {
1330
- var _this3 = this;
1146
+ var _this4 = this;
1331
1147
 
1332
1148
  if (typeof cb !== 'function') {
1333
1149
  cb = nop;
@@ -1339,7 +1155,7 @@
1339
1155
  //but if we want it to be parallel, then this becomes more complex. so when initializing the model, we add a 'fake' root state, which
1340
1156
  //makes the following operation safe.
1341
1157
  this._model.initialRef.forEach(function (s) {
1342
- return _this3._configuration.add(s);
1158
+ return _this4._configuration.add(s);
1343
1159
  });
1344
1160
 
1345
1161
  return cb;
@@ -1477,7 +1293,7 @@
1477
1293
  }, {
1478
1294
  key: '_startBigStep',
1479
1295
  value: function _startBigStep(e) {
1480
- var _this4 = this;
1296
+ var _this5 = this;
1481
1297
 
1482
1298
  this.emit('onBigStepBegin', e);
1483
1299
 
@@ -1486,7 +1302,7 @@
1486
1302
  if (state.invokes) state.invokes.forEach(function (invoke) {
1487
1303
  if (invoke.autoforward) {
1488
1304
  //autoforward
1489
- _this4._scriptingContext.send({
1305
+ _this5._scriptingContext.send({
1490
1306
  target: '#_' + invoke.id,
1491
1307
  name: e.name,
1492
1308
  data: e.data
@@ -1495,7 +1311,7 @@
1495
1311
  if (invoke.id === e.invokeid) {
1496
1312
  //applyFinalize
1497
1313
  if (invoke.finalize) invoke.finalize.forEach(function (action) {
1498
- return _this4._evaluateAction(e, action);
1314
+ return _this5._evaluateAction(e, action);
1499
1315
  });
1500
1316
  }
1501
1317
  });
@@ -1512,23 +1328,23 @@
1512
1328
  }, {
1513
1329
  key: '_finishBigStep',
1514
1330
  value: function _finishBigStep(e, allStatesEntered, allStatesExited, cb) {
1515
- var _this5 = this;
1331
+ var _this6 = this;
1516
1332
 
1517
- var statesToInvoke = Array.from(new Set([].concat(_toConsumableArray(allStatesEntered)).filter(function (s) {
1518
- return s.invokes && !allStatesExited.has(s);
1519
- }))).sort(sortInEntryOrder);
1333
+ var statesToInvoke = Array.from(allStatesEntered).filter(function (s) {
1334
+ return s.invokes;
1335
+ }).sort(sortInEntryOrder);
1520
1336
 
1521
1337
  // Here we invoke whatever needs to be invoked. The implementation of 'invoke' is platform-specific
1522
1338
  statesToInvoke.forEach(function (s) {
1523
1339
  s.invokes.forEach(function (f) {
1524
- return _this5._evaluateAction(e, f);
1340
+ return _this6._evaluateAction(e, f);
1525
1341
  });
1526
1342
  });
1527
1343
 
1528
1344
  // cancel invoke for allStatesExited
1529
1345
  allStatesExited.forEach(function (s) {
1530
1346
  if (s.invokes) s.invokes.forEach(function (invoke) {
1531
- _this5._scriptingContext.cancelInvoke(invoke.id);
1347
+ _this6._scriptingContext.cancelInvoke(invoke.id);
1532
1348
  });
1533
1349
  });
1534
1350
 
@@ -1795,7 +1611,7 @@
1795
1611
  }, {
1796
1612
  key: '_enterStates',
1797
1613
  value: function _enterStates(currentEvent, selectedTransitionsWithTargets) {
1798
- var _this6 = this;
1614
+ var _this7 = this;
1799
1615
 
1800
1616
  this._log("entering states");
1801
1617
 
@@ -1899,7 +1715,7 @@
1899
1715
  this._internalEventQueue.push({ name: "done.state." + parent.id, data: stateEntered.donedata && stateEntered.donedata.call(this._scriptingContext, currentEvent) });
1900
1716
  if (grandparent && grandparent.typeEnum === PARALLEL) {
1901
1717
  if (grandparent.states.every(function (s) {
1902
- return _this6.isInFinalState(s);
1718
+ return _this7.isInFinalState(s);
1903
1719
  })) {
1904
1720
  this._internalEventQueue.push({ name: "done.state." + grandparent.id });
1905
1721
  }
@@ -2084,7 +1900,7 @@
2084
1900
  }, {
2085
1901
  key: '_addAncestorStatesToEnter',
2086
1902
  value: function _addAncestorStatesToEnter(state, ancestor, statesToEnter, statesForDefaultEntry, defaultHistoryContent) {
2087
- var _this7 = this;
1903
+ var _this8 = this;
2088
1904
 
2089
1905
  var traverse = function traverse(anc) {
2090
1906
  if (anc.typeEnum === PARALLEL) {
@@ -2099,7 +1915,7 @@
2099
1915
  if (child.typeEnum !== HISTORY && ![].concat(_toConsumableArray(statesToEnter)).some(function (s) {
2100
1916
  return query.isDescendant(s, child);
2101
1917
  })) {
2102
- _this7._addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
1918
+ _this8._addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
2103
1919
  }
2104
1920
  };
2105
1921
 
@@ -2153,7 +1969,7 @@
2153
1969
  }, {
2154
1970
  key: '_addDescendantStatesToEnter',
2155
1971
  value: function _addDescendantStatesToEnter(state, statesToEnter, statesForDefaultEntry, defaultHistoryContent) {
2156
- var _this8 = this;
1972
+ var _this9 = this;
2157
1973
 
2158
1974
  if (state.typeEnum === HISTORY) {
2159
1975
  if (this._historyValue[state.id]) {
@@ -2373,7 +2189,7 @@
2373
2189
  if (child.typeEnum !== HISTORY && ![].concat(_toConsumableArray(statesToEnter)).some(function (s) {
2374
2190
  return query.isDescendant(s, child);
2375
2191
  })) {
2376
- _this8._addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
2192
+ _this9._addDescendantStatesToEnter(child, statesToEnter, statesForDefaultEntry, defaultHistoryContent);
2377
2193
  }
2378
2194
  };
2379
2195
 
@@ -2401,11 +2217,11 @@
2401
2217
  }, {
2402
2218
  key: 'isInFinalState',
2403
2219
  value: function isInFinalState(s) {
2404
- var _this9 = this;
2220
+ var _this10 = this;
2405
2221
 
2406
2222
  if (s.typeEnum === COMPOSITE) {
2407
2223
  return s.states.some(function (s) {
2408
- return s.typeEnum === FINAL && _this9._configuration.contains(s);
2224
+ return s.typeEnum === FINAL && _this10._configuration.contains(s);
2409
2225
  });
2410
2226
  } else if (s.typeEnum === PARALLEL) {
2411
2227
  return s.states.every(this.isInFinalState.bind(this));
@@ -2783,14 +2599,14 @@
2783
2599
  }, {
2784
2600
  key: 'invoke',
2785
2601
  value: function invoke(invokeObj) {
2786
- var _this10 = this;
2602
+ var _this11 = this;
2787
2603
 
2788
2604
  //look up invoker by type. assume invokers are passed in as an option to constructor
2789
2605
  this._invokeMap[invokeObj.id] = new Promise(function (resolve, reject) {
2790
- (_this10._interpreter.opts.invokers || InterpreterScriptingContext.invokers)[invokeObj.type](_this10._interpreter, invokeObj, _this10._interpreter.opts.invokerExecutionContext, function (err, session) {
2606
+ (_this11._interpreter.opts.invokers || InterpreterScriptingContext.invokers)[invokeObj.type](_this11._interpreter, invokeObj, _this11._interpreter.opts.invokerExecutionContext, function (err, session) {
2791
2607
  if (err) return reject(err);
2792
2608
 
2793
- _this10._interpreter.emit('onInvokedSessionInitialized', session);
2609
+ _this11._interpreter.emit('onInvokedSessionInitialized', session);
2794
2610
  resolve(session);
2795
2611
  });
2796
2612
  });
@@ -2798,7 +2614,7 @@
2798
2614
  }, {
2799
2615
  key: 'cancelInvoke',
2800
2616
  value: function cancelInvoke(invokeid) {
2801
- var _this11 = this;
2617
+ var _this12 = this;
2802
2618
 
2803
2619
  //TODO: on cancel invoke clean up this._invokeMap
2804
2620
  var sessionPromise = this._invokeMap[invokeid];
@@ -2806,10 +2622,10 @@
2806
2622
  if (sessionPromise) {
2807
2623
  this._interpreter._log('sessionPromise found');
2808
2624
  sessionPromise.then(function (session) {
2809
- _this11._interpreter._log('resolved session ' + invokeid + '. cancelling... ');
2625
+ _this12._interpreter._log('resolved session ' + invokeid + '. cancelling... ');
2810
2626
  session.cancel();
2811
2627
  //clean up
2812
- delete _this11._invokeMap[invokeid];
2628
+ delete _this12._invokeMap[invokeid];
2813
2629
  }, function (err) {
2814
2630
  //TODO: dispatch error back into the state machine as error.communication
2815
2631
  });
@@ -2854,7 +2670,7 @@
2854
2670
  }
2855
2671
 
2856
2672
  function defaultSendAction(event, options) {
2857
- var _this12 = this;
2673
+ var _this13 = this;
2858
2674
 
2859
2675
  if (typeof setTimeout === 'undefined') throw new Error('Default implementation of BaseInterpreter.prototype.send will not work unless setTimeout is defined globally.');
2860
2676
 
@@ -2886,7 +2702,7 @@
2886
2702
  //TODO: test this code path.
2887
2703
  var invokeId = match[1];
2888
2704
  this._invokeMap[invokeId].then(function (session) {
2889
- doSend.call(_this12, session);
2705
+ doSend.call(_this13, session);
2890
2706
  });
2891
2707
  } else {
2892
2708
  throw new Error('Unrecognized send target.'); //TODO: dispatch error back into the state machine
@@ -2900,8 +2716,9 @@
2900
2716
  var timeoutHandle = setTimeout(function () {
2901
2717
  if (event.sendid) delete this._timeoutMap[event.sendid];
2902
2718
  this._timeouts.delete(timeoutOptions);
2903
- if (this._interpreter.opts.doSend) {
2904
- this._interpreter.opts.doSend(session, event);
2719
+ var _doSend = this._interpreter.opts.doSend || BaseInterpreter.doSend;
2720
+ if (_doSend) {
2721
+ _doSend(session, event);
2905
2722
  } else {
2906
2723
  session[this._interpreter.opts.sendAsync ? 'genAsync' : 'gen'](event);
2907
2724
  }
@@ -2966,34 +2783,302 @@
2966
2783
  query: query
2967
2784
  });
2968
2785
  }).call(this, require('_process'));
2969
- }, { "./ArraySet": 2, "./constants": 3, "./helpers": 4, "./query": 5, "_process": 7, "tiny-events": 8, "util": 11 }], 7: [function (require, module, exports) {
2970
- // shim for using process in browser
2971
- var process = module.exports = {};
2786
+ }, { "./ArraySet": 1, "./constants": 2, "./helpers": 3, "./query": 4, "_process": 8, "tiny-events": 6, "util": 11 }], 6: [function (require, module, exports) {
2787
+ function EventEmitter() {
2788
+ this._listeners = {};
2789
+ }
2972
2790
 
2973
- // cached from whatever global is present so that test runners that stub it
2974
- // don't break things. But we need to wrap it in a try catch in case it is
2975
- // wrapped in strict mode code which doesn't define any globals. It's inside a
2976
- // function because try/catches deoptimize in certain engines.
2791
+ EventEmitter.prototype.on = function _on(type, listener) {
2792
+ if (!Array.isArray(this._listeners[type])) {
2793
+ this._listeners[type] = [];
2794
+ }
2977
2795
 
2978
- var cachedSetTimeout;
2979
- var cachedClearTimeout;
2796
+ if (this._listeners[type].indexOf(listener) === -1) {
2797
+ this._listeners[type].push(listener);
2798
+ }
2980
2799
 
2981
- function defaultSetTimout() {
2982
- throw new Error('setTimeout has not been defined');
2983
- }
2984
- function defaultClearTimeout() {
2985
- throw new Error('clearTimeout has not been defined');
2986
- }
2987
- (function () {
2988
- try {
2989
- if (typeof setTimeout === 'function') {
2990
- cachedSetTimeout = setTimeout;
2991
- } else {
2992
- cachedSetTimeout = defaultSetTimout;
2800
+ return this;
2801
+ };
2802
+
2803
+ EventEmitter.prototype.once = function _once(type, listener) {
2804
+ var self = this;
2805
+
2806
+ function __once() {
2807
+ for (var args = [], i = 0; i < arguments.length; i += 1) {
2808
+ args[i] = arguments[i];
2993
2809
  }
2994
- } catch (e) {
2995
- cachedSetTimeout = defaultSetTimout;
2996
- }
2810
+
2811
+ self.off(type, __once);
2812
+ listener.apply(self, args);
2813
+ }
2814
+
2815
+ __once.listener = listener;
2816
+
2817
+ return this.on(type, __once);
2818
+ };
2819
+
2820
+ EventEmitter.prototype.off = function _off(type, listener) {
2821
+ if (!Array.isArray(this._listeners[type])) {
2822
+ return this;
2823
+ }
2824
+
2825
+ if (typeof listener === 'undefined') {
2826
+ this._listeners[type] = [];
2827
+ return this;
2828
+ }
2829
+
2830
+ var index = this._listeners[type].indexOf(listener);
2831
+
2832
+ if (index === -1) {
2833
+ for (var i = 0; i < this._listeners[type].length; i += 1) {
2834
+ if (this._listeners[type][i].listener === listener) {
2835
+ index = i;
2836
+ break;
2837
+ }
2838
+ }
2839
+ }
2840
+
2841
+ this._listeners[type].splice(index, 1);
2842
+ return this;
2843
+ };
2844
+
2845
+ EventEmitter.prototype.emit = function _emit(type) {
2846
+ if (!Array.isArray(this._listeners[type])) {
2847
+ return this;
2848
+ }
2849
+
2850
+ for (var args = [], i = 1; i < arguments.length; i += 1) {
2851
+ args[i - 1] = arguments[i];
2852
+ }
2853
+
2854
+ this._listeners[type].forEach(function __emit(listener) {
2855
+ listener.apply(this, args);
2856
+ }, this);
2857
+
2858
+ return this;
2859
+ };
2860
+
2861
+ module.exports.EventEmitter = EventEmitter;
2862
+ }, {}], 7: [function (require, module, exports) {
2863
+ "use strict";
2864
+
2865
+ var _createClass = function () {
2866
+ function defineProperties(target, props) {
2867
+ for (var i = 0; i < props.length; i++) {
2868
+ var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
2869
+ }
2870
+ }return function (Constructor, protoProps, staticProps) {
2871
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
2872
+ };
2873
+ }();
2874
+
2875
+ function _classCallCheck(instance, Constructor) {
2876
+ if (!(instance instanceof Constructor)) {
2877
+ throw new TypeError("Cannot call a class as a function");
2878
+ }
2879
+ }
2880
+
2881
+ function _possibleConstructorReturn(self, call) {
2882
+ if (!self) {
2883
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2884
+ }return call && ((typeof call === "undefined" ? "undefined" : _typeof2(call)) === "object" || typeof call === "function") ? call : self;
2885
+ }
2886
+
2887
+ function _inherits(subClass, superClass) {
2888
+ if (typeof superClass !== "function" && superClass !== null) {
2889
+ throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === "undefined" ? "undefined" : _typeof2(superClass)));
2890
+ }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
2891
+ }
2892
+
2893
+ var base = require('@scion-scxml/core-base'),
2894
+ helpers = base.helpers,
2895
+ query = base.query,
2896
+ transitionComparator = base.helpers.transitionComparator;
2897
+
2898
+ /**
2899
+ * @description Implements SCION legacy semantics. See {@link scion.BaseInterpreter} for information on the constructor arguments.
2900
+ * @class Statechart
2901
+ * @extends BaseInterpreter
2902
+ */
2903
+
2904
+ var Statechart = function (_base$BaseInterpreter) {
2905
+ _inherits(Statechart, _base$BaseInterpreter);
2906
+
2907
+ function Statechart(modelOrModelFactory, opts) {
2908
+ _classCallCheck(this, Statechart);
2909
+
2910
+ opts = opts || {};
2911
+ opts.legacySemantics = true;
2912
+
2913
+ return _possibleConstructorReturn(this, (Statechart.__proto__ || Object.getPrototypeOf(Statechart)).call(this, modelOrModelFactory, opts));
2914
+ }
2915
+
2916
+ /** @private */
2917
+
2918
+ _createClass(Statechart, [{
2919
+ key: "_selectTransitions",
2920
+ value: function _selectTransitions(currentEvent, selectEventlessTransitions) {
2921
+ if (this.opts.onlySelectFromBasicStates) {
2922
+ var states = this._configuration.iter();
2923
+ } else {
2924
+ var statesAndParents = new this.opts.Set();
2925
+
2926
+ //get full configuration, unordered
2927
+ //this means we may select transitions from parents before states
2928
+ var configList = this._configuration.iter();
2929
+ for (var idx = 0, len = configList.length; idx < len; idx++) {
2930
+ var basicState = configList[idx];
2931
+ statesAndParents.add(basicState);
2932
+ var ancestors = query.getAncestors(basicState);
2933
+ for (var ancIdx = 0, ancLen = ancestors.length; ancIdx < ancLen; ancIdx++) {
2934
+ statesAndParents.add(ancestors[ancIdx]);
2935
+ }
2936
+ }
2937
+
2938
+ states = statesAndParents.iter();
2939
+ }
2940
+
2941
+ var transitionSelector = this.opts.transitionSelector;
2942
+ var enabledTransitions = new this.opts.Set();
2943
+
2944
+ var e = this._evaluateAction.bind(this, currentEvent);
2945
+
2946
+ for (var stateIdx = 0, stateLen = states.length; stateIdx < stateLen; stateIdx++) {
2947
+ var transitions = states[stateIdx].transitions;
2948
+ for (var txIdx = 0, len = transitions.length; txIdx < len; txIdx++) {
2949
+ var t = transitions[txIdx];
2950
+ if (transitionSelector(t, currentEvent, e, selectEventlessTransitions)) {
2951
+ enabledTransitions.add(t);
2952
+ }
2953
+ }
2954
+ }
2955
+
2956
+ var priorityEnabledTransitions = this._selectPriorityEnabledTransitions(enabledTransitions);
2957
+
2958
+ this._log("priorityEnabledTransitions", priorityEnabledTransitions);
2959
+
2960
+ return priorityEnabledTransitions;
2961
+ }
2962
+
2963
+ /** @private */
2964
+
2965
+ }, {
2966
+ key: "_selectPriorityEnabledTransitions",
2967
+ value: function _selectPriorityEnabledTransitions(enabledTransitions) {
2968
+ var priorityEnabledTransitions = new this.opts.Set();
2969
+
2970
+ var tuple = this._getInconsistentTransitions(enabledTransitions),
2971
+ consistentTransitions = tuple[0],
2972
+ inconsistentTransitionsPairs = tuple[1];
2973
+
2974
+ priorityEnabledTransitions.union(consistentTransitions);
2975
+
2976
+ this._log("enabledTransitions", enabledTransitions);
2977
+ this._log("consistentTransitions", consistentTransitions);
2978
+ this._log("inconsistentTransitionsPairs", inconsistentTransitionsPairs);
2979
+ this._log("priorityEnabledTransitions", priorityEnabledTransitions);
2980
+
2981
+ while (!inconsistentTransitionsPairs.isEmpty()) {
2982
+ enabledTransitions = new this.opts.Set(inconsistentTransitionsPairs.iter().map(function (t) {
2983
+ return this.opts.priorityComparisonFn(t);
2984
+ }, this));
2985
+
2986
+ tuple = this._getInconsistentTransitions(enabledTransitions);
2987
+ consistentTransitions = tuple[0];
2988
+ inconsistentTransitionsPairs = tuple[1];
2989
+
2990
+ priorityEnabledTransitions.union(consistentTransitions);
2991
+
2992
+ this._log("enabledTransitions", enabledTransitions);
2993
+ this._log("consistentTransitions", consistentTransitions);
2994
+ this._log("inconsistentTransitionsPairs", inconsistentTransitionsPairs);
2995
+ this._log("priorityEnabledTransitions", priorityEnabledTransitions);
2996
+ }
2997
+ return priorityEnabledTransitions;
2998
+ }
2999
+
3000
+ /** @private */
3001
+
3002
+ }, {
3003
+ key: "_getInconsistentTransitions",
3004
+ value: function _getInconsistentTransitions(transitions) {
3005
+ var allInconsistentTransitions = new this.opts.Set();
3006
+ var inconsistentTransitionsPairs = new this.opts.Set();
3007
+ var transitionList = transitions.iter();
3008
+
3009
+ this._log("transitions", transitions);
3010
+
3011
+ for (var i = 0; i < transitionList.length; i++) {
3012
+ for (var j = i + 1; j < transitionList.length; j++) {
3013
+ var t1 = transitionList[i];
3014
+ var t2 = transitionList[j];
3015
+ if (this._conflicts(t1, t2)) {
3016
+ allInconsistentTransitions.add(t1);
3017
+ allInconsistentTransitions.add(t2);
3018
+ inconsistentTransitionsPairs.add([t1, t2]);
3019
+ }
3020
+ }
3021
+ }
3022
+
3023
+ var consistentTransitions = transitions.difference(allInconsistentTransitions);
3024
+ return [consistentTransitions, inconsistentTransitionsPairs];
3025
+ }
3026
+ }, {
3027
+ key: "_conflicts",
3028
+ value: function _conflicts(t1, t2) {
3029
+ return !this._isArenaOrthogonal(t1, t2);
3030
+ }
3031
+
3032
+ /** @private */
3033
+
3034
+ }, {
3035
+ key: "_isArenaOrthogonal",
3036
+ value: function _isArenaOrthogonal(t1, t2) {
3037
+
3038
+ this._log("transition scopes", t1.scope, t2.scope);
3039
+
3040
+ var isOrthogonal;
3041
+ isOrthogonal = query.isOrthogonalTo(t1.scope || t1.source, t2.scope || t2.source);
3042
+
3043
+ this._log("transition scopes are orthogonal?", isOrthogonal);
3044
+
3045
+ return isOrthogonal;
3046
+ }
3047
+ }]);
3048
+
3049
+ return Statechart;
3050
+ }(base.BaseInterpreter);
3051
+
3052
+ base.Statechart = Statechart;
3053
+ module.exports = base;
3054
+ }, { "@scion-scxml/core-base": 5 }], 8: [function (require, module, exports) {
3055
+ // shim for using process in browser
3056
+ var process = module.exports = {};
3057
+
3058
+ // cached from whatever global is present so that test runners that stub it
3059
+ // don't break things. But we need to wrap it in a try catch in case it is
3060
+ // wrapped in strict mode code which doesn't define any globals. It's inside a
3061
+ // function because try/catches deoptimize in certain engines.
3062
+
3063
+ var cachedSetTimeout;
3064
+ var cachedClearTimeout;
3065
+
3066
+ function defaultSetTimout() {
3067
+ throw new Error('setTimeout has not been defined');
3068
+ }
3069
+ function defaultClearTimeout() {
3070
+ throw new Error('clearTimeout has not been defined');
3071
+ }
3072
+ (function () {
3073
+ try {
3074
+ if (typeof setTimeout === 'function') {
3075
+ cachedSetTimeout = setTimeout;
3076
+ } else {
3077
+ cachedSetTimeout = defaultSetTimout;
3078
+ }
3079
+ } catch (e) {
3080
+ cachedSetTimeout = defaultSetTimout;
3081
+ }
2997
3082
  try {
2998
3083
  if (typeof clearTimeout === 'function') {
2999
3084
  cachedClearTimeout = clearTimeout;
@@ -3152,82 +3237,6 @@
3152
3237
  process.umask = function () {
3153
3238
  return 0;
3154
3239
  };
3155
- }, {}], 8: [function (require, module, exports) {
3156
- function EventEmitter() {
3157
- this._listeners = {};
3158
- }
3159
-
3160
- EventEmitter.prototype.on = function _on(type, listener) {
3161
- if (!Array.isArray(this._listeners[type])) {
3162
- this._listeners[type] = [];
3163
- }
3164
-
3165
- if (this._listeners[type].indexOf(listener) === -1) {
3166
- this._listeners[type].push(listener);
3167
- }
3168
-
3169
- return this;
3170
- };
3171
-
3172
- EventEmitter.prototype.once = function _once(type, listener) {
3173
- var self = this;
3174
-
3175
- function __once() {
3176
- for (var args = [], i = 0; i < arguments.length; i += 1) {
3177
- args[i] = arguments[i];
3178
- }
3179
-
3180
- self.off(type, __once);
3181
- listener.apply(self, args);
3182
- }
3183
-
3184
- __once.listener = listener;
3185
-
3186
- return this.on(type, __once);
3187
- };
3188
-
3189
- EventEmitter.prototype.off = function _off(type, listener) {
3190
- if (!Array.isArray(this._listeners[type])) {
3191
- return this;
3192
- }
3193
-
3194
- if (typeof listener === 'undefined') {
3195
- this._listeners[type] = [];
3196
- return this;
3197
- }
3198
-
3199
- var index = this._listeners[type].indexOf(listener);
3200
-
3201
- if (index === -1) {
3202
- for (var i = 0; i < this._listeners[type].length; i += 1) {
3203
- if (this._listeners[type][i].listener === listener) {
3204
- index = i;
3205
- break;
3206
- }
3207
- }
3208
- }
3209
-
3210
- this._listeners[type].splice(index, 1);
3211
- return this;
3212
- };
3213
-
3214
- EventEmitter.prototype.emit = function _emit(type) {
3215
- if (!Array.isArray(this._listeners[type])) {
3216
- return this;
3217
- }
3218
-
3219
- for (var args = [], i = 1; i < arguments.length; i += 1) {
3220
- args[i - 1] = arguments[i];
3221
- }
3222
-
3223
- this._listeners[type].forEach(function __emit(listener) {
3224
- listener.apply(this, args);
3225
- }, this);
3226
-
3227
- return this;
3228
- };
3229
-
3230
- module.exports.EventEmitter = EventEmitter;
3231
3240
  }, {}], 9: [function (require, module, exports) {
3232
3241
  if (typeof Object.create === 'function') {
3233
3242
  // implementation from standard node.js 'util' module
@@ -3803,7 +3812,7 @@
3803
3812
  return Object.prototype.hasOwnProperty.call(obj, prop);
3804
3813
  }
3805
3814
  }).call(this, require('_process'), typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
3806
- }, { "./support/isBuffer": 10, "_process": 7, "inherits": 9 }] }, {}, [1])(1);
3815
+ }, { "./support/isBuffer": 10, "_process": 8, "inherits": 9 }] }, {}, [7])(7);
3807
3816
  });
3808
3817
  });
3809
3818
  //# sourceMappingURL=scion.js.map