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

subscription.suspend() / .continue() #270

Closed
Bombo opened this issue Jan 11, 2012 · 1 comment
Closed

subscription.suspend() / .continue() #270

Bombo opened this issue Jan 11, 2012 · 1 comment

Comments

@Bombo
Copy link

Bombo commented Jan 11, 2012

Hello Steve,

I was having a little fun with manual subscriptions and the possibility to dispose one in cases where I didn't need or want the subscription to fire. After finishing all the operations needed, I create a new subscription with the same callback. Seemed to work just fine in most cases.

Sadly though the disposed subsciprion obviously looses its place in the subscription queue and thus has a lower priority than a foreach-template subscription.

When some new properties on array elements are needed for the template and those properties are usually set via the disposed and renewed manual subscription the templating obviously fails.

To cut a long story short: It would be nice, if a manual subscription could be suspended and continued at a later point in time. The code changes to support this behaviour doesn't seem too big. But maybe that's just my newbie eye on that matter. :)

Thanks in advance!
Boris

@mbest
Copy link
Member

mbest commented Dec 14, 2012

I don't think this is a common need, and it can be handled by a simple extension:

ko.subscribable.fn.supsendableSubscribe = function(callback, callbackTarget, event) {
    var isSuspended = false;
    return ko.utils.extend(this.subscribe(function () {
            if (!isSuspended)
                return callback.apply(this, arguments);
        }, callbackTarget, event), {
            suspend: function() { isSuspended = true; },
            unsuspend: function() { isSuspended = false; }
        });
};

@mbest mbest closed this as completed Dec 14, 2012
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