New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subscribing to a computed when mapping #69
Comments
Fix up the first example by saving |
no effect |
During mapping, evaluation of I have to admit I think it should work even if you didn't explicitly evaluate the |
Thanks Roy. That is a better workaround. I'll use that. I'll have a look to see if i can follow the dependancy detection through. I've found that this is unrelated to throttling which might simplify things a bit. |
Ok. I think I found it !! In You maintain a list of unwrapped DOs in the array In The wrapper is never evaluated, and since I'm subscribing to the wrapper my function is never called. Not sure of the best solution but if you stored the wrapped DO in the array it should all work. So just swap lines 244 and 245: realDependentObservable = wrap(realDependentObservable);
dependentObservables.push(realDependentObservable); |
Of course evaluating the wrapper will remove it from |
Yes, spot on. Thanks for taking the time to dig a bit deeper. I'm preparing a fix right now, based on these suggestions. I'm also adding a unit test based on your original fiddle to make sure the problem stays away. |
Great work! I wanted to see whether you needed a doubly nested model (to simplify the test). But the fiddle just worked! LOL. It was because i'm using the code in the master branch which has been fixed. :) This is a version before the fix with only a single nested object and you do still get the bug. That being said. Normally, when i subscribe to a DO, the function only gets called after the first change. in this case it gets called by I guess I could set Thanks again! |
Currently all DO's are wrapped, whether Maybe you can play around a bit and report your findings? It's definitely an easy fix to do. |
No. It isn't wrapped if your DO already has if (!realDeferEvaluation) {
dependentObservables.push(realDependentObservable);
realDependentObservable = wrap(realDependentObservable);
} of course for this to work correctly you'd need to swap var realDeferEvaluation = options.deferEvaluation; and if (read && typeof read == "object") { // mirrors condition in knockout implementation of DO's
options = read;
} Currently if you did |
Oh, right. Apologies for the misinformation, I'm juggling too many things at the moment. :) If you feel so inclined, a unit test + pull request for this functionality is more than welcome! |
Simplify subscriber test. As discussed in #69
In trying to test the behaviour described above. I have uncovered a more serious bug. I will start a new Issue for it. |
Ok. I've fixed issue #71 but now i don't think there's any way of testing the above behaviour without putting in some debug code like I've tried var realDO = ko.dependentObservable;
ko.dependentObservable = function(read, owner, options){
var result = realDO(read, owner, options);
result.real = ko.dependentObservable.real;
return result;
}
ko.dependentObservable.real = true;
var mapped = ko.mapping.fromJS(obj, mapping);
equal(mapped.inner.DO1.real, true)
equal(mapped.inner.DO2.real, undefined) but of course Any thoughts? |
I think the |
Just realised knockout.mapping doesn't support the DEBUG check. In knockout it is added in the build script https://github.com/SteveSanderson/knockout/blob/master/build/build-windows.bat#L31 But this would require restructuring the code a bit. Would you be cool to add this? |
Are you asking if it's okay for you to add it, or if I want to add it? :) In both cases the answer is 'yes' but I am not currently behind a coding machine. |
I was asking if you'd like to. If you let me know what it's in I'll add this test+fix. |
Ok! I'll try to take some time over the weekend to do this. |
James, the |
Thanks Roy. Pull request 73 includes pull request 72 which I rebased to the current master. Don't use github to merge both because i think you'll end up with duplicate commits. It's a shame github doesn't allow a fasforward merge :( Probably best to merge outside of github and push. Thanks James |
Merge complete! I'll create a v2.1.2 release from this. |
Hi I've set up a simple demo of the issue I'm having
http://jsfiddle.net/x3PLB/
I'm not sure if it requires a doubly nested model but it more accurately reflects my scenario. If you look at
InnerInner
you can see I've setup a computed which merely depends onX
Y
andZ
. and a subscription to that computed which prints "test" to the console.The idea is to throttle these three observables together.
I seems that because
ko.computed
is being overridden while mapping, throttling doesn't work. The throttle extender returns a wrapped computed and so does knockout.mapping... maybe there's a clash there?One work around I've found is...
However, this wouldn't work for a writable computed (which is why it requires a wrapper).
(The delay is required to avoid raising the subscribe method before the first change.)
Any help would be appreciated.
Cheers
Update: I've found that this is not related to throttling
http://jsfiddle.net/x3PLB/3/
The text was updated successfully, but these errors were encountered: