官术网_书友最值得收藏!

Summarizing

Our cleanup started with the view; we wanted to remove a direct connection to the dispatcher and also stop having to use magic strings as this is quite error prone, and it's easy to misspell. Instead, we can rely on constants. To remedy this, we created an action creator class that talked to the dispatcher instead.

We also created a constants module to remove the magic strings. 

Furthermore, we improved the store by starting to use EventEmitter. Finally, we further improved the store by adding more actions to it and also started to refer to the constants.

At this point, our solution is ready for more actions to be added to it and we should feel pretty clear on what files we need to add to, as we support more and more user interactions.

Lastly, we added improvements around ES2015 and immutability, which made our code look a lot cleaner. With this foundation, we are now ready to go from static data to involve working with side effects and Ajax in the upcoming section.

Let us summarize all our improvements in a diagram showing the constructs added to our flow:

It is clear that using an action creator isn't strictly necessary but it does clean up the code quite a bit, and the same goes for using an EventEmitter in the store; it's nice but not necessary.

主站蜘蛛池模板: 滦平县| 曲阜市| 滦平县| 祁门县| 新宾| 武隆县| 灵川县| 杭锦后旗| 怀来县| 河源市| 榆树市| 长顺县| 龙海市| 张掖市| 东莞市| 星座| 茂名市| 文安县| 桓台县| 攀枝花市| 洪洞县| 稻城县| 亚东县| 平山县| 遵义县| 天水市| 鄂尔多斯市| 西贡区| 漠河县| 陕西省| 荃湾区| 墨竹工卡县| 兴仁县| 民县| 尤溪县| 额尔古纳市| 天气| 九龙城区| 大关县| 富锦市| 延边|