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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

SAP Commerce Cloud Spartacus UI 的 ActionClass 数据结构设计

發布時間:2023/12/19 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SAP Commerce Cloud Spartacus UI 的 ActionClass 数据结构设计 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以 CmsSetPageSuccessIndex 為例:

運行時該 Action 類包含三大字段:

(1) meta
(2) payload
(3) type

meta

meta 包含的 loader 字段和 meta 本身都是一個 object.

meta.entityId 和 entityType 是該 action payload 的標識位。

loader 表明該 entity 加載狀況。

payload

包含的業務數據:

type

字符串類型。

從 上圖 Prototype 能看出,CmsSetPageSuccessIndex 的原型鏈類為 EntitySuccessAction.

這一點也能從其實現代碼看出:

export class CmsSetPageSuccessIndex extends StateUtils.EntitySuccessAction {readonly type = CMS_SET_PAGE_SUCCESS_INDEX;constructor(pageContext: PageContext, payload: Page) {super(pageContext.type, pageContext.id, payload);} }

查看 EntitySuccessAction 的實現:

屬性1,meta 屬性,定義在該類里。
屬性2,payload,通過構造函數參數定義。
屬性3,type,定義在上圖81行,然后被 CmsSetPageSuccessIndex 重載。

EntitySuccessAction 構造函數接收三個參數:entityType,id 和 payload.

通過 entityType 和 id,生產出 meta 字段。

entitySuccessMeta 可以看成一個構造器或者工廠函數:

根據 entityType 和 id,生產出 EntityLoaderMeta, 后者是 EntityMeta 和 LoaderMeta 的聯合。

export interface EntityMeta {entityType: string;entityId: string | string[];entityRemove?: boolean; }export interface LoaderMeta {entityType: string;loader: {load?: boolean;error?: any;success?: boolean;}; }

采用三個點的語法,是因為這兩個 interface,都有同名字段:entityType

LoaderMeta 的運行時數據,通過構造器 loadMeta 制造:

export function loadMeta(entityType: string): LoaderMeta {return {entityType: entityType,loader: {load: true,},}; }

EntityMeta 字段的值,通過 entityMeta 構造:

export function entityMeta(type: string, id: string | string[]): EntityMeta {return {entityType: type,entityId: id,}; }

運行時通過 PageEffect 從 Commerce Cloud 后臺讀取 CMS 數據成功后,新建 ActionClass,將負載通過構造函數參數傳入。

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

總結

以上是生活随笔為你收集整理的SAP Commerce Cloud Spartacus UI 的 ActionClass 数据结构设计的全部內容,希望文章能夠幫你解決所遇到的問題。

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