Skip to content
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

Knockout computed update notification sometimes not firing #24

Closed
nmehlei opened this issue Oct 3, 2014 · 5 comments
Closed

Knockout computed update notification sometimes not firing #24

nmehlei opened this issue Oct 3, 2014 · 5 comments

Comments

@nmehlei
Copy link

nmehlei commented Oct 3, 2014

I am currently investigating a very weird bug in my application which seems to be strongly-related to the ko-deferred-updates v.3.2.0.

When using the newest version, sometimes (in a very hard to reproduce way) either the update notification of a changed computed is not sent or subscribing computed's just ignore said notification. Either way I detect bindings that stay frozen in states, dependent computed's that get corrupted computations because they use old values, etc.

It may be the same for normal observables but since I use more computed's than observables, I did not find such a case with observables in my application yet.

Unfortunately I was unable to find a reproducible way.
Used Knockout version is the newest, 3.2.0.
This does not happen when using ko-deferred-updates v.3.1.0 (albeit with a small hack to deactivate the version check to use it for ko 3.2.0, which worked perfectly for months) and thus only started to occur since the last update.

@mbest
Copy link
Owner

mbest commented Oct 9, 2014

Thanks for reporting this. I've come up with an example that reproduces the problem.
http://jsfiddle.net/mbest/cq8qp42b/

function ViewModel() {
    var self = this;
    self.x = ko.observable(1);
    self.y = ko.computed(function() {
        return self.x() * 2;
    }).extend({throttle:1000});
    self.update = function() {
        self.y();
    }
}

If update is called after x is changed and before the 1000 ms timeout, the computed never fires a change notification. This example makes it easy to test, but this problem could happen without using throttle if the timing was right.

@mbest
Copy link
Owner

mbest commented Oct 9, 2014

Here's a much simpler example. http://jsfiddle.net/mbest/33wmc6rn/

function ViewModel() {
    var self = this;
    self.x = ko.observable(1);
    self.y = ko.computed(function() {
        return self.x() * 2;
    });
    self.update = function() {
        self.x(self.x()+1);
        self.y();
    }
}

I'm working on fix now.

@mbest mbest closed this as completed in 97db591 Oct 9, 2014
@nmehlei
Copy link
Author

nmehlei commented Oct 9, 2014

Awesome!
I'll try it out later today, thank you so much.

@mbest
Copy link
Owner

mbest commented Oct 14, 2014

Did it work for you?

@nmehlei
Copy link
Author

nmehlei commented Oct 15, 2014

Oh, I'm so sorry, forgot to report.
Yes it worked perfectly, thanks!

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

No branches or pull requests

2 participants