adopted-ember-addons / validated-changeset

Buffering changes to form data
MIT License
36 stars 27 forks source link

Fix findSiblings and the target kept its prototype #175

Open sapryniukt opened 2 years ago

sapryniukt commented 2 years ago

We ran into the issue of losing prototype and incorrect invocation of setDeep when tried to change the EmberData property in the changeset.

My changeset looked something like this:

data: {
    "name": "Jim Bob",
    "address": CountryModel {
        "country": "US",
        "address1": "",
    }
}

but after execution:

changeset.set("address.address1", "some");

We got:

changes: {
    "name": "Jim Bob",
    "address": Object {
        "address1": "some",
    }
}

Looks like findSiblings works well with POJO, but doesn't consider Class object. I proppose a simple solution to this by using

Object.setPrototypeOf(obj, prototype)

or

Object.create(prototype)

Also the tests that check and reproduce the issue have been added.