美文网首页SAP
SAP Spartacus ProductConnector和P

SAP Spartacus ProductConnector和P

作者: 华山令狐冲 | 来源:发表于2020-12-12 09:47 被阅读0次

名称:ProductConnector
路径:在core文件夹下

通过ProductAdapter向Commerce Cloud发起数据请求:

逻辑很简单,直接调用adapter的load方法。

什么时候ProductConnector会被调用?

let ProductEffects = class ProductEffects {
    constructor(actions$, productConnector) {
        this.actions$ = actions$;
        this.productConnector = productConnector;
        // we want to cancel all ongoing requests when currency or language changes,
        this.contextChange$ = this.actions$.pipe(ofType(CURRENCY_CHANGE, LANGUAGE_CHANGE));
        this.loadProduct$ = createEffect(() => ({ scheduler, debounce = 0 } = {}) => this.actions$.pipe(ofType(LOAD_PRODUCT), map((action) => ({
            code: action.payload,
            scope: action.meta.scope,
        })), 
        // we are grouping all load actions that happens at the same time
        // to optimize loading and pass them all to productConnector.getMany
        bufferDebounceTime(debounce, scheduler), mergeMap((products) => merge(...this.productConnector
            .getMany(products)
            .map(this.productLoadEffect))), withdrawOn(this.contextChange$)));
    }

有17个product需要加载:


loadProduct$的实现,包含了加载多个product的逻辑:

这17个product是外层传进来的:

看这个getProductForScope是何时被调用的:


又出现了一个ProductService:

位于facade层:

Spartacus-storefront.js:

这个ProductCarouselComponent位于storefrontlib文件夹内:

相关文章

网友评论

    本文标题:SAP Spartacus ProductConnector和P

    本文链接:https://www.haomeiwen.com/subject/nfbgyktx.html