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
sizeorcountwithlength - Removed
toJs,fromJSandasImmutable - Replaced
first,getandgetInwith lodash get: https://lodash.com/docs/4.17.15#get - Replaced
setby 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
setInwith same approach ofsetbut verifying manually on aifstatement if object has the property that allows me to alter it's value (example:if (o && o.a) { o.a.b = newValue }) - Replaced
findEntrywithfindfrom javascript - Replaced
deletewithsplicefrom javascript - Replaced
addon aSetto 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]+