美文网首页
this.counter$ = store.select(fro

this.counter$ = store.select(fro

作者: 华山令狐冲 | 来源:发表于2021-02-09 11:13 被阅读0次

this.counter$ = store.select(fromExample.getCounterCounter);

上述调用返回一个Observable<number>:

传入select方法的fromExample.getCounterCounter是一个createSelector返回的值:

执行select操作:


pathOrMapFn就是fromExample.getCounterCounter指向的值:
注意,Store是Observable的子类,这个select是Store的重新实现:



这个source$就是store.select(fromExample.getCounterCounter);里的store:

最后返回的是一个施加了MapOperator的新Store(新Observable):

而我们应用程序传入selector的fromExample.getCounterCounter,体现在这个新store的什么地方?

source就是我们应用代码里构造函数注入的store,父类是Observable.

对于source store,执行map里指定的箭头函数,即我们应用程序传入store.select里的函数:

位于第976行:


我们传入的getCounter(第1061行的projector)被一个memoize函数修饰:

更多Jerry的原创文章,尽在:"汪子熙":


相关文章

网友评论

      本文标题:this.counter$ = store.select(fro

      本文链接:https://www.haomeiwen.com/subject/ywhavktx.html