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

Cannot define one callback per request #75

Closed
mjeanroy opened this issue Nov 24, 2011 · 7 comments
Closed

Cannot define one callback per request #75

mjeanroy opened this issue Nov 24, 2011 · 7 comments

Comments

@mjeanroy
Copy link
Contributor

If you subscribe to multiple topics, you cannot define one callback per subscriptions : all callbacks are always called.
Since "jQuery.atmosphere.request" has a "callback" property, I thought it was possible but no, because "invokeCallback" function don't look at it.
I looked at jQuery plugin and I think you can fix it by adding to "invokeCallback" function :

if (typeof(jQuery.atmosphere.request.callback) == 'function') {
  jQuery.atmosphere.request.callback(response);
}

I tested, it seems to work, but maybe it's not the best way to do it.

@jfarcand
Copy link
Member

I like it. Will add it now. Do you have a sample you can share so I can test?

@jfarcand
Copy link
Member

So the new code will looks like

       invokeCallback: function(response) {
        var call = function (index, func) {
            func(response);
        };


        if (typeof(jQuery.atmosphere.request.callback) == 'function') {
            jQuery.atmosphere.request.callback(response);
        } else {
            jQuery.atmosphere.log(logLevel, ["Invoking " + jQuery.atmosphere.callbacks.length + " callbacks"]);
            if (jQuery.atmosphere.callbacks.length > 0) {
                jQuery.each(jQuery.atmosphere.callbacks, call);
            }
        }
    }

Is that OK?

@mjeanroy
Copy link
Contributor Author

Yes, this is the idea.

But maybe, "jQuery.atmosphere.callbacks" schould be call even if "jQuery.atmosphere.request.callback" is defined.
With this, you can define one callback per request and "global" callbacks for all request. I don't know if it is the best choice, but I think it can be usefull to have "global" callbacks.

How I fixed it :

invokeCallback: function(response) {
    var call = function (index, func) {
        func(response);
    };

    // Invoke global callbacks
    jQuery.atmosphere.log(logLevel, ["Invoking " + jQuery.atmosphere.callbacks.length + " callbacks"]);
    if (jQuery.atmosphere.callbacks.length > 0) {
        jQuery.each(jQuery.atmosphere.callbacks, call);
    }
    // Invoke request callback
    if (typeof(jQuery.atmosphere.request.callback) == 'function') {
        jQuery.atmosphere.request.callback(response);
    }
}

I can write a sample you can test, where can I send it to you ?

@jfarcand
Copy link
Member

Make a lot of sence. Use jfarcand@apache.org

Thanks a lot!

@jfarcand
Copy link
Member

OK I've integrated it with a basic test. Still highly interested to a simple sample if you have a chance. Thanks a lot.

@mjeanroy
Copy link
Contributor Author

I just sent you my sample at jfarcand@apache.org.
Thanks!

@jfarcand
Copy link
Member

Works like a charm!!!

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