Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load a module #7

Open
ryuever opened this issue Sep 1, 2020 · 1 comment
Open

How to load a module #7

ryuever opened this issue Sep 1, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@ryuever
Copy link
Member

ryuever commented Sep 1, 2020

Halation在进行module register的时候是依靠load.strategy来实现对于module是否记载的处理

export default function PluginComponent() {
  return {
    name: 'plugin-a',

    loader: {
      strategy: [{
        type: 'ban',
        resolver: () => {}
      },{
        type: 'flags',
        resolver: () => {}
      }, {
        type: 'event',
        resolver: () => {}
      }, {
        type: 'runtime',
        resolver: () => {}
      }],
    }
  }
}

类型的话,主要是分为下面的四种

enum StrategyType {
  // 你可以认为这个属于偏静态的约束方式,比如当进入商详的时候,goodsId其实已经知道了;比如可以通过
  // ban 进行一些黑名单的约束
  ban,

  // 函数会接受flags
  flags,

  // 应用自定义的render phase;
  event,

  // 可能会依赖model在runtime时的值;这个其实就是与业务耦合,需要通过值的判断进行是否加载模块的判断
  // 其实这个halation中更经常碰到的问题
  runtime,
}

对于loader的使用方式,他们最后值的合并类似&&的关系

  1. 如果第一个function返回false,那么后面的function就不需要继续处理
  2. 只有当所有的function都返回true的时候,loader才返回true,也就认为当前的module可以进行加载了

上面的方式只是解决了普遍情况的问题,但是还有一种情况;

  1. module B的自组件包含A,A-
  2. A, A-是通过flag值来判断到底渲染哪个;
  3. 但是还有一个约束,B还要通过runtime的值来判断究竟是A还是A-(比如一个值为空就渲染A-)

目前Halation提供的方式是对component进行registerModuleMap属性的注入,直接通过registerModuleMap拿到对应的module然后调用load的方式进行加载

const B = props =>  {
  const { registerModuleMap } = props

  const load = registerModuleMap.get('A')

  load()
}

Maybe

  1. when to trigger next phrase; useRender to collect which
  2. when to notify to the end of collection
    1. useEffect is not a good choice...
    2. The followed ComponentHelper may works...
  3. Every exported module is required to has useRender function.
@ryuever ryuever added the enhancement New feature or request label Sep 1, 2020
@ryuever
Copy link
Member Author

ryuever commented Sep 12, 2020

related to

  1. 435b63e
  2. 4a541fb
  3. bbba3c2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant