How does SAP Spartacus get the CMS metadata of the current rendered page

Time:2021-8-3

There is a CMS dependency in the pagelayoutservice implementation: cmsservice

How does SAP Spartacus get the CMS metadata of the current rendered page

The metadata information of the current page is maintained through cms.getcurrentpage.

How does SAP Spartacus get the CMS metadata of the current rendered page

Get the current page context from routingservice, and then extract the actual data from the ngrx store in central:
How does SAP Spartacus get the CMS metadata of the current rendered page

Implementation of routingservice.getpagecontext: read from store.

How does SAP Spartacus get the CMS metadata of the current rendered page

How does SAP Spartacus get the CMS metadata of the current rendered page

For the arrow function of typescript, the following two methods are correct:

The first one: the typescript compiler automatically deduces if the return type is not specified for the function.

let fun5 = (data:number)=> data * data;

Second: complete writing. The number after the first arrow indicates that the return type is number

let fun5:(data:number) =>number = (data:number)=> data * data;

Select accepts an input parameter: routingselector.getnextpagecontext, which is a function: the input type is any and the output type is pagecontext:

How does SAP Spartacus get the CMS metadata of the current rendered page

The type definition of getnextpagecontext is exactly the same as that of mapfn specified in the select interface:

(state: any) => PageContext

select<any, PageContext>(mapFn: (state: any) => PageContext): (source$: Observable<any>) => Observable<PageContext>

Type definition of select itself: return a function. The input parameter received by the function is observable of type T, and the output is observable object of type K.

How does SAP Spartacus get the CMS metadata of the current rendered page

Let’s assume that the routingstate has been obtained, and write the mapper function first. Then go back and solve the problem of how to get the routingstate, that is, getrouterstate.
How does SAP Spartacus get the CMS metadata of the current rendered page

Similarly:
How does SAP Spartacus get the CMS metadata of the current rendered page

More Jerry’s original articles are: “Wang Zixi”:
How does SAP Spartacus get the CMS metadata of the current rendered page