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

Document additions/modifications to (Array|Object).prototype #95

Closed danny-andrews closed 7 years ago

danny-andrews commented 8 years ago

In the docs, it reads:

1. All the methods that would normally mutate the data structures instead throw ImmutableError.
2. All the methods that return a relevant value now return an immutable equivalent of that value.
3. Attempting to reassign values to their elements (e.g. foo[5] = bar) will not work. Browsers other than Internet Explorer will throw a TypeError if use strict is enabled, and in all other cases it will fail silently.
4. A few additional methods have been added for convenience.

Modifying built-in behavior of basic data structures is a pretty big deal, so it would be nice to have an exhaustive list of the modified/added methods in 1, 2, and 4.

rtfeldman commented 8 years ago

Fair enough. Happy to accept a PR for this! :smile:

estaub commented 8 years ago

(noob here, hopefully not too off-topic) It would be good to know (without testing) whether static object/array methods like Object.keys() will work. Nothing in the readme leads me to guess one way or the other.

crudh commented 8 years ago

@estaub yes, they will work. All objects and arrays are normal javascript objects and arrays with the exception that they are frozen and mutating methods throw errors.

danny-andrews commented 7 years ago

I actually don't think enumerating the modified built-in methods is that important anymore. The purpose of the library implies it's going to be doing that stuff. It's more important to know which methods have been added to the prototype (which is already documented). Although, from the examples, it's not clear that Array.prototype is modified, since the Immutable.METHOD_NAME version is used. Example: https://github.com/rtfeldman/seamless-immutable#flatmap.