Ticket #7650 (closed defect: fixed)

Opened 10 months ago

Last modified 8 months ago

Declaration: can't really create/override methods

Reported by: bill Owned by: bill
Priority: normal Milestone: 1.3
Component: Dijit Version: 1.2beta
Severity: normal Keywords:
Cc:

Description

The Declaration code lets you declare a class with methods:

<table dojoType="dijit.Declaration" widgetClass="demo.Table" ...>
	<script type="dojo/method" event="onSort" args="index">
		...
	</script>
</div>

Unfortunately methods declared this way are implemented as connections, rather than as real methods in the declared class' prototype. This leads to many issues including:

  • can't return a value
  • can't override an existing method
  • i suspect this.inherited() doesn't work

It also breaks the deferredConnect code in Widget.js that checks whether an event handler method has been redefined from a sentinel value:

for(attr in this._deferredConnects){
	if(this[attr] !== dijit._connectOnUseEventHandler){
		delete this._deferredConnects[attr];	// redefined, probably dojoAttachEvent exists
	}
}

... last issue is leading to JS errors in mail demo when clicking an item in the inbox, since an unwanted connection is getting setup from this.domNode.onclick --> this.onClick.

Change History

Changed 10 months ago by bill

  • status changed from new to closed
  • resolution set to fixed

(In [15238]) Refactor Declaration code so that methods become real methods. Also do dojo/connects on prototype methods rather than using fake mixin trick.

Also updated demo.Table example to declare onClick method so that code in Widget looking for override to onClick works.

Fixes #7650 !strict

Changed 9 months ago by Maine

  • status changed from closed to reopened
  • resolution deleted

Changeset [15238] breaks preamble - see my test case on Dijit.Declaration

Changed 9 months ago by bill

  • milestone changed from 1.2 to 1.2.1

Ah, yeah I see your point; looks like the current code in Declaration.js just ignores a <script type="dojo/method" ...> declaration of preamble (when it should be overriding the definition in the base class).

Probably can just remove the line

preambles = dojo.query("> script[type='dojo/method'][event='preamble']", src).orphan(),

from Declaration.js as it doesn't seem necessary to special case preamble.

Changed 8 months ago by peller

  • milestone changed from 1.2.1 to 1.2.2

Changed 8 months ago by bill

  • status changed from reopened to closed
  • resolution set to fixed
  • milestone changed from 1.2.2 to 1.3

Maine - thanks for the test case.

Fixed in [15603].

Note: See TracTickets for help on using tickets.