]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/Destroyable.js.uncompressed.js
1 define("dijit/Destroyable", [
2 "dojo/_base/array", // array.forEach array.map
5 ], function(array
, aspect
, declare
){
10 return declare("dijit.Destroyable", null, {
12 // Mixin to track handles and release them when instance is destroyed.
14 // Call this.own(...) on list of handles (returned from dojo/aspect, dojo/on,
15 // dojo/Stateful::watch, or any class (including widgets) with a destroyRecursive() or destroy() method.
16 // Then call destroy() later to destroy this instance and release the resources.
18 destroy: function(/*Boolean*/ preserveDom
){
20 // Destroy this class, releasing any resources registered via own().
21 this._destroyed
= true;
26 // Track specified handles and remove/destroy them when this instance is destroyed, unless they were
27 // already removed/destroyed manually.
31 // The array of specified handles, so you can do for example:
32 // | var handle = this.own(on(...))[0];
34 array
.forEach(arguments
, function(handle
){
35 var destroyMethodName
=
36 "destroyRecursive" in handle
? "destroyRecursive" : // remove "destroyRecursive" for 2.0
37 "destroy" in handle
? "destroy" :
40 // When this.destroy() is called, destroy handle. Since I'm using aspect.before(),
41 // the handle will be destroyed before a subclass's destroy() method starts running, before it calls
42 // this.inherited() or even if it doesn't call this.inherited() at all. If that's an issue, make an
43 // onDestroy() method and connect to that instead.
44 var odh
= aspect
.before(this, "destroy", function(preserveDom
){
45 handle
[destroyMethodName
](preserveDom
);
48 // If handle is destroyed manually before this.destroy() is called, remove the listener set directly above.
49 var hdh
= aspect
.after(handle
, destroyMethodName
, function(){
55 return arguments
; // handle