Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy conversion between mutable and immutable with prototype methods. #5

Open
nmn opened this issue Apr 8, 2015 · 0 comments
Open

Comments

@nmn
Copy link
Contributor

nmn commented Apr 8, 2015

There are lots of methods already defined on the prototypes of the types.

I propose two more methods. The idea is to have the same capability as 'fromJS' and 'toJS' as seen on 'immutable-js'
On all the immutable types:

.toMutable

This would return a new mutable object/array/Map/Set with the same data as the Immutable value. It will not mutate the Immutable Type.

On the other hand, the Object.prototype, Array.prototype, Map.prototype and Set.prototype, should get one extra method:

.toImmutable

This would return a new Immutable type with the same values as the ones in the mutable types.

  • In case of Objects, only the keys that are on the object themselves (and not prototypes) will be copied over.
  • In case of arrays, and 'holes' will be converted to undefined
  • There doesn't seem to be any edge cases with Maps of Sets.

These methods will also be recursive, as in all sub values, will be made mutable/immutable as well.

Polyfills for these methods are fairly trivial, and I'll be posting them here in more comments soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant