mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 07:57:02 +03:00
KnockoutJS use Symbol for isObservableArray()
This commit is contained in:
parent
5225b62a0a
commit
7ca5991041
3 changed files with 34 additions and 42 deletions
|
|
@ -7,12 +7,12 @@ ko.observableArray = initialValues => {
|
|||
return Object.setPrototypeOf(ko.observable(initialValues), ko.observableArray['fn']).extend({'trackArrayChanges':true});
|
||||
};
|
||||
|
||||
//const IS_OBSERVABLE_ARRAY = Symbol('IS_OBSERVABLE_ARRAY');
|
||||
const IS_OBSERVABLE_ARRAY = Symbol('IS_OBSERVABLE_ARRAY');
|
||||
|
||||
// Note that for browsers that don't support proto assignment, the
|
||||
// inheritance chain is created manually in the ko.observableArray constructor
|
||||
ko.observableArray['fn'] = Object.setPrototypeOf({
|
||||
// [IS_OBSERVABLE_ARRAY]: 1,
|
||||
[IS_OBSERVABLE_ARRAY]: 1,
|
||||
'remove'(valueOrPredicate) {
|
||||
var underlyingArray = this.peek();
|
||||
var removed = false;
|
||||
|
|
@ -63,11 +63,7 @@ Object.getOwnPropertyNames(Array.prototype).forEach(methodName => {
|
|||
}
|
||||
});
|
||||
|
||||
//ko.isObservableArray = obj => !!(obj && obj[IS_OBSERVABLE_ARRAY]);
|
||||
ko.isObservableArray = instance =>
|
||||
ko.isObservable(instance)
|
||||
&& typeof instance["remove"] == "function"
|
||||
&& typeof instance["push"] == "function";
|
||||
ko.isObservableArray = obj => !!(obj && obj[IS_OBSERVABLE_ARRAY]);
|
||||
|
||||
ko.exportSymbol('observableArray', ko.observableArray);
|
||||
ko.exportSymbol('isObservableArray', ko.isObservableArray);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue