@@ -10,9 +10,8 @@ export let d = {};
10
10
let truthy = ( ) => true ;
11
11
let empty = ( ) => ( { } ) ;
12
12
let identity = a => a ;
13
- let identity2 = ( a , b ) => b ;
14
13
let callBoth = ( par , fn , self , args ) => par . apply ( self , args ) && fn . apply ( self , args ) ;
15
- let callForward = ( par , fn , self , [ a , b ] ) => fn . call ( self , a , par . call ( self , a , b ) ) ;
14
+ let callForward = ( par , fn , self , [ a , b ] ) => fn . call ( self , par . call ( self , a , b ) , b ) ;
16
15
let create = ( a , b ) => Object . freeze ( Object . create ( a , b ) ) ;
17
16
18
17
function stack ( fns , def , caller ) {
@@ -27,9 +26,6 @@ function fnType(fn) {
27
26
return create ( this , { fn : valueEnumerable ( fn ) } ) ;
28
27
}
29
28
30
- let actionType = { } ;
31
- export let action = fnType . bind ( actionType ) ;
32
-
33
29
let reduceType = { } ;
34
30
export let reduce = fnType . bind ( reduceType ) ;
35
31
@@ -42,7 +38,7 @@ function filter(Type, arr) {
42
38
43
39
function extractActions ( args ) {
44
40
let guards = stack ( filter ( guardType , args ) . map ( t => t . fn ) , truthy , callBoth ) ;
45
- let reducers = stack ( filter ( reduceType , args ) . map ( t => t . fn ) , identity2 , callForward ) ;
41
+ let reducers = stack ( filter ( reduceType , args ) . map ( t => t . fn ) , identity , callForward ) ;
46
42
return [ guards , reducers ] ;
47
43
}
48
44
@@ -105,7 +101,7 @@ let invokeType = {
105
101
} ;
106
102
function machineToPromise ( machine ) {
107
103
return function ( ) {
108
- return new Promise ( ( resolve , reject ) => {
104
+ return new Promise ( resolve => {
109
105
this . child = interpret ( machine , s => {
110
106
this . onChange ( s ) ;
111
107
if ( s . machine . state . value . final ) {
@@ -130,11 +126,11 @@ let machine = {
130
126
} ;
131
127
}
132
128
} ;
133
- export function createMachine ( states , contextFn ) {
129
+ export function createMachine ( states , contextFn = empty ) {
134
130
if ( d . _create ) d . _create ( states ) ;
135
131
let current = Object . keys ( states ) [ 0 ] ;
136
132
return create ( machine , {
137
- context : valueEnumerable ( contextFn || empty ) ,
133
+ context : valueEnumerable ( contextFn ) ,
138
134
current : valueEnumerable ( current ) ,
139
135
states : valueEnumerable ( states )
140
136
} ) ;
@@ -144,7 +140,7 @@ function transitionTo(service, fromEvent, candidates) {
144
140
let { machine, context } = service ;
145
141
for ( let { to, guards, reducers } of candidates ) {
146
142
if ( guards ( context ) ) {
147
- service . context = reducers . call ( service , fromEvent , context ) ;
143
+ service . context = reducers . call ( service , context , fromEvent ) ;
148
144
149
145
let original = machine . original || machine ;
150
146
let newMachine = create ( original , {
@@ -177,6 +173,7 @@ let service = {
177
173
this . onChange ( this ) ;
178
174
}
179
175
} ;
176
+
180
177
export function interpret ( machine , onChange ) {
181
178
let s = Object . create ( service , {
182
179
machine : valueEnumerableWritable ( machine ) ,
@@ -186,4 +183,4 @@ export function interpret(machine, onChange) {
186
183
s . send = s . send . bind ( s ) ;
187
184
s . machine = s . machine . state . value . enter ( s . machine , s , { } ) ;
188
185
return s ;
189
- }
186
+ }
0 commit comments