Continuing my blog on dojo.attr()....

I've realized that if you use dojo.attr to connect an event, you're
pretty much stuck with it and can't disconnect it.

dojo.attr(node, "onmouseover")
- in FF returns null
- in IE returns the anonymous function from somewhere in dojo.connect.

I think it would be preferable to return the handle to the connection.
Or more accurately, an array of handles, in the case of more than one
connection.


Mike Wilcox
mwilcox at sitepen.com
http://www.sitepen.com
work: 650.968.8787 x218
cell: 214.697.4872

Search Discussions

  • Peter E Higgins at Oct 21, 2008 at 10:12 am
    I think that complicates the API some -- for the same convenience and
    simplistic reasons NodeList.connect doesn't return a handle (though
    thinking about it, maybe some form of meta-data-in-NodeList would be
    useful here? unrelated, sorry -- ) it seems having attr handle what
    .connect does directly is redundant and would confuse folks.

    dojo.connect(node, "onmouseover', function(e){ ... }) // if you want the
    handle
    dojo.attr(node, {
    onclick: function(e){ ... }, id:"foo" // if you don't care
    });

    Regards,
    Peter Higgins


    Mike Wilcox wrote:
    Continuing my blog on dojo.attr()....

    I've realized that if you use dojo.attr to connect an event, you're
    pretty much stuck with it and can't disconnect it.

    dojo.attr(node, "onmouseover")
    - in FF returns null
    - in IE returns the anonymous function from somewhere in dojo.connect.

    I think it would be preferable to return the handle to the connection.
    Or more accurately, an array of handles, in the case of more than one
    connection.


    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
  • Mike Wilcox at Oct 21, 2008 at 10:34 am
    Wouldn't this make attr a no-op for something that might need to be
    destroyed?

    I would venture to say that the number one reason for using a
    JavaScript library is to help the dev with memory leaks in closures.
    To then give them a loophole to still fall into that trap, I would say
    is not a good idea.

    IMHO, if it's too kludgey, we're money ahead to just remove the
    connect from attr.


    BTW, I'd also argue that NodeList.connect should return handles for
    the same reason. But i wouldn't advocate removing connect from that.

    Mike

    On Oct 21, 2008, at 9:12 AM, Peter E Higgins wrote:

    I think that complicates the API some -- for the same convenience and
    simplistic reasons NodeList.connect doesn't return a handle (though
    thinking about it, maybe some form of meta-data-in-NodeList would be
    useful here? unrelated, sorry -- ) it seems having attr handle what
    .connect does directly is redundant and would confuse folks.

    dojo.connect(node, "onmouseover', function(e){ ... }) // if you want
    the
    handle
    dojo.attr(node, {
    onclick: function(e){ ... }, id:"foo" // if you don't care
    });

    Regards,
    Peter Higgins


    Mike Wilcox wrote:
    Continuing my blog on dojo.attr()....

    I've realized that if you use dojo.attr to connect an event, you're
    pretty much stuck with it and can't disconnect it.

    dojo.attr(node, "onmouseover")
    - in FF returns null
    - in IE returns the anonymous function from somewhere in
    dojo.connect.

    I think it would be preferable to return the handle to the
    connection.
    Or more accurately, an array of handles, in the case of more than one
    connection.


    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872
  • Nathan Toone at Oct 21, 2008 at 10:59 am
    I would argue that dojo.attr is just a cross-browser way of setting
    attributes on a node. That is, similar to saying
    node.something=value. When setting events this way in
    html/javascript, there isn't a handle or anything returned (ie saying
    node.onclick=somefunc)

    Also - "connect"/"disconnect" are really pairs to each other - it
    doesn't really make much sense to have an "attr"/"disconnect" pair.
    If anything, I think that calling, for example dojo.attr("click",null)
    it would disconnect everything - the same as calling node.onclick=null
    would do.

    -Nathan
    On 10/21/08, Mike Wilcox wrote:
    Wouldn't this make attr a no-op for something that might need to be
    destroyed?

    I would venture to say that the number one reason for using a
    JavaScript library is to help the dev with memory leaks in closures.
    To then give them a loophole to still fall into that trap, I would say
    is not a good idea.

    IMHO, if it's too kludgey, we're money ahead to just remove the
    connect from attr.


    BTW, I'd also argue that NodeList.connect should return handles for
    the same reason. But i wouldn't advocate removing connect from that.

    Mike

    On Oct 21, 2008, at 9:12 AM, Peter E Higgins wrote:

    I think that complicates the API some -- for the same convenience and
    simplistic reasons NodeList.connect doesn't return a handle (though
    thinking about it, maybe some form of meta-data-in-NodeList would be
    useful here? unrelated, sorry -- ) it seems having attr handle what
    .connect does directly is redundant and would confuse folks.

    dojo.connect(node, "onmouseover', function(e){ ... }) // if you want
    the
    handle
    dojo.attr(node, {
    onclick: function(e){ ... }, id:"foo" // if you don't care
    });

    Regards,
    Peter Higgins


    Mike Wilcox wrote:
    Continuing my blog on dojo.attr()....

    I've realized that if you use dojo.attr to connect an event, you're
    pretty much stuck with it and can't disconnect it.

    dojo.attr(node, "onmouseover")
    - in FF returns null
    - in IE returns the anonymous function from somewhere in
    dojo.connect.

    I think it would be preferable to return the handle to the
    connection.
    Or more accurately, an array of handles, in the case of more than one
    connection.


    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
  • Mike Wilcox at Oct 21, 2008 at 12:21 pm

    On Oct 21, 2008, at 9:59 AM, Nathan Toone wrote:
    If anything, I think that calling, for example dojo.attr("click",null)
    it would disconnect everything - the same as calling node.onclick=null
    would do.
    I agree that this would be the thing to do. It would be a bit of a
    rewrite, as attr is currently sniffing for a function, not a null.

    This could work for all properties, and be a shortcut to removeAttr()
    - if the value===null && value!==undefined

    Mike

    -Nathan
    On 10/21/08, Mike Wilcox wrote:
    Wouldn't this make attr a no-op for something that might need to be
    destroyed?

    I would venture to say that the number one reason for using a
    JavaScript library is to help the dev with memory leaks in closures.
    To then give them a loophole to still fall into that trap, I would
    say
    is not a good idea.

    IMHO, if it's too kludgey, we're money ahead to just remove the
    connect from attr.


    BTW, I'd also argue that NodeList.connect should return handles for
    the same reason. But i wouldn't advocate removing connect from that.

    Mike

    On Oct 21, 2008, at 9:12 AM, Peter E Higgins wrote:

    I think that complicates the API some -- for the same convenience
    and
    simplistic reasons NodeList.connect doesn't return a handle (though
    thinking about it, maybe some form of meta-data-in-NodeList would be
    useful here? unrelated, sorry -- ) it seems having attr handle what
    .connect does directly is redundant and would confuse folks.

    dojo.connect(node, "onmouseover', function(e){ ... }) // if you want
    the
    handle
    dojo.attr(node, {
    onclick: function(e){ ... }, id:"foo" // if you don't care
    });

    Regards,
    Peter Higgins


    Mike Wilcox wrote:
    Continuing my blog on dojo.attr()....

    I've realized that if you use dojo.attr to connect an event, you're
    pretty much stuck with it and can't disconnect it.

    dojo.attr(node, "onmouseover")
    - in FF returns null
    - in IE returns the anonymous function from somewhere in
    dojo.connect.

    I think it would be preferable to return the handle to the
    connection.
    Or more accurately, an array of handles, in the case of more than
    one
    connection.


    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872
  • Adam L. Peller at Oct 21, 2008 at 1:09 pm
    dojo.attr keeps getting bigger... should it really be in base?
    On Tue, Oct 21, 2008 at 12:21 PM, Mike Wilcox wrote:

    On Oct 21, 2008, at 9:59 AM, Nathan Toone wrote:
    If anything, I think that calling, for example dojo.attr("click",null)
    it would disconnect everything - the same as calling node.onclick=null
    would do.
    I agree that this would be the thing to do. It would be a bit of a
    rewrite, as attr is currently sniffing for a function, not a null.

    This could work for all properties, and be a shortcut to removeAttr()
    - if the value===null && value!==undefined

    Mike

    -Nathan
    On 10/21/08, Mike Wilcox wrote:
    Wouldn't this make attr a no-op for something that might need to be
    destroyed?

    I would venture to say that the number one reason for using a
    JavaScript library is to help the dev with memory leaks in closures.
    To then give them a loophole to still fall into that trap, I would
    say
    is not a good idea.

    IMHO, if it's too kludgey, we're money ahead to just remove the
    connect from attr.


    BTW, I'd also argue that NodeList.connect should return handles for
    the same reason. But i wouldn't advocate removing connect from that.

    Mike

    On Oct 21, 2008, at 9:12 AM, Peter E Higgins wrote:

    I think that complicates the API some -- for the same convenience
    and
    simplistic reasons NodeList.connect doesn't return a handle (though
    thinking about it, maybe some form of meta-data-in-NodeList would be
    useful here? unrelated, sorry -- ) it seems having attr handle what
    .connect does directly is redundant and would confuse folks.

    dojo.connect(node, "onmouseover', function(e){ ... }) // if you want
    the
    handle
    dojo.attr(node, {
    onclick: function(e){ ... }, id:"foo" // if you don't care
    });

    Regards,
    Peter Higgins


    Mike Wilcox wrote:
    Continuing my blog on dojo.attr()....

    I've realized that if you use dojo.attr to connect an event, you're
    pretty much stuck with it and can't disconnect it.

    dojo.attr(node, "onmouseover")
    - in FF returns null
    - in IE returns the anonymous function from somewhere in
    dojo.connect.

    I think it would be preferable to return the handle to the
    connection.
    Or more accurately, an array of handles, in the case of more than
    one
    connection.


    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    Mike Wilcox
    mwilcox at sitepen.com
    http://www.sitepen.com
    work: 650.968.8787 x218
    cell: 214.697.4872

    _______________________________________________
    dojo-contributors mailing list
    dojo-contributors at dojotoolkit.org
    http://turtle.dojotoolkit.org/mailman/listinfo/dojo-contributors
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20081021/a1daf09c/attachment.htm
  • Bill Keese at Nov 4, 2008 at 7:28 pm

    Nathan Toone wrote:
    If anything, I think that calling, for example dojo.attr("click",null)
    it would disconnect everything - the same as calling node.onclick=null
    would do.
    Note that dojo.attr() already has code to disconnect the old handler
    when defining a new one. dojo.attr() calls dojo.connect(), and saves
    the returned handle in _evtHdlrMap.

    So I think rearranging that code a bit would make
    dojo.attr("click",null) work as you suggested.

    However, the correct way to remove an attribute is dojo.removeAttr(),
    not dojo.attr(node, "click", null), so dojo.removeAttr() should work [too].

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdojo-contributors @
categoriesdojo
postedOct 21, '08 at 10:11a
activeNov 4, '08 at 7:28p
posts7
users5
websitedojotoolkit.org

People

Translate

site design / logo © 2022 Grokbase