mobx-multiple-store
v1.2.1
Published
基于 mobx 的多 stroe 管理工具
Downloads
7
Readme
基于 mobx 的多 stroe 管理工具
api doc
StoreHelper
创建 mobx-stroe, 根据 instanceKey 作缓存
|属性|说明|类型| |----|----|----| |static findOrCreate|查找或者创建实例|(instanceKey: string, newState?: Object)=> instance| |constructor|创建实例|(state: Object)=> instance|
WebAPIStore
继承 StoreHelper
|属性|说明|类型|默认值| |----|----|----|----| |isFetching|请求中|boolean|false| |isFulfilled|请求完成|boolean|false| |isRejected|请求失败|boolean|false| |error|错误对象|Error|null| |tryFetchData|尝试调用 fetchData 方法,isFulfilled 为 true 时不调用|Function|Function| |mergeFetched|自动处理 fetching 状态,并自动合并请求结果|(handle: Function | Promise) => Promise|Function| |fetching|自动处理 fetching 状态|(handle: Function | Promise) => Promise|Function|
fetchAction
自动处理 fetching 状态的装饰器,只有在继承了 WebAPIStore 时才有效
class A extends WebAPIStore {
@fetchAction // 基本用法
@fetchAction.merge // 自动合并请求结果
@fetchAction.flow // 异步 action,参考 mobx.flow
@fetchAction.bound // 绑定 this,参考 mobx.action.bound
@fetchAction({ bound: true, useFlow: true, autoMerge: true }) // 传递参数, 默认都为 false
func() {
}
}asyncAction
异步 action 装饰器,参考 mobx.flow
observables
绑定多个 mobx.observable
@observables(
{
title: '' // observable
},
{
list: [] // observable.ref
}
)
class A extends WebAPIStore {
}