Change detection with Observable vs Immutable

后端 未结 2 1249
盖世英雄少女心
盖世英雄少女心 2021-02-05 13:37

So I read this article about Angular 2 change detection, but after reading it I have got more confused, so I started reading some of the comments which led to more confusion.

2条回答
  •  不思量自难忘°
    2021-02-05 14:15

    I don't get it how Observables are quite different from Immutables and in this specific case of the Todo app, which approach is better?

    Imagine that you have a tree of nodes, and each node has a bit that says "I may have changed". With Observable, we are talking about events getting emitted; the event is dispatched up the tree. In other words:

    • Todo_ChangeDetector would be flagged,
    • then walking up the tree, Todos_ChangeDetector would be flagged,
    • then walking up the tree, App_ChangeDetector would be flagged,
    • then the normal change detection kicks in.

    Imagine you have 2 todo lists:

    1. a grocery list.
    2. a list of meetings (work?) for the day.

    Which grocery list is active you are currently showing would be the Observable; e.g. a dropdown, nav pills, etc. All the todo items under those 2 lists could be Immutable; e.g. you are not the meeting organizer and cannot change the meetings.

提交回复
热议问题