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

Added delegate/undelegate fallbacks to bind/unbind and fixed broken Zepto/Dojo delegate implementations #760

Closed
wants to merge 6 commits into
base: minor
from

Conversation

Projects
None yet
1 participant
@andykant
Contributor

andykant commented Mar 3, 2014

can.delegate and can.undelegate (in util/LIBRARY/LIBRARY.js) don't implement fallback binding for objects for non-elements and objects that don't explicitly define delegate/undelegate. (#754)

This is an updated pull request based on the minor branch instead of master. (see #758 for the original pull request)

Additionally, the existing Zepto/Dojo delegate methods completely fail in cases where the selector === "".

This pull request fixes these issues by having can.delegate/undelegate fallback to their can.bind/unbind counterparts in cases where normal object instances don't implement delegate/undelegate. Also included is the addition of can/util/event and can/control/modifier tests to the tests run with all libraries in test/* as well as adding test/jquery-2.html to test/index.html.

For example in util/jquery/jquery.js:

delegate: function(selector, ev , cb){
    if(this.delegate) {
        this.delegate(selector, ev , cb)
    }
     else if(isBindableElement(this)) {
        $(this).delegate(selector, ev, cb)
    } else {
        // make it bind-able ...
    }
    return this;
},
undelegate: function(selector, ev , cb){
    if(this.undelegate) {
        this.undelegate(selector, ev , cb)
    }
     else if(isBindableElement(this)) {
        $(this).undelegate(selector, ev, cb)
    } else {
        // make it bind-able ...

    }
    return this;
},

The problem with this is there are portions of the CanJS codebase that call .delegate instead of .bind. Specifically, modifier functions like in can/control/modifier.

steal("can/construct", "can/control", "can/control/modifier", function(Construct, Control) {
    Construct("SomeObject", {
        bind: can.bind,
        unbind: can.unbind,
        dispatch: can.dispatch
    });

    Control('SomeClass', {
        init: function() {
            this.options.some_object = new SomeObject();
            this.on();
        },
        "{some_object} some_event:debounce(100)": function() {
            // THIS NEVER FIRES
        }
    });

    var control = new SomeClass(document.body);
    control.options.some_object.dispatch("some_event");
});

andykant and others added some commits Feb 28, 2014

Adding .bind()/.unbind() fallback calls to .delegate/.undelegate in l…
…ibrary support files (#754)

Conflicts:
	util/dojo/dojo.js
	util/mootools/mootools.js
	util/yui/yui.js
Fixed delegate/undelegate in Dojo and Zepto
Added fallbacks but also reverted to can.bind/unbind when no delegate
selector was specified.

Conflicts:
	util/dojo/dojo.js

@andykant andykant added the Bug label Mar 3, 2014

@andykant

This comment has been minimized.

Show comment
Hide comment
@andykant

andykant Apr 4, 2014

Contributor

Closing, as these changes are now included in #870.

Contributor

andykant commented Apr 4, 2014

Closing, as these changes are now included in #870.

@andykant andykant closed this Apr 4, 2014

@andykant andykant deleted the delegate-fallback-2 branch Apr 4, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment