import mitt from 'mitt' ; interface Data { key : any ; nextState : any ; } type Events = { STORE_INITED : string ; STORE_UPDATED : Data ; } ; enum EventKey { STORE_INITED = 'STORE_INITED' , STORE_UPDATED = 'STORE_UPDATED' } export const emitter = mitt < Events > ( ) ; export function emitStoreInit ( key ) { emitter . emit ( EventKey . STORE_INITED , key ) ; } export function emitStoreUpdate ( data ) { emitter . emit ( EventKey . STORE_UPDATED , data ) ; } export function onStoreInit ( cb ) { emitter . on ( EventKey . STORE_INITED , key => { cb ( key ) ; } ) ; } export function onStoreUpdate ( cb ) { emitter . on ( EventKey . STORE_UPDATED , data => { cb ( data ) ; } ) ; }