配置
configure函数用于向concent配置一个模块,包括其state、reducer、watch、computed和init定义。
注意,该函数必需在
concent启动之后才能调用,所以除了run函数可以配置模块,configure也可以完成此项工作,唯一不同的是:run负责启动concent并一次性配置多个模块,configure一次只能配置一个模块,具体使用场景参考下面的何时使用
函数签名定义
configure(
module:string,
config:{
state:object,
reducer:Reducer,
watch:Watch,
computed:Computed,
init:Init
}
)
reducer、watch、computed、init类型定义参见
run的解释
如何使用
import {configure} from 'concent';
import fooModule from './model';
configure('foo', fooModule);
何时使用
- 当你的模块和组件有着密不可分的关系的时候
- 当你的组件期望独立打包发到
npm的时候,期望模块定义和组件一起打包发布
此时,别人引用你的组件的同时就完成了模块的配置
|_cc-components
|_PlatformTable
| |_index.js
| |_TableHeader.js
| |_TableFooter.js
| |_TableSearch.js
| |_model
| | |_index.js
| | |_state.js
| | |_reducer.js
| | |_...
|
|_...
//code in PlatformTable/index.js
import {register} from 'concent';
import './model';
// @register('PlatFormTable', {module:'platformTable', watchedKeys:'*'})
@register('PlatFormTable', 'platformTable')
export default class extends Components{
}
