sula icon indicating copy to clipboard operation
sula copied to clipboard

RFC - 行为链规范

Open xz8la8 opened this issue 4 years ago • 1 comments

行为链指一串行为序列,例如,请求 -> 弹窗 -> 刷新表格 -> 隐藏loading,这就是一串行为序列,sula 使用 rope(绳子)来喻指行为序列。

sula rope 分为两部分 rope-container 和 rope。

  • rope-container 连接渲染插件与rope的行为触发器,
  • rope 将行为粘合到一起来响应渲染插件的事件,参考了connect

rope-container

  • disabled(默认是false)
  • visible (默认是true)
  • confirm string | PopconfirmProps
  • tooltip string | TooltipProps

示例

const config = {
  render: {
    type: 'button',
	props: {
	  children: 'Submit'
	},
	confirm: 'Confirm to submit?',
	tooltip: 'Submit information',
	disabled: false,
	visible: false,
	action: {
	  type: 'fetch',
	  url: '/api/info',
	  method: 'GET'
	}
  }
}

rope

  • before 决定是否触发该action,如果不触发则终止行为链
  • finish 下一个action
  • error 执行 action 出错,终止行为链
  • final 不论成功or失败,均执行
  • resultPropName 执行结果保存在ctx.results中的属性名

示例

const config = {
  before: (ctx) => ctx.name === 'sula',
  finish: (ctx) => { ... }
  error: (ctx) => {...}
  final: (ctx) => {...}
  resultPropName: validateFields
}

行为链形态

例如有a,b,c,d四个行为,在rope中最终都会转成

const config = ['a', 'b', 'c', 'd'];

例如,

const config = {
  type: 'a',
  finish: {
    type: 'b',
	finish: ['c', 'd']
  }
}

一个和渲染插件结合的示例

const config = {
  type: 'button',
  props: {
    children: 'Submit'
  },
  action: [
	 {
	   type: 'validateGroupFields',
	   args: ['TaskGroup'],
	   resultPropName: 'taskGroupFieldsValue',
	 },
	 (ctx) => {
	   return 'hello'
	 },
	 {
	   type: 'fetch',
	   url: '/api/info',
	   convertParams(ctx) {
         return {
            ...ctx.results.taskGroupFieldsValue,
            word: ctx.result,
         }
	    }
    }
  ]
}

xz8la8 avatar Apr 20 '20 06:04 xz8la8

请问 actionsRender 内的每个render共享ctx该如何去做?

leiyaguang avatar Jan 28 '21 10:01 leiyaguang