Skip to content

Conversation

aaronj1335
Copy link

this may be easiest to illustrate with code:

var o = ko.observable()
var oa = ko.observableArray()
var model = {};

ko.mapping.fromJS({o: o, oa: oa}, model);

equal(model.o, o); // this is currently true
equal(model.oa, oa) // this isn't true, but is fixed with this commit

the problem is that using ko.mapping, if you've got an existing OA,
there's no way to update a viewmodel with the existing OA, a new one is
always created.

this pull request provides a way to update viewmodels to reference
pre-existing observable arrays.

this may be easiest to illustrate with code:

```js
var o = ko.observable()
var oa = ko.observableArray()
var model = {};

ko.mapping.fromJS({o: o, oa: oa}, model);

equal(model.o, o); // this is currently true
equal(model.oa, oa) // this isn't true, but is fixed with this commit
```

the problem is that using ko.mapping, if you've got an existing OA,
there's no way to update a viewmodel with the existing OA, a new one is
always created.

this pull request provides a way to update viewmodels to reference
pre-existing observable arrays.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we know here that rootObject is an array (because isArray is true). if it's also a function, then we know it's an observableArray, so we want to preserve that reference, so if the viewmodel is updated, so is the original observable array.

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

Successfully merging this pull request may close these issues.

1 participant