I decided to remove all Immutable code on our big project because it wasn't causing our React to render less (using selectors on our redux layer was actually better).
Since our project has tests to check if everything is still working, I was able to achieve that with the following steps:
Search on all files on vscode or any editor with Use Regular Expression
option (command+alt+r on vscode):
(Immutable|\.(size|count\(|toJS(?!\w)|fromJS(?!\w)|first[\(\)]|get\(|set\(|findEntry\(|getIn\(|setIn\(|contains\(|delete\(|asImmutable|add\())
Then on each find that was actually from a Immutable code:
- Remove Immutable imports
- Replaced
size
orcount
withlength
- Removed
toJs
,fromJS
andasImmutable
- Replaced
first
,get
andgetIn
with lodash get: https://lodash.com/docs/4.17.15#get - Replaced
set
by first copying the object with lodash cloneDeep: https://lodash.com/docs/4.17.15#cloneDeep and then actually assigning direct values on the copyed object - Replaced
setIn
with same approach ofset
but verifying manually on aif
statement if object has the property that allows me to alter it's value (example:if (o && o.a) { o.a.b = newValue }
) - Replaced
findEntry
withfind
from javascript - Replaced
delete
withsplice
from javascript - Replaced
add
on aSet
to just adding to an Array and then using lodash uniq: https://lodash.com/docs/4.17.15#uniq
Also Check reduces with 3 params (Immutable Maps reduce) by searching with:
\.reduce\(\([\w\s]+,[\w\s]+,[\w\s]+