A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Time:2021-12-21

How to understand the proxy facade in the Spartacus UI of SAP e-commerce cloud?

Jerry, this articleWhat is the proxy FA ç ade of the Spartacus UI of the sap e-commerce cloudProvides a theoretical explanation.

This paper introduces a practical example.

When we open the following URL, the loading of quick order core module will not be triggered by default, because we do not use any functions of quick order at all:

http://localhost:4299/electro…

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Of course, we still have a way in the home page app module. Manually write some codes in TS. these codes can be executed normally only after the quick order core module is loaded:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Although the dependent quickorderfacade injected by the above code is a part of the quick order root module and is loaded normally, the quickorderfacade is only an abstract class and needs the specific implementation provided in the core module to continue execution. Therefore, after adding the above code, when we access the home page of Spartacus UI, it will also trigger the loading of quick order core module.

The above conclusion can be observed in the chrome Developer Tool Network tab that the quick order core module is loaded:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

And printing of corresponding debugging code:
A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

At runtime, when the appmodule is loaded as an entry module, the angular framework will call_ Dependencies declared in resolveinjectordeftypes parser constructor:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

At this time, because the quickorder core module has not been loaded, the dependencies are provided through the factory method facadefactory provided by the quickorderfacade:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Here, the standard inject from angular / core is called and injected in combination with the passed in descriptor:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

What is the result of calling inject to inject facadefactoryservice?

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

As a result, an instance of facadefactoryservice is obtained, and each attribute field of the instance is injected into the corresponding instance:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Here, we are going to create a specific implementation of cartquickordercore. First, we need to check whether the feature has been enabled:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

this. cmsConfig. The cartquickorder record does exist in the featuremodules:
A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Here is an attempt to get the implementation of quickorderfacade:

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Finally, it is injected through quickorderservice.

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

At this point, the quick order core module should have been loaded.

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Let’s take a specific look at which line of code triggered the core module loading?

A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

entrance:
A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

The next function call in this line triggers a delayed load:
A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

Final position:
A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud

More Jerry’s original articles are: “Wang Zixi”:
A practical example of the Spartacus UI proxy facade of SAP e-commerce cloud