diff options
author | Andrew Dolgov <[email protected]> | 2013-03-18 10:26:24 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2013-03-18 10:26:26 +0400 |
commit | f0cfe83e3725f9a3928da97a6e3085e79cb25309 (patch) | |
tree | 4b0af188defaa807c7bc6ff3a101b41c9166c463 /lib/dijit/Destroyable.js.uncompressed.js | |
parent | 9a2885da170ffd64358b99194095851a2d09c1b6 (diff) |
upgrade dojo to 1.8.3 (refs #570)
Diffstat (limited to 'lib/dijit/Destroyable.js.uncompressed.js')
-rw-r--r-- | lib/dijit/Destroyable.js.uncompressed.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/dijit/Destroyable.js.uncompressed.js b/lib/dijit/Destroyable.js.uncompressed.js new file mode 100644 index 000000000..ee6b8893e --- /dev/null +++ b/lib/dijit/Destroyable.js.uncompressed.js @@ -0,0 +1,59 @@ +define("dijit/Destroyable", [ + "dojo/_base/array", // array.forEach array.map + "dojo/aspect", + "dojo/_base/declare" +], function(array, aspect, declare){ + +// module: +// dijit/Destroyable + +return declare("dijit.Destroyable", null, { + // summary: + // Mixin to track handles and release them when instance is destroyed. + // description: + // Call this.own(...) on list of handles (returned from dojo/aspect, dojo/on, + // dojo/Stateful::watch, or any class (including widgets) with a destroyRecursive() or destroy() method. + // Then call destroy() later to destroy this instance and release the resources. + + destroy: function(/*Boolean*/ preserveDom){ + // summary: + // Destroy this class, releasing any resources registered via own(). + this._destroyed = true; + }, + + own: function(){ + // summary: + // Track specified handles and remove/destroy them when this instance is destroyed, unless they were + // already removed/destroyed manually. + // tags: + // protected + // returns: + // The array of specified handles, so you can do for example: + // | var handle = this.own(on(...))[0]; + + array.forEach(arguments, function(handle){ + var destroyMethodName = + "destroyRecursive" in handle ? "destroyRecursive" : // remove "destroyRecursive" for 2.0 + "destroy" in handle ? "destroy" : + "remove"; + + // When this.destroy() is called, destroy handle. Since I'm using aspect.before(), + // the handle will be destroyed before a subclass's destroy() method starts running, before it calls + // this.inherited() or even if it doesn't call this.inherited() at all. If that's an issue, make an + // onDestroy() method and connect to that instead. + var odh = aspect.before(this, "destroy", function(preserveDom){ + handle[destroyMethodName](preserveDom); + }); + + // If handle is destroyed manually before this.destroy() is called, remove the listener set directly above. + var hdh = aspect.after(handle, destroyMethodName, function(){ + odh.remove(); + hdh.remove(); + }, true); + }, this); + + return arguments; // handle + } +}); + +}); |