preserve the oa instance when it appears in data#177
Open
aaronj1335 wants to merge 1 commit into
Open
Conversation
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.
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this may be easiest to illustrate with code:
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.