Skip to content

Commit

Permalink
Merge pull request knockout#827 from paglias/733-observableArray-non-…
Browse files Browse the repository at this point in the history
…array-value

fixes knockout#733
  • Loading branch information
rniemeyer committed Mar 16, 2013
2 parents 788f66d + 43ab750 commit f1c8a2d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/subscribables/observableArray.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
ko.observableArray = function (initialValues) {
if (arguments.length == 0) {
// Zero-parameter constructor initializes to empty array
initialValues = [];
}
if ((initialValues !== null) && (initialValues !== undefined) && !('length' in initialValues))
initialValues = initialValues || [];

if (typeof initialValues != 'object' || !('length' in initialValues))
throw new Error("The argument passed when initializing an observable array must be an array, or null, or undefined.");

var result = ko.observable(initialValues);
ko.utils.extend(result, ko.observableArray['fn']);
return result;
}
};

ko.observableArray['fn'] = {
'remove': function (valueOrPredicate) {
Expand Down Expand Up @@ -89,7 +87,7 @@ ko.observableArray['fn'] = {
this.valueHasMutated();
}
}
}
};

// Populate ko.observableArray.fn with read/write functions from native arrays
// Important: Do not add any additional functions here that may reasonably be used to *read* data from the array
Expand Down

0 comments on commit f1c8a2d

Please sign in to comment.