1- import { ReduceStore } from "reshow-flux" ;
1+ import { ImmutableStore } from "reshow-flux" ;
22import { Map , List } from "immutable" ;
33import get from "get-object-value" ;
44import callfunc from "call-func" ;
55import { T_NULL , IS_ARRAY , KEYS } from "reshow-constant" ;
66
7- import dispatcher , { dispatch } from "../dispatcher" ;
8-
97let alertCount = 0 ;
108
119const toMessage = ( message ) => {
@@ -21,7 +19,7 @@ const toMessage = (message) => {
2119
2220const getMessage = ( action ) => toMessage ( get ( action , [ "params" , "message" ] ) ) ;
2321
24- class MessageStore extends ReduceStore {
22+ class MessageStore {
2523 dialogCallback = T_NULL ;
2624 alertMap = { } ;
2725
@@ -89,24 +87,25 @@ class MessageStore extends ReduceStore {
8987 this . alertMap [ message . id ] = message ;
9088 return state . set ( "alerts" , this . getAlertList ( ) ) ;
9189 }
90+ }
9291
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 ;
108107 }
109- }
108+ } ) ;
110109
111- // Export a singleton instance of the store
112- export default new MessageStore ( dispatcher ) ;
110+ export default store ;
111+ export { messageDispatch } ;
0 commit comments