Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12122 closed defect (fixed)

dijit._Widget getSetterAttributes fails with "anonymous" classes

Reported by: ben hockey Owned by: bill
Priority: high Milestone: 1.6
Component: Dijit Version: 1.5
Keywords: Cc: Eugene Lazutkin
Blocked By: Blocking:

Description

if i "anonymously" declare 2 widgets like this:

var Widget1 = dojo.declare([dijit._Widget, dijit._Templated], {}),
    Widget2 = dojo.declare([dijit._Widget, dijit._Templated], {
        _setFooAttr: function (value) {
            this.foo = value;
        }
    });

you will be able to see that Widget1 and Widget2 prototypes both have a declaredClass of 'dijit._Templated'. this causes a problem when getSetterAttributes caches the setter attributes for a class based on it's declaredClass. Widget1 and Widget2 have the same declaredClass but have different setters. this causes instances of Widget2 not to have the setters called when doing something like this widget2Instance = new Widget2 ({foo: 'bar'});

Change History (5)

comment:1 Changed 9 years ago by ben hockey

Component: GeneralDijit
Owner: anonymous deleted

comment:2 Changed 9 years ago by bill

Cc: Eugene Lazutkin added

Not sure what the best solution to this is. We could just get rid of that caching altogether, as I don't know if it has a significant effect on performance or not.

Or could modify dojo.declare() to attach a unique ID to each class, maybe in _meta.id. Eugene, what do you think?

comment:3 Changed 9 years ago by bill

Milestone: tbd1.6
Owner: set to bill
Status: newassigned

I benchmarked removing the caching... on IE6 in benchTool.html, for the "create" test, it increased the run time from 375ms to 468ms. So the caching seems worthwhile.

But it looks like I can cache inside the constructor, setting this.constructor._setterAttrs, so I guess I don't need a unique per-class ID at all.

comment:4 Changed 9 years ago by bill

Resolution: fixed
Status: assignedclosed

(In [23468]) Don't rely on declaredClass as a key for caching since it's not unique for anonymous classes, fixes #12122 !strict.

comment:5 Changed 9 years ago by bill

(In [23476]) Test case that setters are called even for anonymous classes, even when multiple anonymous classes have the same declaredClass. Refs #12122.

Note: See TracTickets for help on using tickets.