/ Published in: JavaScript
Expand |
Embed | Plain Text
/** * @class App.Quick * Special Class (Singleton) * This small singleton works like a kind of application telephone book. * A quick register to find critical and often used objects in the application. * This object is in NO WAY generic and always application DEPENDENT !!! * * What makes this small class useful is that it dynamically generates the functions for how the * values can be retrieved * * f.e. * * App.Quick.set('abba', this); * * Means that in the register entry abba the reference is set to "this", but in such a way that it * will be set by reference, not by value!. * * You can retrieve this value simply by using: * App.Quick.abba(); * * App.Quick.check('abba'); * looks for the existance of a function called 'abba', used for validating if object functions already * exist, before calling them. * * You can also create the entries directly (hard coded) in this class (sometimes good for overview) * * @namespace App * * @singleton * @author J.J. van de Merwe, Enovision GmbH * @version 1.0 */ Ext.ns('App'); App.Quick = function(){ return { settings : {}, /** * function that checks if an entry already been created for this class (dynamically that is) * @params {string} set, which contains the label of the set item to be checked * * @return {boolean} exists?, true if exists, false if not exists */ check : function(set) { return ((App.Quick[set] && typeof(App.Quick[set]) === 'function') === true) ? true : false; }, /** * function that adds new entries to the App.Quick set in realtime * @params {string} set, which contains the label of the set item to be added * @params {mixed objec} Value, the reference value to be connected with the set * @params (boolean) forced, when set to true, it will override any existing one with the same label, * this is also the default value (false, will not override) * * @return {boolean} execution state (true is oké, false is no good) */ set : function(set, Value, forced) { if (typeof(set) === 'undefined' || typeof(Value) === 'undefined') { return false; } var is_forced = (typeof(forced) === 'undefined') ? true : forced; if (typeof(App.Quick[set]) !== 'undefined' && is_forced === false) return false; if (typeof(set) !== 'string') return false; App.Quick.settings[set] = Value; App.Quick[set] = function() { return App.Quick.settings[set]; } return true; }, /** * hardcoded sample (please this sample assumes that App.Quick.StructureManager has * been set somewhere in the software) * THIS IS NOT VERY PRACTICAL, BUT FOR THE DEMO ITS OKÉ */ TreeNodeSelectedSemester : function() { return App.Quick.StructureManager()._selectedSemester; } } }();
Comments
Subscribe to comments
You need to login to post a comment.

This mini class I made because I was a bit tired in the complexity of findings objects and their attributes back quickly. The principle is to have a singleton class that holds all the major object references to be found. A major requirement was, to also address them easy. Please pay attention to the this. The class creates a small cleaverness to have the values by reference and not by value. This would not be so good, if this is not the this you expect to get back. Have fun with it. It works very good.
Don't use this snippet anymore. There are easier and more structural ways to do the same thing.