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

Nathan Toone toonetown at dojotoolkit.org
Tue Oct 21 10:59:43 EDT 2008


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 <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
>



More information about the dojo-contributors mailing list