日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

SAP Spartacus 事件服务 Event Service 使用介绍

發布時間:2023/12/19 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SAP Spartacus 事件服务 Event Service 使用介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

官方鏈接:https://sap.github.io/spartacus-docs/event-service/#page-title

The Spartacus event service provides a stream of events that you can consume without a tight integration to specific components or modules. The event system is used in Spartacus to build integrations to third party systems, such as tag managers and web trackers.

Spartacus 事件服務提供了一個事件流,您可以使用這些事件流,而無需與特定組件或模塊緊密集成。 Spartacus 中使用事件系統來構建與第三方系統的集成,例如標簽管理器和網絡跟蹤器。

The event service also allows you to decouple certain components. For example, you might have a component that dispatches an event, and another component that reacts to this event, without requiring any hard dependency between the components.

事件服務還允許您解耦某些組件。 例如,您可能有一個分派事件的組件和另一個對該事件做出反應的組件,而無需組件之間的任何硬依賴。

一個例子:

import { CxEvent } from "@spartacus/core"; export class CartAddEntryEvent extends CxEvent {cartId: string;userId: string;productCode: string;quantity: number; }

在 app module 里監聽這個事件的代碼:

export class AppModule {constructor(events: EventService, myAdapter: OccCartAdapter) {const result$ = events.get(CartAddEntrySuccessEvent);result$.subscribe((event) => console.log(event));} }

運行時,我一旦將某個產品加到購物車里,就會觸發上面 app module 里注冊的匿名函數的 console.log, 打印出 CartAddEntrySuccessEvent 實例的值。

Pulling Additional Data From Facades - 從 Facade 中提取額外數據

如果您需要比特定事件中包含的數據更多的數據,您可以將此數據與其他流組合。 例如,您可以從 facade 收集額外的數據。

以下是對“添加到購物車事件”做出反應的示例,然后等待購物車 stable(因為需要從后端重新加載 OCC 購物車),然后將所有購物車數據附加到事件數據:

constructor(events: EventService,cartService: ActiveCartService){} /* ... */const result$ = this.events.get(CartAddEntrySuccessEvent).pipe(// When the above event is captured, wait for the cart to be stable// (because OCC reloads the cart after any cart operation)...switchMap((event) =>this.cartService.isStable().pipe(filter(Boolean), mapTo(event))),// Merge the state snapshot of the cart with the data from the event:withLatestFrom(this.cartService.getActive()),map(([event, cart]) => ({ ...event, cart })) );

運行時效果:

更多Jerry的原創文章,盡在:“汪子熙”:

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的SAP Spartacus 事件服务 Event Service 使用介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。