5

如何查看 SAP Spartacus PageLayoutComponent 里的 template$ 的值

 2 years ago
source link: https://segmentfault.com/a/1190000040124136
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何查看 SAP Spartacus PageLayoutComponent 里的 template$ 的值

SAP Spartacus PageLayoutService.ts 里的 templateName$ get 操作:返回一个 Observable 对象,包裹的类型为 string.

pipe 的第一个操作 filter,目的是确保 page 对象的 template 属性一定存在,避免接下来第二个 map 操作出现返回被 Observable 包裹的 undefined 值的情况。

而在 PageLayoutComponent 实现里,有一个同名属性。

从 layoutName$ 返回的逻辑看,优先从 section$ 里取数。如果 section$ 里有值,返回 section 的值,否则直接返回 PageLayoutService 的 templateName$.

可以查看到这个 project 的具体实现位置:

从 page 结构里拿到 template 属性:值为 ProductDetailsPageTemplate

具体原理,是从 ngrx central store 里,拿到 product 明细页面相关数据:

拿到 result 后,调用 next,通知对应的 subscriber:

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK