umijs / sula

🚀 Pluggable enterprise-level configurable framework based on antd.
https://docs.sula.vercel.app
MIT License
789 stars 90 forks source link

RFC - 行为链规范 #6

Open xz8la8 opened 4 years ago

xz8la8 commented 4 years ago

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

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

rope-container

示例

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

示例

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,
         }
        }
    }
  ]
}
leiyaguang commented 3 years ago

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