Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,15 @@
this.__transitions__ = [];
this.trace = false;

// attach to __instances so external tools can access this instance
if (opts.track) { State.instances.push(this); }

if (f) { f.call(this); }
}

// Public: exposes state instances that have been given `track: true` in `opt`.
State.instances = [];

// Public: Convenience method for creating a new statechart. Simply creates a
// root state and invokes the given function in the context of that state.
//
Expand Down
5 changes: 5 additions & 0 deletions spec/statechart_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ describe('State constructor function', function() {
s = new State('x', {H: true}, f);
expect(context).toBe(s);
});

it('should push the state onto `instances` via setting `track` to `true`', function() {
var s = new State('a', { track: true });
expect(State.instances).toEqual([s])
});
});

describe('State#addSubstate', function() {
Expand Down