Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to use immutable.js with lodash?

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?

like image 295
Glen Swift Avatar asked May 07 '15 19:05

Glen Swift


People also ask

Is Lodash set immutable?

Immutability. In Lodash FP, the functions do not mutate the data they manipulate.

Should I use immutable js?

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 .

Is immutable js fast?

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.

Why use immutable js react?

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.


2 Answers

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']
like image 168
Brett Hayes Avatar answered Sep 17 '22 18:09

Brett Hayes


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.

like image 29
Brian Neisler Avatar answered Sep 17 '22 18:09

Brian Neisler