Actuator 执行器

基本介绍

Actuator 主要用于 options 参数的解析与执行。

如何使用

初始化

  • def 与外部传入的 options 进行合并,计算出最终的 options
const actuator = new Actuator({
  options: {},
  def: {
    getBaseConfig () {
      return {
        title: '',
        idKey: 'id'
      }
    },
  }
})

参数

  • options 外部options。
  • def 默认options。
  • def.getBaseConfig 默认options.getBaseConfig。

函数

initConfig

初始化 config

执行 def.getBaseConfig(nvt)options.getBaseConfig(nvt) 并将结果进行 mergeObject,计算出最终的 config

this.actuator.initConfig(nvt)

has

用于检查 options 中的回调函数是否存在。

const options = {
  getDataList: () => []
}

this.actuator.has('getDataList')
// => true

this.actuator.has('getDataListSync')
// => false

dispatch

用于触发 options 中的回调函数。

  • 如果不是函数,会返回值。
  • 可以携带任意数量的参数。
const options = {
  getDefaultParams: (value) => {
    return value
  },
  hasDefaultParams: true
}

this.actuator.dispatch('getDefaultParams', false)
// => false

this.actuator.dispatch('hasDefaultParams')
// => true

getOptions

获取最终的 options

this.actuator.getOptions()

getConfig

用于获取 config

this.actuator.getConfig()

getConfigBy

用于获取 config 中的某一个字段。

// 获取 options.getBaseConfig() 返回值中的 icon 字段。
this.actuator.getConfigBy('icon')