-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Observable, when used on an array, does work when mutating array methods have been overwritten #6920
Comments
Sorry but this is usage that we will not support because there are just too many possible edge cases to consider if we were to make Vue compatible with arbitrary modifications to built-in types. |
Thank you for the quick response. const A = class extends Array {
constructor() {
super();
}
push(...args) {
console.log("push() called");
return super.push(...args);
}
} Although I know VueJS alters my data structure slightly to enable reactivity, my expectation would be that it does not actually lose any of the functionality I might have on that data. /Paul |
@yyx990803 Should I pursue discussion this somewhere else? forums? I certainly don't want to spend time opening up the discussion if you are not going to entertain pursuing a solution. |
Probably should open a fresh feature request to support reactivity on subclassed Arrays. |
Version
2.5.2
Reproduction link
https://jsbin.com/fekeduvaqo/edit?js,console,output
Steps to reproduce
push()
method by overriding the method directly on the array instanceWhat is expected?
That VueJS's reactive system detects mutations to the array
What is actually happening?
VueJS does not react to array mutations.
I ran into issue because I have a code base that already uses a similar pattern for observing data.
In looking at the source, the Array prototype is created using the Array.prototype and then simply applied to the instance by replacing
__proto__
. I think the solution would be to move that logic to protoAugment() and/or to copyAugment() by storing the "original method" before overriding it and then ensuring the original is called..Another observation is that protoAugment does not take into consideration method override done on the instance of an Array... The custom
__proto__
will never be reached in these cases. So even my suggested solution would not help in these cases./Paul
The text was updated successfully, but these errors were encountered: