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

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/19 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SAP Commerce Cloud Spartacus UI 的 ActionClass 数据结构设计 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

以 CmsSetPageSuccessIndex 為例:

運(yùn)行時(shí)該 Action 類(lèi)包含三大字段:

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

meta

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

meta.entityId 和 entityType 是該 action payload 的標(biāo)識(shí)位。

loader 表明該 entity 加載狀況。

payload

包含的業(yè)務(wù)數(shù)據(jù):

type

字符串類(lèi)型。

從 上圖 Prototype 能看出,CmsSetPageSuccessIndex 的原型鏈類(lèi)為 EntitySuccessAction.

這一點(diǎn)也能從其實(shí)現(xiàn)代碼看出:

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 的實(shí)現(xiàn):

屬性1,meta 屬性,定義在該類(lèi)里。
屬性2,payload,通過(guò)構(gòu)造函數(shù)參數(shù)定義。
屬性3,type,定義在上圖81行,然后被 CmsSetPageSuccessIndex 重載。

EntitySuccessAction 構(gòu)造函數(shù)接收三個(gè)參數(shù):entityType,id 和 payload.

通過(guò) entityType 和 id,生產(chǎn)出 meta 字段。

entitySuccessMeta 可以看成一個(gè)構(gòu)造器或者工廠(chǎng)函數(shù):

根據(jù) entityType 和 id,生產(chǎn)出 EntityLoaderMeta, 后者是 EntityMeta 和 LoaderMeta 的聯(lián)合。

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

采用三個(gè)點(diǎn)的語(yǔ)法,是因?yàn)檫@兩個(gè) interface,都有同名字段:entityType

LoaderMeta 的運(yùn)行時(shí)數(shù)據(jù),通過(guò)構(gòu)造器 loadMeta 制造:

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

EntityMeta 字段的值,通過(guò) entityMeta 構(gòu)造:

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

運(yùn)行時(shí)通過(guò) PageEffect 從 Commerce Cloud 后臺(tái)讀取 CMS 數(shù)據(jù)成功后,新建 ActionClass,將負(fù)載通過(guò)構(gòu)造函數(shù)參數(shù)傳入。

更多Jerry的原創(chuàng)文章,盡在:“汪子熙”:

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。