这个类型为Store<fromExample.State>的变量:
![](https://img.haomeiwen.com/i2085791/dc82e2b0ae6e5475.png)
本质是个Observable:
![](https://img.haomeiwen.com/i2085791/1b08e55843e2f94b.png)
store的source字段的_value里,包含了两个state的初始值:
![](https://img.haomeiwen.com/i2085791/1c495ba3e048b406.png)
this.counter$ = store.select(fromExample.getCounterCounter)之后马上subscribe
![](https://img.haomeiwen.com/i2085791/fac536177fb337d0.png)
先执行this.counter$这个Observable自带的operator:
![](https://img.haomeiwen.com/i2085791/3c7a2976f5da7ddf.png)
这个DistinctUntilChangedOperator来自:
![](https://img.haomeiwen.com/i2085791/302dd3357df9c41d.png)
![](https://img.haomeiwen.com/i2085791/741112c024e4e929.png)
![](https://img.haomeiwen.com/i2085791/1dc65a012201e766.png)
map操作符执行的逻辑就是:
source => pathOrMapFn(source ... )
![](https://img.haomeiwen.com/i2085791/5d5f937a22d119c3.png)
projectFn.apply最终会调用应用程序传入store.select里的函数:
![](https://img.haomeiwen.com/i2085791/9411935f371ee242.png)
![](https://img.haomeiwen.com/i2085791/ea02e791a89917f4.png)
我们自己实现的getter在这里被调用:
![](https://img.haomeiwen.com/i2085791/2f5e9b1027e912a2.png)
调用到应用程序自己的projector了:
![](https://img.haomeiwen.com/i2085791/2068cf3b7df495af.png)
![](https://img.haomeiwen.com/i2085791/a6a9df8e47a63cd6.png)
// 2020-11-05 3:36PM - 经过调试,最后发现,一旦对this.counter$调用
// subscribe,最终会触发fromExample.getCounterCounter, 后者
// 从当前最新的state里取数据
![](https://img.haomeiwen.com/i2085791/2960f6c8aefa3488.png)
更多Jerry的原创文章,尽在:"汪子熙":
![](https://img.haomeiwen.com/i2085791/7cc33388ba14e967.png)
网友评论