rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

undefined === isImmutable? #223

Open bradennapier opened 7 years ago

bradennapier commented 7 years ago
const mutableObject = Immutable.isImmutable(undefined)
   ? Immutable.asMutable(undefined)
   : undefined

this causes an error because undefined is immutable to the isImmutable request for some reason then it fails to make it mutable (obviously).

bradennapier commented 7 years ago

In your source I found this

} else {
      // In JavaScript, only objects are even potentially mutable.
      // strings, numbers, null, and undefined are all naturally immutable.
      return true;
    }

which to me is an issue - my goal is to check if the item is an immutable object so i know if i need to convert it or not

seems like maybe asMutable should return an object or value that , if immutable has modified, converts it back to an untouched value. therefore could do Immutable.asMutable(undefined) and simply get back undefined.