-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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的使用方式,他们最后值的合并类似&&的关系
- 如果第一个function返回false,那么后面的function就不需要继续处理
- 只有当所有的function都返回true的时候,loader才返回true,也就认为当前的module可以进行加载了
上面的方式只是解决了普遍情况的问题,但是还有一种情况;
- module B的自组件包含A,A-
- A, A-是通过flag值来判断到底渲染哪个;
- 但是还有一个约束,B还要通过runtime的值来判断究竟是A还是A-(比如一个值为空就渲染A-)
目前Halation提供的方式是对component进行registerModuleMap属性的注入,直接通过registerModuleMap拿到对应的module然后调用load的方式进行加载
const B = props => {
const { registerModuleMap } = props
const load = registerModuleMap.get('A')
load()
}Maybe
- when to trigger next phrase; useRender to collect which
- when to notify to the end of collection
- useEffect is not a good choice...
- The followed ComponentHelper may works...
- Every exported module is required to has
useRenderfunction.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request