当前位置:网站首页>Difference between rxjs of() and of ({})

Difference between rxjs of() and of ({})

2022-06-12 18:24:00 Jerrywang WangZiXi

I've been doing SAP Spartacus A unit test of e-commerce cloud :

Rxjs of() and of({}) The difference between _github

At first I return Yes. of(), Later, I found that the words written like this , The figure below map Anonymous functions within the operator do not trigger .

Rxjs of() and of({}) The difference between _abap_02

We can find the reason through one-step debugging :
Rxjs of() and of({}) The difference between _ Anonymous functions _03

First, from the current Observable Extract... From the object map The operator . Every one passes pipe Processed Observable object , There is one. Operator quote .

then , Use this Operator call Observable object .

Rxjs of() and of({}) The difference between _sap_04

Execution section 28 Line logic :
Rxjs of() and of({}) The difference between _abap_05

there this Still point to the original Observable object , and array That is, the input parameter , That is to say, the introduction of of Empty object in {}.

If change to of(), So the first 2 Yes array It's empty , So it won't enter for loop , therefore map Anonymous functions in operators , There will be no chance of implementation :

Rxjs of() and of({}) The difference between _abap_06

Every map Operator All maintained a project attribute , Point to map Anonymous function passed in when calling :
Rxjs of() and of({}) The difference between _sap_07

Now it's time to execute my anonymous function :
Rxjs of() and of({}) The difference between _ The operator _08

more Jerry The original article of , All in :“ Wang Zixi ”:
Rxjs of() and of({}) The difference between _abap_09

原网站

版权声明
本文为[Jerrywang WangZiXi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202281610111453.html