Skip to content

Support classes #4

Closed
Closed

Description

@peterholak

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.

Activity

  1. peterholak commented on Feb 2, 2017

    @peterholak
    Author

    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.

  2. Yaojian commented on Apr 15, 2017

    @Yaojian

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions