Serivce
本节主要讲如何定义一个Service ?
简单的Service
interface State {
// 定义State的类型
}
class DemoService extends Service<State> {
defaultState: State = {
// 实现State
}
}Reducer
interface State {
count: number
}
class DemoService extends Service<State>{
defaultState: State ={
count: 0
}
@Reducer()
add(state:State, x: number):State {
return { count: state.count + x }
}
@Reducer()
reset():State {
return this.defaultState
}
}ImmerReducer
Effect
Notice #1: this.actions()
Last updated
Was this helpful?