Opened 13 years ago

Last modified 9 years ago

#4122 closed enhancement

dijit.WidgetSet: support array interface — at Version 6

Reported by: alex Owned by: alex
Priority: high Milestone: 2.0
Component: Dijit Version: 0.9
Keywords: 4alex Cc: alex
Blocked By: Blocking:

Description (last modified by bill)

The methods on dijit.WidgetSet (and by association, dijit.registry) appear to surface array-like semantics (forEach, filter, etc.), however these methods do not take a scope parameter and do not return an array-like object. Given that many other bread-and-butter Dojo interfaces respect array-like semantics (sometimes going to great length to do so), these methods should probably be re-designed and a toArray() method (or better, basic array behavior on the base class itself) should be added to the class.

Change History (6)

comment:1 Changed 13 years ago by bill

Owner: changed from bill to alex

For efficiency reasons WidgetSet? holds a hash rather than an array, since the widgets are typically accessed by id.

toArray() method was left out on purpose, to prevent users from doing something inefficient like dojo.filter(widgetSet.toArray(), ...) rather than widgetSet.filter(..).

I guess the return value from byClass() or filter() could be an array, although I want to do things like

dijit.byClass("Button").forEach(...)

which means that we need to return a souped-up array like NodeList? does, not a plain []. There should probably be support for that in dojo.

Talked to Alex about this. He said he'll make a backwards-compatible patch to support stuff like this and then (if it looks OK) I'll add to 1.0.

comment:2 Changed 13 years ago by bill

PS: oh Alex said that he wants a toArray() function for debugging output. I don't mind adding it for that reason but let's name it _dumpToArray() to make it clear that people shouldn't be using it in general.

comment:3 Changed 13 years ago by bill

Keywords: 4alex added

comment:4 Changed 12 years ago by bill

Milestone: 1.12.0

Too late to make an API change (or even addition) for Dijit 1.1... bumping.

comment:5 Changed 12 years ago by david

Bumping this up for discussion again...

There doesn't seem to be a good way to get a set of widgets on the page. It seems to me that a toArray method is necessary. Sure, you don't want to use it for general purpose things, but it sure makes life easier. It also doesn't make sense to me to partially implement things like forEach if you aren't giving people an easy way to get at the data.

While I'm at it, a dijit equivelent to dojo.query would be mighty nice. Quick, how do I get all the dijit.form.* dijits under a given dijit.form.Form? (Current answer: {{{dojo.filter(myFormDijit.getDescendants(), "return item.declaredClass.indexOf('dijit.form.')==0")}}}) Maybe I should make this a new feature request?

comment:6 Changed 12 years ago by bill

Description: modified (diff)
Summary: dijit.WidgetSet methods broken or mis-designeddijit.WidgetSet: support array interface
Type: defectenhancement

I'm not sure what this means:

It also doesn't make sense to me to partially implement things like forEach if you aren't giving people an easy way to get at the data.

If you are talking about forEach() not taking a scope variable, that could definitely be added. If you are saying that you just want an array of output, not sure how that's related to forEach().

Regarding dojo.query() for dijits, I have heard discussion about that although, yes, it shouldn't be part of this ticket. Should make a new ticket... although probably the idea is too vague right now to even make a ticket....

Need to think about syntax etc. Would it be something like dijit.query(".foo dijit.form.Button") to find all button widgets with an ancestor DOM node with class=foo ? That syntax is no good b/c it's ambiguous. Anyway, think about what kind of API you would like. Think about whether it needs to work on DOM nodes or just widgets, and whether it needs to do things like querying on widget attributes (ex: find all Button widgets with name=foo, or BorderContainer widgets with design=headline)

Note: See TracTickets for help on using tickets.