import { defineStoreSlice , Action } from '@dura/react' ; import { store } from './store' ; const deloy = ( ms ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ; const user = defineStoreSlice ( { namespace : 'user' , state : { /** 姓名 */ name : '张三' , } , reducers : { onChangeName ( state , action ) { state . name = action . payload . name ; } , } , effects : { async onAsyncQuery ( action ) { await deloy ( 2000 ) ; store . actions . user . onChangeName ( { ... action . payload } ) ; } , } , watchs : { changeTestDom : { dep : state => [ state . name ] , handler : async ( state ) => { if ( document . querySelector ( '#test' ) ) { document . querySelector ( '#test' ) . innerHTML = state . name ; } } , } , } , } ) ; export default user ;