Difference in performance between ngrx and ngxs?

给你一囗甜甜゛ 提交于 2020-07-18 03:31:10

问题


I want to use ngxs for state management in my Angular 6 application.

But I am not sure if it is mature for big projects.

I can not find any articles about Difference in performance between ngrx and ngxs. Can someone provide some info about it?

Performance metrics: Getting a large number of items form the store and writing back into the store.


回答1:


Here is good answer from Reddit (Angular2+ community). It's from a developer who tested both and switched to NGXS.

I would like to share my experience. We have a medium-large enterprise app. We started with NGRX, but it quickly became clear that

NGRX code is much difficult to understand and write to teammates.

NGRX is boilerplate hell. You spend lot of time with it.

The concept of "Effects" is good, but it just adds extra layers of complexity which could be simplified.

Developer Experience (DX) was horrifying.

Then we switched to NGXS.

It has minimum boilerplate. You jump right into "action" :D.

We were delighted by its DX.

It is much easier to understand for teammates and everybody was suddenly productive.

There are some tradeoffs like server calls are in reducers, but it made sense to use after a while.

PLUGINS! There are loads of plugins from logging to forms handling (Awesome thing ever).




回答2:


From what I'm experiencing, NGXS is way simpler to write and it's easier to work with lazy loaded states. It has such a simple syntax, it's OOP, instead of Redux FP paradigm. Decorate your actions and selectors, subscribe to memoized states, catch dispatched actions anywhere, etc.

However, I found a pitfall when it comes to the storage plugin which is essentially for offline first applications. It uses sync local storage which has a limit of 5MB and will stall the UI when it needs to write big data to storage. However you could write a custom storage solution on top of the plugin. It's scalable, extensible, you can inject the util classes in a breeze, the documentation is as simple as it can be.




回答3:


I recently had a problem with NGRX, since I had to dispatch two actions, but the second depended on the success of the first, the problem was that the Reducers run asynchronously, and the second action ended without the first one having finished, try to solve it with an Effects , but even there the same thing happened. With NGXS I could solve it since the Dispacher returns an observable at the end of the action.

In general NGXS has worked very well, and the performance is very similar, I had to update a lot of data in an architecture with several nested levels, and there does not seem to be a difference in the update time.



来源:https://stackoverflow.com/questions/50704430/difference-in-performance-between-ngrx-and-ngxs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!