Skip to content

Instantly share code, notes, and snippets.

@tehmou
Created July 31, 2017 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tehmou/20bd8431ec6a89cb5fe6615367375e83 to your computer and use it in GitHub Desktop.
Save tehmou/20bd8431ec6a89cb5fe6615367375e83 to your computer and use it in GitHub Desktop.
Check a JS immutable object for plain mutable objects
import { Iterable } from 'immutable'
function checkIsImmutable(obj, path = '') {
if (Iterable.isIterable(obj)) {
obj.keySeq().forEach(key => {
checkIsImmutable(obj.get(key), path + '.' + key);
});
} else if (typeof obj === 'object' && obj !== null) {
console.warn(path + ' was not immutable');
} else {
// Basic type
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment