头图

First study why the standard effects can be called: set a breakpoint in the ProductReviewsEffects constructor:

It is found that when visiting the homepage, the breakpoint is triggered.

Why does ProductReviewEffect have to be loaded when AppModule starts?

Clicking on AppModule will jump to my customized AppModule file, but there is no ProductReviewEffect in this file:

This EffectFeatureModule is an implementation of the standard framework:

All standard Effects instances of Spartacus are instantiated in the following code 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);
}

The question is, where are these Effects resolved for AppModule?

Take a look at how the standard Effects are done?

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

solution

Finally, it took effect:

More original articles by Jerry, all in: "Wang Zixi":


注销
1k 声望1.6k 粉丝

invalid