-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
allow long subscriber chains #359
Conversation
This allows subscriber chains to be very long without stack overflow. This is only done for the default event; could probably be done for "beforeChange" also, but would be a more intrusive code change.
Ping? |
Ping? This change is relatively short and passes all tests (including a new test). Please let me know if there's anything I can do to make this change easier to accept. |
We're currently finishing up work on version 2.1. Afterwards, we'll be able to go through the waiting issues and pull requests. |
Great, thanks for the update. |
I haven't yet looked out your code in detail, but this will be on our list of items for version 2.2. Other possible implementations include @sciolizer's De-duping calls to evaluateImmediate, or parts of my deferred updates plugin. |
Great! I'm happy with anything that passes my test case with good efficiency. If you do go with either of the other solutions, please do test it with my test case. |
Needs to be reviewed in detail for any possible side-effects, but in principle, this sounds like a worthy improvement. I'd be pleased to have it in 2.2. Thanks Haberman! |
Hi there, it looks like you haven't gotten a chance to fold this change into knockout? I tried my test case with the latest repo and it is still failing with stack overflow. Anything I can do to help this change get accepted? Thanks, |
Here's my version of this that I just added to my Deferred Updates plugin: var oldnotifySubscribers = ko.subscribable.fn.notifySubscribers, notifyQueue;
ko.subscribable.fn.notifySubscribers = function (valueToNotify, event) {
if (event === 'change' || event === 'dirty' || event === undefined) {
if (!notifyQueue) {
try {
notifyQueue = [];
oldnotifySubscribers.call(this, valueToNotify, event);
if (notifyQueue.length) {
for (var i = 0, n; n = notifyQueue[i]; i++) {
oldnotifySubscribers.call(n.object, n.value, n.event);
}
}
} finally {
notifyQueue = null;
}
} else {
notifyQueue.push({
object: this,
value: valueToNotify,
event: event
});
}
} else {
oldnotifySubscribers.call(this, valueToNotify, event);
}
}; |
The code I attached above for As a compromise, I've come up with some changes (#1088) that provide a 100%+ increase in the maximum dependency depth. |
…four function call levels. Also reduce stack overhead by not using "call" in computed unless needed.
@haberman – If you have a look at the comments linked to this issue, you'll note that the plan is, at the moment, to have this problem persist on legacy Firefox, for two reasons:
The patch you proposed certainly looks to work, but it adds some complexity and does not extend to other event types that may also be affected. On that basis I'll close this issue, but please comment if you think we're missing something important here and we can certainly discuss/re-open. Sorry it took so long to get to this @haberman . I hope you found a workaround in the mean time! Cheers |
This allows subscriber chains to be very long
without stack overflow. This is only done for
the default event; could probably be done for
"beforeChange" also, but would be a more
intrusive code change.
This change passes all tests in my browser
(Chrome).
See: #358