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

Unable to detect changes on a deserialized array #2

Open
sdalexandre opened this issue Aug 18, 2021 · 1 comment
Open

Unable to detect changes on a deserialized array #2

sdalexandre opened this issue Aug 18, 2021 · 1 comment

Comments

@sdalexandre
Copy link

When I deserialize an object using the JsonSerializer the type of the array change. When displaying the constructor.name of the array, the name become "bound Array".

And then overriding the push() method for example doesn't work:

const MYTYPE_SERIALIZER = new JsonSerializer(MyType)

console.log(data.myArray.constructor.name); // It display "Array"
let myType = MYTYPE_SERIALIZER.deserialize(data, true);
console.log(myType .myArray.constructor.name); // It display "bound Array"

let myArray = myType.myArray;
myArray.push = function () {
        console.log("Debug");
        return Array.prototype.push.apply(this, arguments);
}
myArray.push("Something"); // The console.log("Debug") will not be called
@uon-io
Copy link
Contributor

uon-io commented Dec 9, 2021

@ArrayMember fields values get replaced with a Proxy to detect changes. The library keeps track of mutations on a @model decorated class instance. To get a list of mutations you can do:

import { GetMutations } from '@uon/model';

let mutations  = GetMutations(my_model_instance)

Hope this helps.

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