I'm using immutable.js with my flux application. It is very useful and gives performance boost. But what actually makes me sad is the fact that I can't use lodash together with it. Lodash provides great API with ton of useful functions, so I wonder maybe there is a way to get them together to work for me?
Immutability. In Lodash FP, the functions do not mutate the data they manipulate.
Using ImmutableJS can improve dramatically the performance of your application. And, because the immutable data never changes, you can always expect new data to be passed from the above. To make sure you are correctly comparing the data and not updating the UI when there is no change, you should always use the .
Immutable push is super fastjs is about 100x faster than push of native javascript . Note that when pushing an element to an immutable. js list, the list is not modified. A new list is returned with the element appended to it: this is how immutable collections work.
Immutable. js allows us to detect changes in JavaScript objects/arrays without resorting to the inefficiencies of deep equality checks, which in turn allows React to avoid expensive re-render operations when they are not required. This means Immutable. js performance tends to be good in most scenarios.
You could use Ramda if you want immutability and side-effect free functions.
The library provides useful functions similar to lodash but in a functional programming style that never mutates user data.
Consider this React example using the flatten function in Ramda using ES6 syntax.
import { flatten } from 'ramda';
const users = ['Steve Jobs', ['Steve Wozniak']];
const flatUsers = flatten(users);
// returns ['Steve Jobs', 'Steve Wozniak']
I've recently written a Lodash wrapper providing Immutable.JS support called mudash. Most of the major Lodash functions are supported with more being added regularly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With