1
- import { ReduceStore } from "reshow-flux" ;
1
+ import { ImmutableStore } from "reshow-flux" ;
2
2
import { Map , List } from "immutable" ;
3
3
import get from "get-object-value" ;
4
4
import callfunc from "call-func" ;
5
5
import { T_NULL , IS_ARRAY , KEYS } from "reshow-constant" ;
6
6
7
- import dispatcher , { dispatch } from "../dispatcher" ;
8
-
9
7
let alertCount = 0 ;
10
8
11
9
const toMessage = ( message ) => {
@@ -21,7 +19,7 @@ const toMessage = (message) => {
21
19
22
20
const getMessage = ( action ) => toMessage ( get ( action , [ "params" , "message" ] ) ) ;
23
21
24
- class MessageStore extends ReduceStore {
22
+ class MessageStore {
25
23
dialogCallback = T_NULL ;
26
24
alertMap = { } ;
27
25
@@ -89,24 +87,25 @@ class MessageStore extends ReduceStore {
89
87
this . alertMap [ message . id ] = message ;
90
88
return state . set ( "alerts" , this . getAlertList ( ) ) ;
91
89
}
90
+ }
92
91
93
- reduce ( state , action ) {
94
- switch ( action . type ) {
95
- case "dialog/start" :
96
- return this . dialogStart ( state , action ) ;
97
- case "dialog/end" :
98
- return this . dialogEnd ( state , action ) ;
99
- case "alert/reset" :
100
- return this . alertReset ( state , action ) ;
101
- case "alert/del" :
102
- return this . alertDel ( state , action ) ;
103
- case "alert/add" :
104
- return this . alertAdd ( state , action ) ;
105
- default :
106
- return state ;
107
- }
92
+ const [ store , messageDispatch ] = ImmutableStore ( ( state , action ) => {
93
+ const oMess = new MessageStore ( ) ;
94
+ switch ( action . type ) {
95
+ case "dialog/start" :
96
+ return oMess . dialogStart ( state , action ) ;
97
+ case "dialog/end" :
98
+ return oMess . dialogEnd ( state , action ) ;
99
+ case "alert/reset" :
100
+ return oMess . alertReset ( state , action ) ;
101
+ case "alert/del" :
102
+ return oMess . alertDel ( state , action ) ;
103
+ case "alert/add" :
104
+ return oMess . alertAdd ( state , action ) ;
105
+ default :
106
+ return state ;
108
107
}
109
- }
108
+ } ) ;
110
109
111
- // Export a singleton instance of the store
112
- export default new MessageStore ( dispatcher ) ;
110
+ export default store ;
111
+ export { messageDispatch } ;
0 commit comments