SAP Spartacus和product相关的标准normalizer

以product name normalizer为例:

SAP Spartacus和product相关的标准normalizer_第1张图片

路径:C:\Code\SPA\spartacus\projects\core\src\occ\adapters\product\converters\product-name-normalizer.ts

拷贝下类的名称:
ProductNameNormalizer

如果想运行时调试,在Spartacus-core.js里,根据这个名称搜索,找到对应的JavaScript function:ProductNameNormalizer_Factory:

SAP Spartacus和product相关的标准normalizer_第2张图片

/**
 * Construct an `InjectableDef` which defines how a token will be constructed by the DI system, and
 * in which injectors (if any) it will be available.
 *
 * This should be assigned to a static `ɵprov` field on a type, which will then be an
 * `InjectableType`.
 *
 * Options:
 * * `providedIn` determines which injectors will include the injectable, by either associating it
 *   with an `@NgModule` or other `InjectorType`, or by specifying that this injectable should be
 *   provided in the `'root'` injector, which will be the application-level injector in most apps.
 * * `factory` gives the zero argument function which will create an instance of the injectable.
 *   The factory can call `inject` to access the `Injector` and request injection of dependencies.
 *
 * @codeGenApi
 */
function ɵɵdefineInjectable(opts) {
     
    return {
     
        token: opts.token,
        providedIn: opts.providedIn || null,
        factory: opts.factory,
        value: undefined,
    };
}

SAP Spartacus和product相关的标准normalizer_第3张图片
SAP Spartacus和product相关的标准normalizer_第4张图片

随着构造函数一起传进来的配置对象:

SAP Spartacus和product相关的标准normalizer_第5张图片

这个配置对象的赋值是通过eeinject(OccConfig)进行的:

SAP Spartacus和product相关的标准normalizer_第6张图片

converter调用的地方:Pipeable operator to apply converter logic in a observable stream

SAP Spartacus和product相关的标准normalizer_第7张图片
SAP Spartacus和product相关的标准normalizer_第8张图片

 convertSource(source, injectionToken) {
     
        return this.getConverters(injectionToken).reduce((target, converter) => {
     
            return converter.convert(source, target);
        }, undefined);
    }

SAP Spartacus和product相关的标准normalizer_第9张图片

向Commerce Cloud后台发起请求:

SAP Spartacus和product相关的标准normalizer_第10张图片
SAP Spartacus和product相关的标准normalizer_第11张图片
SAP Spartacus和product相关的标准normalizer_第12张图片

得到完整的occ地址:

SAP Spartacus和product相关的标准normalizer_第13张图片
SAP Spartacus和product相关的标准normalizer_第14张图片
SAP Spartacus和product相关的标准normalizer_第15张图片

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

你可能感兴趣的:(TypeScript,Angular)