What are benefits of using store (ngrx) in angular 2

后端 未结 3 385
旧时难觅i
旧时难觅i 2020-12-12 16:07

I\'m working on a angular 1.x.x project and thinking about upgrading my code to angular 2.

Now in my project I have many services

3条回答
  •  孤街浪徒
    2020-12-12 16:40

    A nice explanation about the benefis of using a store you can find in there documentation

    Centralized, Immutable State

    All relevant application state exists in one location. This makes it easier to track down problems, as a snapshot of state at the time of an error can provide important insight and make it easy to recreate issues. This also makes notoriously hard problems such as undo/redo trivial in the context of a Store application and enables powerful tooling.

    Performance

    Since state is centralized at the top of your application, data updates can flow down through your components relying on slices of store. Angular 2 is built to optimize on such a data-flow arrangement, and can disable change detection in cases where components rely on Observables which have not emitted new values. In an optimal store solution this will be the vast majority of your components.

    Testability

    All state updates are handled in reducers, which are pure functions. Pure functions are extremely simple to test, as it is simply input in, assert against output. This enables the testing of the most crucial aspects of your application without mocks, spies, or other tricks that can make testing both complex and error prone.

    Multiple stores?

    IMO use one store and add your data types as properties in your store.

提交回复
热议问题