SAP Spartacus auth.service.ts里的user调用触发的源代码位置
返回類型是一個subscription.
Represents a disposable resource, such as the execution of an Observable.
subscription代表一個一次性的,可被處理的資源,即Observable的執行,調用subscribe方法才真正開始Observable的執行。
A Subscription has one important method, unsubscribe, that takes no argument and just disposes the resource held by the subscription.
Additionally, subscriptions may be grouped together through the add()method, which will attach a child Subscription to the current Subscription. When a Subscription is unsubscribed, all its children (and its grandchildren) will be unsubscribed as well.
/*** This function provides the userId the OCC calls should use, depending* on whether there is an active storefront session or not.** It returns the userId of the current storefront user or 'anonymous'* in the case there are no signed in user in the storefront.** The user id of a regular customer session is 'current'. In the case of an* asm customer emulation session, the userId will be the customerId.*/getOccUserId(): Observable<string> {return this.getUserToken().pipe(map((userToken) => {if (!!userToken && !!userToken.userId) {return userToken.userId;} else {return OCC_USER_ID_ANONYMOUS;}}));}getOccUserID的實現如上源代碼所示。
map尖括號里的UserToken,即調用map的源Observable包裹的對象類型,UserToken.
Map接受一個箭頭函數,稱為project, 將UserToken對象映射成一個字符串,然后將該字符串包裹成Observable對象,傳給執行鏈里下一個Observable,如果有的話。
當然,getUserToken本身必須返回Observable才行。
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
總結
以上是生活随笔為你收集整理的SAP Spartacus auth.service.ts里的user调用触发的源代码位置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP Spartacus Config
- 下一篇: SAP Spartacus用户登录之后读