-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 extended array #456
Comments
To achieve this behaviour you have to extend mobx internal class class CollectionPage<T> {
@observable data: IObservableArray<T>
@observable page: number
@observable pageCount: number
constructor(data: T[], page: number, pageCount: number) {
this.data = observable(data);
this.page = page;
this.pageCount = pageCount;
}
} |
Allright, I suppose there are no plans to add support for extending |
Nope, it is not a much requested feature and might make other generic functionality harder in general. |
No, observable array will actually be gone in the future in favor of real
arrays with proxies. So that brings you back to what you should do: extend
the Array class.
....
....
Which is not possible in javascript. (Well, it is limited)
…On di 2 jan. 2018 17:05 Francesco ***@***.***> wrote:
No hope?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#456 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhMGNWJT4dXr0IlNbrLfmzw-gMAXPks5tGlO9gaJpZM4JathS>
.
|
Thanks for the answer, I got the point. |
Actually doesn't that mean that you can create own observable iterable once proxy overlords come to us? class CollectionPage extends Array {
constructor(data, page, pageCount) {
super();
this.page = page;
this.pageCount = pageCount;
this.push.apply(this, data);
}
}
var inst = new CollectionPage(["cookies", "foos", "bars"], 0, 5);
var prox = new Proxy(inst, {
set: function (obj, prop, value) {
console.log('change', obj, prop, value); obj[prop] = value;
return true;
}
});
console.log(inst);
prox[1] = "milk";
prox.page = 3;
prox.pop();
prox.push("more milk");
console.log(inst); This works fine in chrome console right now, so I'd expect |
I've got follwing class:
Is there a way to transform instance of this class into an observable array while keeping both extra properties?
The text was updated successfully, but these errors were encountered: