Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js and Immutable.js

I'm working on a Vue.js application where I have to deal with deeply nested data structures (trees and forests).

After reading about using simple data structures, pure functions and reducing (non-local) mutation, I belief that embracing those ideas would increase the maintainability and simplicity of my code.

While implementing a tree manipulation module using nothing but pure functions, I learned two things:

  • avoiding unintentional mutation of nested objects in JavaScript requires a lot of attention and discipline, especially with larger teams
  • I don't like littering my code with cloneDeep() invocations

Yesterday, I stumbled upon Immutable.js, which looks great to me. After a bit of playing around with it, I feel like it makes my pure functions much easier to reason about.

My Vue.js components would use fromJS(treeNode) and treeNode.toJS() when interacting with the manipulation module.

My question: is it technically possible to Vue.js and Immutable.js together? What are things to keep in mind? Are people using this combination in production? I found this post, which seems to suggest the opposite. That's all I could find.

What are the caveats or practical downsides? Would you suggest to use Immutable.js or to keep deeply cloning regular objects?

edit: updated my question in response to the votes, to make it (less) opinion-based

like image 309
Willem-Aart Avatar asked Jan 27 '18 11:01

Willem-Aart


People also ask

Is Vue immutable?

VueJS is designed to be mutable so that they can be tracked by Vue, while immer tries to achieve the opposite. It doesn't add any value.

Is immutable js still used?

Update on 12 Aug 2021 Happily, the creator of Immutable JS resumed to maintaining his lib, and commits are regular now.

What is immutable js?

Immutable. js is a library that supports an immutable data structure. It means that once created data cannot be changed. It makes maintaining immutable data structures easier and more efficient. The tool supports data structure like: List, Map, Set and also structures that are not implemented in .

How is Vue different from JavaScript?

js is a cross-platform and open-source back-end framework that executes JavaScript code on the server-side. Vue. js is a structural, open-source JavaScript framework that is used for building UIs and single-page applications.


1 Answers

Just reading about this myself, and apparently not: https://forum.vuejs.org/t/immutable-js-with-vue/6366

like image 116
Dave Stewart Avatar answered Sep 27 '22 17:09

Dave Stewart