[dojo-contributors] dojo.attr() - no disconnect

Mike Wilcox mwilcox at sitepen.com
Tue Oct 21 12:21:53 EDT 2008


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 <mwilcox at sitepen.com> 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




More information about the dojo-contributors mailing list