|
export class Service implements IServiceWithStore {
store
useState
setState
getState
constructor() {
this.store = create(
() => ({
current: undefined,
}),
)
this.useState = this.store
this.setState = this.store.setState
this.getState = this.store.getState
}
getCurrent(state = this.getState()) { return state.current }
useCurrent() {
return this.store.useState(this.getCurrent)
}
}
我一般是这样写的,就是会有一些样板代码 |