How SAP Spartacus ngexpressenginedecorator works

JerryWang_ Wang Zixi 2021-10-14 06:07:21

First look at this class Of get Definition :

Receive two input parameters , The type is :

  • NgExpressEngine
  • SsrOptimizationOptions

Return a packaged NgExpressEngine

NgExpressEngine yes Spartacus Create your own type , The essence is a function , Input parameter is NgSetupOptions, The return type is NgExpressEngineInstance.

The latter is a function , As ExpressEngine Execution instance of , receive filePath,option and callback As a parameter .

One-to-one correspondence :

Returns a new function , receive E It's standard NgExpressEngine The input parameter of is used as the input parameter , At the same time, the original two input parameters NgExpressEngine and Spartacus optimization Values are stored :

later , stay server.ts in , We call this wrapped ngExpressEngine, here , The input parameter is an object , Field is bootstrap, This object is the graph E:NgSetupOptions

here , Execute function body :

Object.assign() Method is used to assign the values of all enumerable properties from one or more source objects to the target objects . It will return the target object .

call get Method , Stored here through closures :

Three points , Is to merge different name fields of several objects , final result :

The first input parameter in the closure , That is standard ngExpressEngine:

Here is the Angular The implementation of the standard , We don't worry about :

Note the type returned :

establish OptimizationEngine example :

Last , Returns a new function renderResponse, And when the function executes , The execution context is OptimizedSsrEngine In itself :

from now on ,this.engines Point to Spartacus Their own renderResponse Function :

more Jerry The original article of , All in :" Wang Zixi ":

Please bring the original link to reprint ,thank
Similar articles

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14

2021-10-14