Comments (11)
is it appending? as I am sure there is a boolean you can pass in that tells it to replace or append.
from knockout.merge.
Turns out I was thinking of the merge constructor:
ko.observableArray.fn.withMergeConstructor = function(mergeConstructor, replaceOnMerge) {
this.mergeConstructor = mergeConstructor;
if(replaceOnMerge) {
this.replaceOnMerge = replaceOnMerge;
}
return this;
}
Which has the boolean to replace or append on merge, so wont be applicable here.
from knockout.merge.
On a side note given a few people use this lib now it may be worth adding some unit tests to it so at least there are some scenarios to test for all these things, if I get a moment in the week I will try to add some.
from knockout.merge.
@grofit some automated tests would be good. I get a little lost as soon as people start getting complex build processes, but happy to try and add some simple Jasmine tests etc at some point. I'm basically writing a couple of small tests in a JSFiddle while I'm trying to fix.
from knockout.merge.
Yeah I didnt want to require nodejs to test it all, and I just never bothered adding jasmine. Have done so now so will add more tests as I go, feel free to fill in the gaps.
from knockout.merge.
@grofit almost got a fix for this. I'll add some tests when I create a fork. Quick question - you ever had any issues with observable arrays not updating subscribers?
I'm currently using the following:
// If we have an observable array and a data element which is an array
// then we need to merge the values item by item
for (var i = 0; i < dataElement.length; i++) {
// We don't yet have an item in the array so we need to
// create one. Use a placeholder and the standard merge
// logic to do this
if (i >= knockoutElement().length) {
var placeholder = {};
exports.fromJS(placeholder, dataElement[i]);
knockoutElement.push(placeholder);
} else if (isPrimitive(knockoutElement()[i]) && isPrimitive(dataElement[i])) {
knockoutElement().splice(i, 1, dataElement[i]);
} else {
exports.fromJS(knockoutElement()[i], dataElement[i]);
}
}
What I'm finding is that I jump to the knockoutElement().splice(i, 1, dataElement[i]);
and the array gets updated correctly, but anything that's listening to the array doesn't seem to update properly. I've had to put a knockoutElement.notifySubscribers();
to get this working properly in our codebase but I can't quite figure out why I need it.
from knockout.merge.
Not that I can remember, what version of KO are you using?
from knockout.merge.
@grofit 3.3 debug version from cdnjs.com
from knockout.merge.
@grofit nevermind, had an extra ()
that I didn't need in there. Got a fix, will write some tests quick then issue a pull request. Thanks :)
from knockout.merge.
@grofit love the speed at which I submit a pull request and it gets merged in :) Thanks!
from knockout.merge.
❤️ Github
from knockout.merge.
Related Issues (13)
- More of question than issue: callbacks HOT 6
- Add a License HOT 2
- Ability to create missing observables on a merge HOT 19
- Properties with Null Value HOT 2
- Observable with extender is not being written to HOT 7
- Merge of Arrays HOT 3
- Initialize constructor with data HOT 5
- Add the ability to infer types for sub objects HOT 1
- Can't get working with RequireJS HOT 18
- Uncaught Error: Pass a function that returns the value of the ko.computed HOT 1
- Publish on NPM HOT 1
- Complex Merge doesn't seem to work correctly HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout.merge.