concent

concent

  • Docs
  • API
  • ChangeLog
  • GitHub

›顶层api

顶层api

  • run
  • configure
  • cloneModule
  • register
  • connect
  • connectDumb
  • emit
  • emitWith
  • dispatch
  • getState
  • getGlobalState
  • getComputed
  • setState
  • setGlobalState
  • call
  • execute
  • executeAll

通用类型解释

  • HandlerCtx
  • CcFragmentCtx
  • WatchFn

实例上下文api

  • ctx.dispatch
  • ctx.invoke
  • ctx.setState
  • ctx.setModuleState
  • ctx.setGlobalState
  • ctx.computed
  • ctx.watch
  • ctx.syncBool
  • ctx.set
  • ctx.emit
  • ctx.on
  • ctx.off

CcFragment api

  • Fifth Document

通用api

  • dispatch

配置


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{

}
← runcloneModule →
  • 函数签名定义
  • 如何使用
  • 何时使用
Copyright © 2019 concentjs.org