当前位置:网站首页>How SAP Spartacus redefines login component

How SAP Spartacus redefines login component

2022-07-25 01:04:00 Hua Weiyun

First, in a standard Storefront On , To find the Component Of selector To find the Component name :LoginComponent

And then find the Component The path of , be located feature-libs Below user In module :

feature-libs\user\account\components\login\login.component.ts

Within this module , Found its connection with CMS Component LoginComponent One to one correspondence of :

In my own Storefront Project package-lock.json In the document , Found version number :3.4.3

Create a new one Component, Extended standard LoginComponent:

In my AppModule in , take CMS LoginComponent Map to my extended ExtLoginComponent Go to :

The final runtime effect :

Be careful : If in my expansion Component in , Import from this path LoginComponent:

import { LoginComponent } from ‘@spartacus/user/account/components/login/login.component’;

False report :

ERROR in ./src/app/loginExtension/extLogin.component.ts
Module not found: Error: Can’t resolve ‘@spartacus/user/account/components/login/login.component’ in ‘c:\Code\SPA\strange\mystore\src\app\loginExtension’

The correct path is :

import { LoginComponent } from ‘@spartacus/storefront’;

demand

How to find the exact code location that triggers the network request ?

from initiator View the call stack context in , There is no clue .

Find the name of the control that triggered the network request selector:cx-register

stay Storefront TypeScript I can't find it in the source code :

Generated in compilation JavaScript Search inside cx-register: Found three places

Only direct view SAP Spartacus Source code :cx-register Corresponding RegisterComponent, It's defined in user-profile-components.module.ts in :

Finally found RegisterComponent Other dependencies in :

such as :

  • userRegister:UserRegisterFacade
  • globalMessageService:GlobalMessageService
  • fb:FormBuilder
  • router:RoutingService

These dependencies , In the compilation of for In the runtime code , Can see :

These dependencies are used as another module Be inducted into .

I can't see these module In the way of JavaScript Code ?

Search directly RegisterComponent, There are too many results 200 Multiple matches .

Try another way :

eureka :

So the conclusion is ,TypeScript Compiled into JavaScript Source code , Running at Chrome You can still find it in developer tools .

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/202/202207201249034290.html