Advantages of using immutable.js over Object.assign or spread operators

前端 未结 6 966
天涯浪人
天涯浪人 2021-02-02 08:55

So far most of \"starter boilerplates\" and some posts about react / redux I\'ve seen encourage usage of immutable.js to address mutability. I personally rely on Object.as

6条回答
  •  -上瘾入骨i
    2021-02-02 09:45

    The advantage of immutable.js is that it enforces an immutable redux store (you might forget to extend, or do a sloppy job at protecting your store from modifications) and simplifies the reducers a lot compared to Object.assign or spread operators (both are shallow by the way!).

    That being said I've used redux+immutable in a big Angular 1.x project and there are downsides: performance issues, it's not clear what is immutable and what is not, Angular cannot use immutable.js structures in ng-repeat, etc. Not sure about React though, would love to hear opinions.

提交回复
热议问题