Skip to content

Commit 8e9ca59

Browse files
add support for '*' transition entry (#13)
Co-authored-by: Renée Kooi <renee@kooi.me>
1 parent cfdea4b commit 8e9ca59

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,10 @@ Nanostate.prototype._next = function (eventName) {
6262
return submachine.state
6363
}
6464

65+
if (!Object.prototype.hasOwnProperty.call(this.transitions[this.state], eventName) &&
66+
Object.prototype.hasOwnProperty.call(this.transitions, '*')) {
67+
return this.transitions['*'][eventName]
68+
}
69+
6570
return this.transitions[this.state][eventName]
6671
}

test/nanostate.js

+21
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,24 @@ tape('emit events', function (assert) {
4040

4141
machine.emit('click')
4242
})
43+
44+
tape('global transitions', function (assert) {
45+
var machine = nanostate('green', {
46+
'*': { stop: 'red' },
47+
green: { toYellow: 'yellow' },
48+
yellow: { toRed: 'red' },
49+
red: { toGreen: 'green' }
50+
})
51+
52+
move(assert, machine, [
53+
['toYellow', 'yellow'],
54+
['stop', 'red'],
55+
['toGreen', 'green'],
56+
['stop', 'red'],
57+
['toGreen', 'green'],
58+
['toYellow', 'yellow'],
59+
['toRed', 'red'],
60+
['stop', 'red']
61+
])
62+
assert.end()
63+
})

0 commit comments

Comments
 (0)