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

Support classes #4

Closed
peterholak opened this issue Feb 1, 2017 · 2 comments
Closed

Support classes #4

peterholak opened this issue Feb 1, 2017 · 2 comments

Comments

@peterholak
Copy link

peterholak commented Feb 1, 2017

Hi, great library, I love the idea of not having to use any special structures to achieve immutable updates.

Would it be possible to also support ES6 classes when updating the object? Right now, if I have

class Hello {
    constructor(world) { this.world = world }
    say() { console.log(this.world) }
}
const a = new Hello("World")

and I update a, the resulting object no longer has the same __proto__, so I can't call say on it, etc.

@peterholak
Copy link
Author

peterholak commented Feb 2, 2017

At first glance, looks like this could be achieved by simply replacing the extend function you use with one that first creates the "destination" object with Object.create(Object.getPrototypeOf(value)) before assigning the properties to it.

@Yaojian
Copy link

Yaojian commented Apr 15, 2017

in the quickCopy function, using new obj.constructor() to create instances of ES6 classes.

Object.create(Object.getPrototypeOf(value)) does not support ES6 collection types (i.e. Map, Set) because they use native constructors.

See this stackoverflow question.

BTW, if you want a test, you can use it
npm install https://github.com/Yaojian/ImmutableAssign.git --save before @engineforce merging the pull request.

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

2 participants