- SAP Spartacus 如何使用 API 从浏览器 loca
- SAP Spartacus RouteEvent,如何从loca
- 使用StackBlitz和SAP Spartacus快速创建电商
- 如何安装指定版本的 SAP Spartacus
- SAP 电商云 Spartacus 服务器端渲染的单步调试详细步
- SAP Commerce Accelerator和SAP Spa
- SAP UI5 sap.ui.vk 命名空间内的控件介绍
- 让 fork 出来的 Github 仓库从远端仓库拖取最新的修改
- SAP Spartacus Definition of Done
- 借助 SAP 电商云 Spartacus UI 提供的 Sche
如下图所示,SAP 电商云 UI,用户的购物车 ID,持久化在浏览器的 local storage 里:

运行时,通过封装好的函数 getStorage 读取:

为什么会触发 State module 的加载?

并没有直接用到 StateModule:

默认使用 local storage:

新建一个 subscription,自执行:

上图代码的逻辑:

unsubscribe 之后仍然可以 subscribe,为啥?

对于 interval 产生的 Observable 来说,可以被 unsubscribe.

最后用的是浏览器的原生 API 读取 local storage 数据:

代码第 47 行的 storage 引用,来自函数 getStorage,从 winRef 获取:

winRef 通过依赖注入生成:

winref 包含了 Spartacus 团队针对 Document 的一个封装:

直接利用 Angular 标准的 injection token 来检测运行环境是浏览器还是服务器:

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

网友评论