this.counter$ = store.select(fro
2021-02-09 本文已影响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的原创文章,尽在:"汪子熙":
