File tree Expand file tree Collapse file tree 3 files changed +49
-8
lines changed Expand file tree Collapse file tree 3 files changed +49
-8
lines changed Original file line number Diff line number Diff line change @@ -48,25 +48,36 @@ class AltStore {
48
48
state : this . state
49
49
} )
50
50
51
- const actionHandler = model . actionListeners [ payload . action ] ||
52
- model . otherwise
51
+ const actionHandlers = model . actionListeners [ payload . action ]
53
52
54
- if ( actionHandler ) {
55
- const result = handleDispatch ( ( ) => {
56
- return actionHandler . call ( model , payload . data , payload . action )
57
- } , payload )
53
+ if ( actionHandlers || model . otherwise ) {
54
+ let result
55
+
56
+ if ( actionHandlers ) {
57
+ result = handleDispatch ( ( ) => {
58
+ return actionHandlers . filter ( Boolean ) . every ( ( handler ) => {
59
+ return handler . call ( model , payload . data , payload . action ) !== false
60
+ } )
61
+ } , payload )
62
+ } else {
63
+ result = handleDispatch ( ( ) => {
64
+ return model . otherwise ( payload . data , payload . action )
65
+ } , payload )
66
+ }
58
67
59
68
if ( result !== false && ! this . preventDefault ) this . emitChange ( )
60
69
}
61
70
71
+
72
+
62
73
if ( model . reduce ) {
63
74
handleDispatch ( ( ) => {
64
75
this . state = model . reduce ( this . state , payload )
65
76
} , payload )
66
-
67
77
if ( ! this . preventDefault ) this . emitChange ( )
68
78
}
69
79
80
+
70
81
this . lifecycle ( 'afterEach' , {
71
82
payload,
72
83
state : this . state
Original file line number Diff line number Diff line change @@ -125,7 +125,8 @@ const StoreMixin = {
125
125
126
126
// You can pass in the constant or the function itself
127
127
const key = symbol . id ? symbol . id : symbol
128
- this . actionListeners [ key ] = handler . bind ( this )
128
+ this . actionListeners [ key ] = this . actionListeners [ key ] || [ ]
129
+ this . actionListeners [ key ] . push ( handler . bind ( this ) )
129
130
this . boundListeners . push ( key )
130
131
} ,
131
132
Original file line number Diff line number Diff line change @@ -1391,6 +1391,35 @@ const tests = {
1391
1391
myStore . listen ( null )
1392
1392
} , TypeError , 'listen expects a function' )
1393
1393
} ,
1394
+
1395
+ 'lots of listens' ( ) {
1396
+ const ImportKeysActions = alt . generateActions ( 'change' , 'saved' )
1397
+
1398
+ const call = sinon . spy ( )
1399
+
1400
+ const BalanceClaimStore = alt . createStore ( class {
1401
+ constructor ( ) {
1402
+ this . bindListeners ( {
1403
+ onRefreshBalanceClaims : ImportKeysActions . saved ,
1404
+ onLoadMyAccounts : [
1405
+ ImportKeysActions . change , ImportKeysActions . saved
1406
+ ]
1407
+ } )
1408
+ }
1409
+
1410
+ onRefreshBalanceClaims ( ) {
1411
+ call ( )
1412
+ }
1413
+
1414
+ onLoadMyAccounts ( ) {
1415
+ call ( )
1416
+ }
1417
+ } )
1418
+
1419
+ ImportKeysActions . saved ( )
1420
+
1421
+ assert ( call . calledTwice , 'multiple action handlers are ok' )
1422
+ } ,
1394
1423
}
1395
1424
1396
1425
export default tests
You can’t perform that action at this time.
0 commit comments