The Dojo Toolkit, for which this module is intended, features a versatile topic-based event publishing and subscription framework, that allows widgets throughout the application to receive notifications of various events and associated data.
However, as of version 1.5.0, the Dojo Toolkit lacks a utility to also allow retrieval of previously published event data, preventing the event system from being used to store data for the application model.
Such a capability is useful for UI components that are created by their parent components upon notification of (and obviously after) a particular event, but that still periodically require the latest data on that or other event topic(s) throughout their lifecycle.
This is a storage layer add-on module for the Dojo Toolkit event system. It can be ‘require’d via the Dojo module-loading package system, and be used for the retrieval of previously-published topic-based event data, making it possible for application components to access event data that either could not be received, or was not needed, at the time it was originally published.
Enter an arbitrary event name and some text data below, and click the ‘Store’ button:
Enter the same event name below as entered above, and click the ‘Recall’ button to load and display the text data just entered:
Include the path to the ‘stordje’ module in the ‘djConfig’ ‘modulePaths’ parameter by specifying the HTTP/S path to the StorDJE JavaScript file without the ‘.js’ extension:
<script type='text/javascript' src='/dojo-release-1.5.0/dojo/dojo.js' djConfig="parseOnLoad: true, modulePaths:{'stordje':'/stordje/stordje-release-0.3-min'}"> </script>
Instead of calling the ‘publish(…)’ method of the ‘dojo’ module like this:
dojo.publish('my-event', ["my event data"]);
Change the module from ‘dojo’ to ‘stordje’ like this:
dojo.require('stordje'); stordje.publish('my-event', ["my event data"]);
The method arguments remain exactly the same. The method ‘stordje.publish(…)’ still calls ‘dojo.publish(…)’ internally after saving the event data to a hash map.
To recall the event data, call either the ‘recall(…)’ or ‘recallFirst(…)’ method of the stordje module:
dojo.require('stordje'); var arrData = stordje.recall('my-event'); // Returns the stored string // wrapped inside an array. var strData = stordje.recallFirst('my-event'); // Returns just the stored // string.
These methods simply retrieve the event data from the same hash map to which it was previously saved by ‘stordje.publish(…)’. The ‘recallFirst(…)’ method was added for convenience to unwrap the data from the array in which it was originally published.
Review the Dojo Build System documentation.
Dojo version 1.5.0 and below SDK build script has a limitation on including single-file modules in the build. To include StorDJE in the build, it is necessary to overcome this limitation.
Either override ‘dojo-release-X-src/util/buildscripts/build.js’ with this build.js .
Or apply this build.js.patch patch file to ‘dojo-release-X-src/util/buildscripts/build.js’.
--- dojo-release-1.5.0-src/util/buildscripts/build.js-ORIGINAL 2010-04-28 17:01:11.000000000 -0700 +++ dojo-release-1.5.0-src/util/buildscripts/build.js 2011-01-22 23:12:19.815136749 -0800 @@ -262,6 +262,12 @@ //directory. Also adds code guards to module resources. var prefixSlashName = prefixName.replace(/\./g, "/"); var releasePath = kwArgs.releaseDir + "/" + prefixSlashName; + + var isModuleSingleFile = prefixPath.match(/\.js$/); + if (isModuleSingleFile) { + releasePath += '.js'; + } + var copyRegExps = { include: /./ }; @@ -276,7 +282,15 @@ } logger.info("Copying: " + prefixPath + " to: " + releasePath); - var copiedFiles = fileUtil.copyDir(prefixPath, releasePath, copyRegExps, true); + + var copiedFiles = null; + if (isModuleSingleFile) { + if (fileUtil.copyFile(prefixPath, releasePath, true)) { + copiedFiles = [releasePath]; + } + } else { + copiedFiles = fileUtil.copyDir(prefixPath, releasePath, copyRegExps, true); + } //If want a different selector engine, adjust that now. //Copy the new selector js over the dojo._base.query file
Example:
$ patch dojo-release-1.5.0-src/util/buildscripts/build.js-ORIGINAL build.js.patch
Make sure to specify a prefix for StorDJE in your ‘build-X.profile.js’:
prefixes: [ [ 'dijit', '../dijit' ], [ 'dojox', '../dojox' ], [ 'stordje', '../stordje/stordje-release-0.3-min.js' ], [ 'your_other_module', '../your_other_module' ] ]
Copyright (c) 2010-2018 Marat Nepomnyashy
Except where otherwise noted, this webpage is licensed under a Creative Commons Attribution 3.0 Unported License.
Background wallpaper by Patrick Hoesly, used under Creative Commons Attribution 2.0 Generic License.