SAP 电商云 Spartacus UI ComponentDa
2021-12-17 本文已影响0人
华山令狐冲


为什么 this.componentService.getItems 最后就触发到
Component-data.provider.ts 工厂函数的执行了?

29行的 getService:


getService 的实现在第 70 行,又会调用到第 79 行的 getContext:

这里的 componentData,就和之前这篇文章如何在 SAP 电商云 Spartacus UI 里访问 CMS Component data 数据介绍的内容串联起来了。
输入参数:

首先明确,为什么 defer 里的工厂函数会被执行?一定是因为 defer 返回的 Observable 在某处被 subscribe 了。
getItems -> getService -> getContext -> this.componentData.data$
因为 getItems 被 async pipe 执行,所以 this.componentData.data$ 被 subscribe.
更多Jerry的原创文章,尽在:"汪子熙":
