Skip to content

Commit a7e5a2a

Browse files
committed
add (undocumented) config flag to opt in to be notified of enter/leave lifecycle events even if the transition does NOT change state
1 parent efb57ea commit a7e5a2a

File tree

11 files changed

+106
-14
lines changed

11 files changed

+106
-14
lines changed

.ackrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--ignore-dir=coverage
2+
--ignore-dir=node_modules
3+
--ignore-dir=.nyc_output
4+

dist/state-machine-visualize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ dotcfg.states = function(config, options) {
167167
dotcfg.transitions = function(config, options) {
168168
var n, max, transition,
169169
init = config.init,
170-
transitions = config.source.transitions || [], // easier to visualize using the ORIGINAL transition declarations rather than our run-time mapping
170+
transitions = config.options.transitions || [], // easier to visualize using the ORIGINAL transition declarations rather than our run-time mapping
171171
output = [];
172172
if (options.init && init.active)
173173
dotcfg.transition(init.name, init.from, init.to, init.dot, config, options, output)
174174
for (n = 0, max = transitions.length ; n < max ; n++) {
175-
transition = config.source.transitions[n]
175+
transition = config.options.transitions[n]
176176
dotcfg.transition(transition.name, transition.from, transition.to, transition.dot, config, options, output)
177177
}
178178
return output

dist/state-machine-visualize.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/state-machine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function Config(options, StateMachine) {
177177

178178
options = options || {};
179179

180-
this.source = options; // preserving original options helps with visualize plugin
180+
this.options = options; // preserving original options can be useful (e.g visualize plugin)
181181
this.defaults = StateMachine.defaults;
182182
this.states = [];
183183
this.transitions = [];
@@ -404,7 +404,7 @@ mixin(JSM.prototype, {
404404
transit: function(transition, from, to, args) {
405405

406406
var lifecycle = this.config.lifecycle,
407-
changed = from !== to;
407+
changed = this.config.options.observeUnchangedState || (from !== to);
408408

409409
if (!to)
410410
return this.context.onInvalidTransition(transition, from, to);

dist/state-machine.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/state-machine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function Config(options, StateMachine) {
177177

178178
options = options || {};
179179

180-
this.source = options; // preserving original options helps with visualize plugin
180+
this.options = options; // preserving original options can be useful (e.g visualize plugin)
181181
this.defaults = StateMachine.defaults;
182182
this.states = [];
183183
this.transitions = [];
@@ -404,7 +404,7 @@ mixin(JSM.prototype, {
404404
transit: function(transition, from, to, args) {
405405

406406
var lifecycle = this.config.lifecycle,
407-
changed = from !== to;
407+
changed = this.config.options.observeUnchangedState || (from !== to);
408408

409409
if (!to)
410410
return this.context.onInvalidTransition(transition, from, to);

lib/visualize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ dotcfg.states = function(config, options) {
167167
dotcfg.transitions = function(config, options) {
168168
var n, max, transition,
169169
init = config.init,
170-
transitions = config.source.transitions || [], // easier to visualize using the ORIGINAL transition declarations rather than our run-time mapping
170+
transitions = config.options.transitions || [], // easier to visualize using the ORIGINAL transition declarations rather than our run-time mapping
171171
output = [];
172172
if (options.init && init.active)
173173
dotcfg.transition(init.name, init.from, init.to, init.dot, config, options, output)
174174
for (n = 0, max = transitions.length ; n < max ; n++) {
175-
transition = config.source.transitions[n]
175+
transition = config.options.transitions[n]
176176
dotcfg.transition(transition.name, transition.from, transition.to, transition.dot, config, options, output)
177177
}
178178
return output

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Config(options, StateMachine) {
1111

1212
options = options || {};
1313

14-
this.source = options; // preserving original options helps with visualize plugin
14+
this.options = options; // preserving original options can be useful (e.g visualize plugin)
1515
this.defaults = StateMachine.defaults;
1616
this.states = [];
1717
this.transitions = [];

src/jsm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mixin(JSM.prototype, {
7171
transit: function(transition, from, to, args) {
7272

7373
var lifecycle = this.config.lifecycle,
74-
changed = from !== to;
74+
changed = this.config.options.observeUnchangedState || (from !== to);
7575

7676
if (!to)
7777
return this.context.onInvalidTransition(transition, from, to);

src/plugin/visualize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ dotcfg.states = function(config, options) {
6464
dotcfg.transitions = function(config, options) {
6565
var n, max, transition,
6666
init = config.init,
67-
transitions = config.source.transitions || [], // easier to visualize using the ORIGINAL transition declarations rather than our run-time mapping
67+
transitions = config.options.transitions || [], // easier to visualize using the ORIGINAL transition declarations rather than our run-time mapping
6868
output = [];
6969
if (options.init && init.active)
7070
dotcfg.transition(init.name, init.from, init.to, init.dot, config, options, output)
7171
for (n = 0, max = transitions.length ; n < max ; n++) {
72-
transition = config.source.transitions[n]
72+
transition = config.options.transitions[n]
7373
dotcfg.transition(transition.name, transition.from, transition.to, transition.dot, config, options, output)
7474
}
7575
return output

0 commit comments

Comments
 (0)