关于sap:SAP-Spartacus-标准的-Effects-实现的注入原理

0次阅读

共计 825 个字符,预计需要花费 3 分钟才能阅读完成。

先钻研规范的 effect 为何能够被 call 到:在 ProductReviewsEffects 构造函数里设置断点:

发现在拜访首页时,断点即触发。

为什么 AppModule 启动时,就要加载 ProductReviewEffect?

单击 AppModule,就跳转到我自定义的 AppModule 文件了,然而该文件里并没有 ProductReviewEffect:

这个 EffectFeatureModule 是规范框架的实现:

Spartacus 所有规范的 Effects 实例,都是在下列代码 ngrx-effects.js 里实例化的:

function createEffects(injector, effectGroups, userProvidedEffectGroups) {/** @type {?} */
    const mergedEffects = [];
    for (let effectGroup of effectGroups) {mergedEffects.push(...effectGroup);
    }
    for (let userProvidedEffectGroup of userProvidedEffectGroups) {mergedEffects.push(...userProvidedEffectGroup);
    }
    return createEffectInstances(injector, mergedEffects);
}

问题就是,对于 AppModule 而言,这些 Effects 是从哪里解析进去的?

看一下规范的 Effects 是怎么做的?

export const effects: any[] = [
  ProductsSearchEffects,
  ProductEffects,
  ProductReviewsEffects,
  ProductReferencesEffects,
];
EffectsModule.forFeature(effects),

解决方案

最初,失效了:

更多 Jerry 的原创文章,尽在:” 汪子熙 ”:

正文完
 0