Author: gotcha
Date: Tue Dec 25 15:36:04 2007
New Revision: 50093
Modified:
kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
kukit/kukit.js/branch/finish-closures/kukit/eventreg.js
Log:
unindent and initialize
Modified: kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/TODO.txt (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/TODO.txt Tue Dec 25
15:36:04 2007
@@ -1,5 +1,4 @@
files where indentation has to be undone and initialize needs to be done
-eventreg.js
kssparser.js
tokenizer.js
Modified: kukit/kukit.js/branch/finish-closures/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/eventreg.js (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/eventreg.js Tue Dec 25
15:36:04 2007
@@ -40,202 +40,205 @@
* implements the binder.
*
*/
-var _EventRegistry = function () {
+var _EventRegistry = function() {
+
+this.initialize = function() {
this.content = {};
this.classes = {};
this.eventSets = [];
+};
/* binder registration */
- this.registerBinder = function(className, klass) {
- if (typeof(klass) == 'undefined') {
-;;; kukit.E = 'klass argument is mandatory when registering an event';
-;;; kukit.E += ' binder (_EventRegistry.registerBinder).';
- throw new Error(kukit.E);
- }
- if (this.classes[className]) {
- // Do not allow redefinition
-;;; var msg = 'Error : event class [' + className + '] already
registered.';
-;;; kukit.logError(msg);
- return;
-
- }
- klass.prototype = new _EventBinder();
- klass.prototype.__className__ = className;
- var newKlass = function() {};
- newKlass.prototype = new klass();
- this.classes[className] = newKlass;
- };
-
- this.existsBinder = function(className) {
- var klass = this.classes[className];
- return (typeof(klass) != 'undefined');
- };
-
- this.getBinderClass = function(className) {
- var klass = this.classes[className];
- if (! klass) {
- // not found
-;;; kukit.E = 'Error : undefined event setup type [' + className +
'].';
- throw new Error(kukit.E);
- }
- return klass;
- };
-
- /* events (methods) registration helpers (not to be called directly) */
-
- this._register = function(namespace, eventName, klass,
- bindMethodName, defaultActionMethodName, iterName) {
- if (typeof(defaultActionMethodName) == 'undefined') {
-;;; kukit.E = 'Missing arguments when calling
[_EventRegistry.register].';
- throw new Error(kukit.E);
- }
- // Find out the class name. (Not specified now.)
- var className = klass.prototype.__className__;
- if (typeof(className) == 'undefined') {
- // Create a className, and register it too.
- className = '' + _eventClassCounter;
- _eventClassCounter += 1;
- this.registerBinder(className, klass);
- }
- var binderKlass = this.getBinderClass(className);
- if (!eventName) {
-;;; kukit.E = '[eventName] argument cannot be empty when registering';
-;;; kukit.E += ' an event with [_EventRegistry.register].';
- throw new Error(kukit.E);
- }
- var key = this._getKey(namespace, eventName);
- var entry = this.content[key];
- if (typeof(entry) != 'undefined') {
- if (key[0] == '-') {
- key = key.substring(1);
- }
-;;; kukit.E = 'Attempt to register key [' + key;
-;;; kukit.E += '] twice when registering';
-;;; kukit.E += ' an event with [_EventRegistry.register].';
- throw new Error(kukit.E);
- }
- // check bindMethodName and defaultActionMethodName
- if (bindMethodName && ! binderKlass.prototype[bindMethodName]) {
-;;; kukit.E = 'In _EventRegistry.register bind method [' +
bindMethodName;
-;;; kukit.E += '] is undefined for event [' + eventName;
-;;; kukit.E += '] namespace [' + namespace + '].';
- throw new Error(kukit.E);
- }
- if (defaultActionMethodName && !
binderKlass.prototype[defaultActionMethodName]) {
-;;; kukit.E = 'In _EventRegistry.register default action method [';
-;;; kukit.E += defaultActionMethodName + '] is undefined for event [';
-;;; kukit.E += eventName + '] namespace [' + namespace + '].';
- throw new Error(kukit.E);
- }
- // check the iterator.
- if (! er.getBindIterator(iterName)) {
-;;; kukit.E = 'In _EventRegistry.register unknown bind iterator [';
-;;; kukit.E += iterName + '].';
- throw new Error(kukit.E);
- }
- // register it
- this.content[key] = {
- 'className': className,
- 'bindMethodName': bindMethodName,
- 'defaultActionMethodName': defaultActionMethodName,
- 'iterName': iterName
- };
- };
-
- /* events (methods) binding [ForAll] registration */
-
- this._registerEventSet =
- function(namespace, names, iterName, bindMethodName) {
- // At this name the values should be checked already. so this should
- // be called _after_ _register.
- this.eventSets.push({
- 'namespace': namespace,
- 'names': names,
- 'iterName': iterName,
- 'bindMethodName': bindMethodName
- });
- };
-
- /* there are the actual registration methods, to be called from plugins */
-
- this.register =
- function(namespace, eventName, klass, bindMethodName,
- defaultActionMethodName) {
- this._register(namespace, eventName, klass, bindMethodName,
- defaultActionMethodName, 'EachLegacy');
- this._registerEventSet(namespace, [eventName], 'EachLegacy',
- bindMethodName);
- };
-
- this.unregister =
- function(namespace, eventName) {
- var key = this._getKey(namespace, eventName);
- delete this.content[key];
- var found = null;
- for (var i=0; i < this.eventSets.length; i++) {
- var eventSet = this.eventSets[i];
- if (eventSet['namespace'] == namespace) {
- found = i;
- break;
- }
- }
- if (found != null) {
- this.eventSets.splice(found, 1);
+this.registerBinder = function(className, klass) {
+ if (typeof(klass) == 'undefined') {
+;;; kukit.E = 'klass argument is mandatory when registering an event';
+;;; kukit.E += ' binder (_EventRegistry.registerBinder).';
+ throw new Error(kukit.E);
+ }
+ if (this.classes[className]) {
+ // Do not allow redefinition
+;;; var msg = 'Error : event class [' + className + '] already
registered.';
+;;; kukit.logError(msg);
+ return;
+
+ }
+ klass.prototype = new _EventBinder();
+ klass.prototype.__className__ = className;
+ var newKlass = function() {};
+ newKlass.prototype = new klass();
+ this.classes[className] = newKlass;
+};
+
+this.existsBinder = function(className) {
+ var klass = this.classes[className];
+ return (typeof(klass) != 'undefined');
+};
+
+this.getBinderClass = function(className) {
+ var klass = this.classes[className];
+ if (! klass) {
+ // not found
+;;; kukit.E = 'Error : undefined event setup type [' + className + '].';
+ throw new Error(kukit.E);
}
- };
+ return klass;
+};
- this.registerForAllEvents =
- function(namespace, eventNames, klass,
- bindMethodName, defaultActionMethodName, iterName) {
- if (typeof(eventNames) == 'string') {
- eventNames = [eventNames];
- }
- for (var i=0; i<eventNames.length; i++) {
- var eventName = eventNames[i];
- this._register(namespace, eventName, klass, bindMethodName,
- defaultActionMethodName, iterName);
- }
- this._registerEventSet(namespace, eventNames, iterName,
bindMethodName);
- };
+/* events (methods) registration helpers (not to be called directly) */
- this._getKey = function(namespace, eventName) {
- if (namespace == null) {
- namespace = '';
- } else if (namespace.split('-') > 1) {
-;;; kukit.E = 'In [_EventRegistry.register], [namespace] cannot have';
-;;; kukit.E += 'dashes.';
- throw new Error(kukit.E);
+this._register = function(namespace, eventName, klass,
+ bindMethodName, defaultActionMethodName, iterName) {
+ if (typeof(defaultActionMethodName) == 'undefined') {
+;;; kukit.E = 'Missing arguments when calling [_EventRegistry.register].';
+ throw new Error(kukit.E);
+ }
+ // Find out the class name. (Not specified now.)
+ var className = klass.prototype.__className__;
+ if (typeof(className) == 'undefined') {
+ // Create a className, and register it too.
+ className = '' + _eventClassCounter;
+ _eventClassCounter += 1;
+ this.registerBinder(className, klass);
+ }
+ var binderKlass = this.getBinderClass(className);
+ if (!eventName) {
+;;; kukit.E = '[eventName] argument cannot be empty when registering';
+;;; kukit.E += ' an event with [_EventRegistry.register].';
+ throw new Error(kukit.E);
+ }
+ var key = this._getKey(namespace, eventName);
+ var entry = this.content[key];
+ if (typeof(entry) != 'undefined') {
+ if (key[0] == '-') {
+ key = key.substring(1);
+ }
+;;; kukit.E = 'Attempt to register key [' + key;
+;;; kukit.E += '] twice when registering';
+;;; kukit.E += ' an event with [_EventRegistry.register].';
+ throw new Error(kukit.E);
+ }
+ // check bindMethodName and defaultActionMethodName
+ if (bindMethodName && ! binderKlass.prototype[bindMethodName]) {
+;;; kukit.E = 'In _EventRegistry.register bind method [' + bindMethodName;
+;;; kukit.E += '] is undefined for event [' + eventName;
+;;; kukit.E += '] namespace [' + namespace + '].';
+ throw new Error(kukit.E);
+ }
+ if (defaultActionMethodName && !
binderKlass.prototype[defaultActionMethodName]) {
+;;; kukit.E = 'In _EventRegistry.register default action method [';
+;;; kukit.E += defaultActionMethodName + '] is undefined for event [';
+;;; kukit.E += eventName + '] namespace [' + namespace + '].';
+ throw new Error(kukit.E);
+ }
+ // check the iterator.
+ if (! er.getBindIterator(iterName)) {
+;;; kukit.E = 'In _EventRegistry.register unknown bind iterator [';
+;;; kukit.E += iterName + '].';
+ throw new Error(kukit.E);
+ }
+ // register it
+ this.content[key] = {
+ 'className': className,
+ 'bindMethodName': bindMethodName,
+ 'defaultActionMethodName': defaultActionMethodName,
+ 'iterName': iterName
+ };
+};
+
+/* events (methods) binding [ForAll] registration */
+
+this._registerEventSet =
+ function(namespace, names, iterName, bindMethodName) {
+ // At this name the values should be checked already. so this should
+ // be called _after_ _register.
+ this.eventSets.push({
+ 'namespace': namespace,
+ 'names': names,
+ 'iterName': iterName,
+ 'bindMethodName': bindMethodName
+ });
+};
+
+/* there are the actual registration methods, to be called from plugins */
+
+this.register =
+ function(namespace, eventName, klass, bindMethodName,
+ defaultActionMethodName) {
+ this._register(namespace, eventName, klass, bindMethodName,
+ defaultActionMethodName, 'EachLegacy');
+ this._registerEventSet(namespace, [eventName], 'EachLegacy',
+ bindMethodName);
+};
+
+this.unregister =
+ function(namespace, eventName) {
+ var key = this._getKey(namespace, eventName);
+ delete this.content[key];
+ var found = null;
+ for (var i=0; i < this.eventSets.length; i++) {
+ var eventSet = this.eventSets[i];
+ if (eventSet['namespace'] == namespace) {
+ found = i;
+ break;
}
- return namespace + '-' + eventName;
- };
+ }
+ if (found != null) {
+ this.eventSets.splice(found, 1);
+ }
+};
- this.exists = function(namespace, eventName) {
- var key = this._getKey(namespace, eventName);
- var entry = this.content[key];
- return (typeof(entry) != 'undefined');
- };
+this.registerForAllEvents =
+ function(namespace, eventNames, klass,
+ bindMethodName, defaultActionMethodName, iterName) {
+ if (typeof(eventNames) == 'string') {
+ eventNames = [eventNames];
+ }
+ for (var i=0; i<eventNames.length; i++) {
+ var eventName = eventNames[i];
+ this._register(namespace, eventName, klass, bindMethodName,
+ defaultActionMethodName, iterName);
+ }
+ this._registerEventSet(namespace, eventNames, iterName, bindMethodName);
+};
- this.get = function(namespace, eventName) {
- var key = this._getKey(namespace, eventName);
- var entry = this.content[key];
- if (typeof(entry) == 'undefined') {
-;;; if (key.substr(0, 1) == '-') {
-;;; key = key.substring(1);
-;;; kukit.E = 'Error : undefined global event [';
-;;; kukit.E += key + '] (or maybe namespace is missing ?).';
-;;; } else {
-;;; kukit.E = 'Error : undefined namespace or event in [' + key +
'].';
-;;; }
- throw new Error(kukit.E);
- }
- return entry;
- };
+this._getKey = function(namespace, eventName) {
+ if (namespace == null) {
+ namespace = '';
+ } else if (namespace.split('-') > 1) {
+;;; kukit.E = 'In [_EventRegistry.register], [namespace] cannot have';
+;;; kukit.E += 'dashes.';
+ throw new Error(kukit.E);
+ }
+ return namespace + '-' + eventName;
+};
- this.getBinderClassByEventNamespace = function(namespace, eventName) {
- return this.getBinderClass(this.get(namespace, eventName).className);
- };
+this.exists = function(namespace, eventName) {
+ var key = this._getKey(namespace, eventName);
+ var entry = this.content[key];
+ return (typeof(entry) != 'undefined');
+};
+
+this.get = function(namespace, eventName) {
+ var key = this._getKey(namespace, eventName);
+ var entry = this.content[key];
+ if (typeof(entry) == 'undefined') {
+;;; if (key.substr(0, 1) == '-') {
+;;; key = key.substring(1);
+;;; kukit.E = 'Error : undefined global event [';
+;;; kukit.E += key + '] (or maybe namespace is missing ?).';
+;;; } else {
+;;; kukit.E = 'Error : undefined namespace or event in [' + key + '].';
+;;; }
+ throw new Error(kukit.E);
+ }
+ return entry;
+};
+this.getBinderClassByEventNamespace = function(namespace, eventName) {
+ return this.getBinderClass(this.get(namespace, eventName).className);
+};
+this.initialize.apply(this, arguments);
};
@@ -262,51 +265,49 @@
* postpone binding of actions until called first time
*
*/
-var _LateBinder = function(binder, name, node) {
+var _LateBinder = function() {
+
+this.initialize = function(binder, name, node) {
this.binder = binder;
this.name = name;
this.node = node;
this.boundEvent = null;
+};
- this.executeActions = function() {
- if (! this.boundEvent) {
-;;; var msg = 'Attempt of late binding for event [' + this.name;
-;;; msg += '], node [' + this.node.nodeName + '].';
-;;; kukit.log(msg);
- if (kukit.hasFirebug) {
- kukit.log(this.node);
- }
- var info = kukit.engine.binderInfoRegistry.getBinderInfoById(
- this.binder.__binderId__);
- var oper = info.bound.getBoundOperForNode(this.name, this.node);
- if (oper) {
- // (if eventRule is null here, we could still have the default
- // method, so go on.)
- oper.parms = {};
- this.boundEvent = function() {
- this.binder.triggerEvent(this.name, oper);
- };
-;;; kukit.log('Node bound.');
- } else {
-;;; kukit.logWarning('No node bound.');
- this.boundEvent = function() {};
- }
+this.executeActions = function() {
+ if (! this.boundEvent) {
+;;; var msg = 'Attempt of late binding for event [' + this.name;
+;;; msg += '], node [' + this.node.nodeName + '].';
+;;; kukit.log(msg);
+ if (kukit.hasFirebug) {
+ kukit.log(this.node);
}
- this.boundEvent();
- };
+ var info = kukit.engine.binderInfoRegistry.getBinderInfoById(
+ this.binder.__binderId__);
+ var oper = info.bound.getBoundOperForNode(this.name, this.node);
+ if (oper) {
+ // (if eventRule is null here, we could still have the default
+ // method, so go on.)
+ oper.parms = {};
+ this.boundEvent = function() {
+ this.binder.triggerEvent(this.name, oper);
+ };
+;;; kukit.log('Node bound.');
+ } else {
+;;; kukit.logWarning('No node bound.');
+ this.boundEvent = function() {};
+ }
+ }
+ this.boundEvent();
+};
+this.initialize.apply(this, arguments);
};
/*
*
-* class EventBinder
-*
-* poor man's subclassing
-* This is called automatically on registration, to dress
-* up the event class with the necessary methods
+* class _EventBinder
*
-*/
-
-/* Provide callins on the state instance that execute a given
+* Provide callins on the state instance that execute a given
* continuation event.
* Parameters will be the ones specified in the call +
* those defined in the rule will be added too. (Parameters can
@@ -420,7 +421,7 @@
;;; var msg = 'Deprecated [__continueEvent__],';
;;; msg += 'use [continueEvent] instead !';
;;; kukit.logWarning(msg);
-this.continueEvent(name, node, defaultParameters);
+ this.continueEvent(name, node, defaultParameters);
};
this.continueEventAllNodes = function(name, defaultParameters) {
@@ -452,7 +453,7 @@
;;; var msg = 'Deprecated [__continueEvent_allNodes__],';
;;; msg += 'use [continueEventAllNodes] instead !';
;;; kukit.logWarning(msg);
-this.continueEventAllNodes(name, defaultParameters);
+ this.continueEventAllNodes(name, defaultParameters);
};
this.makeFuncToBind = function(name, node) {
@@ -466,11 +467,11 @@
;;; var msg = 'Deprecated [__makeFuncToBind__],';
;;; msg += 'use [makeFuncToBind] instead !';
;;; kukit.logWarning(msg);
-this.makeFuncToBind(name, node);
+ this.makeFuncToBind(name, node);
};
this.triggerEvent = function(name, oper) {
- // Private. Called from __continueEvent__ or from main event execution.
+ // Private. Called from continueEvent or from main event execution.
oper.binder = this;
if (oper.eventRule) {
// Call the actions, if we had an event rule.
@@ -499,7 +500,7 @@
;;; var msg = 'Deprecated [_EventBinder_triggerEvent],';
;;; msg += 'use [triggerEvent] instead !';
;;; kukit.logWarning(msg);
-this.triggerEvent(name, oper);
+ this.triggerEvent(name, oper);
};
/* (default) method call handling */
@@ -523,10 +524,11 @@
;;; var msg = 'Deprecated [_EventBinder_callMethod],';
;;; msg += 'use [callMethod] instead !';
;;; kukit.logWarning(msg);
-this.callMethod(namespace, name, oper, methodName);
+ this.callMethod(namespace, name, oper, methodName);
};
};
+
/* Event instance registry
*
* class BinderInfoRegistry
@@ -534,85 +536,88 @@
* used in run-time to keep track of the event instances
*
*/
+er.BinderInfoRegistry = function() {
-er.BinderInfoRegistry = function () {
+this.initialize = function() {
this.info = {};
+};
- this.getOrCreateBinderInfo =
- function (id, className, namespace) {
- // Get or create the event.
- var binderInfo = this.info[id];
- if (typeof(binderInfo) == 'undefined') {
- // Create a new event.
-;;; var msg = 'Instantiating event id [' + id + '], className [';
-;;; msg += className + '], namespace [' + namespace + '].';
-;;; kukit.logDebug(msg);
- var binderClass =
kukit.eventsGlobalRegistry.getBinderClass(className);
- var binder = new binderClass();
-
- binderInfo = this.info[id] = new _BinderInfo(binder);
-
- // decorate it with id and class
- binder.__binderId__ = id;
- binder.__binderClassName__ = className;
- binder.__eventNamespace__ = namespace;
- // store the bound rules
- //binder.__bound_rules__ = [];
- } else if (binderInfo.getBinder().__binderClassName__ !=
- className) {
- // just paranoia
-;;; kukit.E = 'Conflicting class for event id [' + id + '], [';
-;;; kukit.E += binderInfo.getBinder().__binderClassName__;
-;;; kukit.E += '] != [' + className + '].';
- throw new Error(kukit.E);
- }
- return binderInfo;
- };
+this.getOrCreateBinderInfo =
+ function (id, className, namespace) {
+ // Get or create the event.
+ var binderInfo = this.info[id];
+ if (typeof(binderInfo) == 'undefined') {
+ // Create a new event.
+;;; var msg = 'Instantiating event id [' + id + '], className [';
+;;; msg += className + '], namespace [' + namespace + '].';
+;;; kukit.logDebug(msg);
+ var binderClass = kukit.eventsGlobalRegistry.getBinderClass(className);
+ var binder = new binderClass();
+
+ binderInfo = this.info[id] = new _BinderInfo(binder);
- this.getBinderInfoById = function (id) {
- // Get an event.
- var binderInfo = this.info[id];
- if (typeof(binderInfo) == 'undefined') {
-;;; kukit.E = 'Event with id [' + id + '] not found.';
- throw new Error(kukit.E);
- }
- return binderInfo;
- };
+ // decorate it with id and class
+ binder.__binderId__ = id;
+ binder.__binderClassName__ = className;
+ binder.__eventNamespace__ = namespace;
+ // store the bound rules
+ //binder.__bound_rules__ = [];
+ } else if (binderInfo.getBinder().__binderClassName__ !=
+ className) {
+ // just paranoia
+;;; kukit.E = 'Conflicting class for event id [' + id + '], [';
+;;; kukit.E += binderInfo.getBinder().__binderClassName__;
+;;; kukit.E += '] != [' + className + '].';
+ throw new Error(kukit.E);
+ }
+ return binderInfo;
+};
- this.getSingletonBinderInfoByName =
- function (namespace, name) {
- //Get className
- var className = kukit.eventsGlobalRegistry.get(namespace,
name).className;
- // Get an event.
- var id = er.makeId(namespace, className);
- var binderInfo = this.info[id];
- if (typeof(binderInfo) == 'undefined') {
-;;; kukit.E = 'Singleton event with namespace [' + namespace;
-;;; kukit.E += '] and (event) name [' + name + '] not found.';
- throw new Error(kukit.E);
- }
- return binderInfo;
- };
+this.getBinderInfoById = function (id) {
+ // Get an event.
+ var binderInfo = this.info[id];
+ if (typeof(binderInfo) == 'undefined') {
+;;; kukit.E = 'Event with id [' + id + '] not found.';
+ throw new Error(kukit.E);
+ }
+ return binderInfo;
+};
- this.startBindingPhase = function () {
- // At the end of the binding phase, we want to process our events. This
- // must include all the binder instances we bound in this phase.
- for (var id in this.info) {
- var binderInfo = this.info[id];
- // process binding on this instance.
- binderInfo.startBindingPhase();
- }
- };
+this.getSingletonBinderInfoByName =
+ function (namespace, name) {
+ //Get className
+ var className = kukit.eventsGlobalRegistry.get(namespace, name).className;
+ // Get an event.
+ var id = er.makeId(namespace, className);
+ var binderInfo = this.info[id];
+ if (typeof(binderInfo) == 'undefined') {
+;;; kukit.E = 'Singleton event with namespace [' + namespace;
+;;; kukit.E += '] and (event) name [' + name + '] not found.';
+ throw new Error(kukit.E);
+ }
+ return binderInfo;
+};
- this.processBindingEvents = function () {
- // At the end of the binding phase, we want to process our events. This
- // must include all the binder instances we bound in this phase.
- for (var id in this.info) {
- var binderInfo = this.info[id];
- // process binding on this instance.
- binderInfo.processBindingEvents();
- }
- };
+this.startBindingPhase = function () {
+ // At the end of the binding phase, we want to process our events. This
+ // must include all the binder instances we bound in this phase.
+ for (var id in this.info) {
+ var binderInfo = this.info[id];
+ // process binding on this instance.
+ binderInfo.startBindingPhase();
+ }
+};
+
+this.processBindingEvents = function () {
+ // At the end of the binding phase, we want to process our events. This
+ // must include all the binder instances we bound in this phase.
+ for (var id in this.info) {
+ var binderInfo = this.info[id];
+ // process binding on this instance.
+ binderInfo.processBindingEvents();
+ }
+};
+this.initialize.apply(this, arguments);
};
/*
@@ -622,43 +627,45 @@
* various binding info. Follows the workflow of the binding in different
stages.
*
*/
+var _BinderInfo = function() {
-var _BinderInfo = function (binder) {
+this.initialize = function(binder) {
this.binder = binder;
this.bound = new _OperRegistry();
+ this.startBindingPhase();
+};
- this.getBinder = function () {
- return this.binder;
- };
-
- this.startBindingPhase = function () {
- // The binding phase starts and it has the information for
- // the currently on-bound events.
- this.binding = new _OperRegistry();
- };
-
- this.bindOper = function (oper) {
- // We mark a given oper. This means a binding on the binder
- // for given event, node and eventRule (containing event namespace,
- // name, and evt- parms.)
- //
- // first see if it can go to already bound ones
- this.bound.checkOperBindable(oper);
- // then register it properly to the binding events
- this.binding.bindOper(oper);
- };
+this.getBinder = function () {
+ return this.binder;
+};
- this.processBindingEvents = function () {
- // We came to the end of the binding phase. Now we process all our
binding
- // events, This will do the actual binding on the browser side.
- this.binding.processBindingEvents(this.binder);
- // Now we to add these to the new ones.
- this.binding.propagateTo(this.bound);
- // Delete them from the registry, to protect against accidents.
- this.binding = null;
- };
+this.startBindingPhase = function () {
+ // The binding phase starts and it has the information for
+ // the currently on-bound events.
+ this.binding = new _OperRegistry();
+};
- this.startBindingPhase();
+this.bindOper = function (oper) {
+ // We mark a given oper. This means a binding on the binder
+ // for given event, node and eventRule (containing event namespace,
+ // name, and evt- parms.)
+ //
+ // first see if it can go to already bound ones
+ this.bound.checkOperBindable(oper);
+ // then register it properly to the binding events
+ this.binding.bindOper(oper);
+};
+
+this.processBindingEvents = function () {
+ // We came to the end of the binding phase. Now we process all our binding
+ // events, This will do the actual binding on the browser side.
+ this.binding.processBindingEvents(this.binder);
+ // Now we to add these to the new ones.
+ this.binding.propagateTo(this.bound);
+ // Delete them from the registry, to protect against accidents.
+ this.binding = null;
+};
+this.initialize.apply(this, arguments);
};
var _iterators = {};
@@ -817,134 +824,135 @@
* a given event setup phase.
*
*/
-var _OperRegistry = function () {
+var _OperRegistry = function() {
+
+this.initialize = function() {
this.infoPerName = {};
this.infoPerNode = {};
+};
- // XXX we can do this without full cloning, more efficiently.
- this.propagateTo = function (newreg) {
- for (var key in this.infoPerName) {
- var rulesPerName = this.infoPerName[key];
- for (var name in rulesPerName) {
- var oper = rulesPerName[name];
- newreg.bindOper(oper);
- }
+// XXX we can do this without full cloning, more efficiently.
+this.propagateTo = function (newreg) {
+ for (var key in this.infoPerName) {
+ var rulesPerName = this.infoPerName[key];
+ for (var name in rulesPerName) {
+ var oper = rulesPerName[name];
+ newreg.bindOper(oper);
}
- };
+ }
+};
- this.checkOperBindable =
- function (oper, name, nodeHash) {
- // Check if the binding with this oper could be done.
- // Throw exception otherwise.
- //
- // Remark. We need different check and bind method,
- // because we need to bind to the currently
- // processed nodes, but we need to check duplication
- // in all the previously bound nodes.
- var info = this.infoPerName;
- // name and nodeHash are for speedup.
- if (typeof(nodeHash) == 'undefined') {
- name = oper.eventRule.kssSelector.name;
- nodeHash = kukit.rd.hashNode(oper.node);
- }
- var rulesPerName = info[name];
- if (typeof(rulesPerName) == 'undefined') {
- // Create an empty list.
- rulesPerName = info[name] = {};
- } else if (typeof(rulesPerName[nodeHash]) != 'undefined') {
-;;; kukit.E = 'Mismatch in bind registry,[ ' + name;
-;;; kukit.E += '] already bound to node in this instance.';
- throw new Error(kukit.E);
- }
- return rulesPerName;
- };
-
- this.bindOper = function (oper) {
- // Marks binding between binder, eventName, node.
- var name = oper.eventRule.kssSelector.name;
- var nodeHash = kukit.rd.hashNode(oper.node);
- var rulesPerName = this.checkOperBindable(oper, name, nodeHash);
- rulesPerName[nodeHash] = oper;
- // also store per node info
- var rulesPerNode = this.infoPerNode[nodeHash];
- if (typeof(rulesPerNode) == 'undefined') {
- // Create an empty list.
- rulesPerNode = this.infoPerNode[nodeHash] = {};
- }
- rulesPerNode[name] = oper;
- };
+this.checkOperBindable =
+ function (oper, name, nodeHash) {
+ // Check if the binding with this oper could be done.
+ // Throw exception otherwise.
+ //
+ // Remark. We need different check and bind method,
+ // because we need to bind to the currently
+ // processed nodes, but we need to check duplication
+ // in all the previously bound nodes.
+ var info = this.infoPerName;
+ // name and nodeHash are for speedup.
+ if (typeof(nodeHash) == 'undefined') {
+ name = oper.eventRule.kssSelector.name;
+ nodeHash = kukit.rd.hashNode(oper.node);
+ }
+ var rulesPerName = info[name];
+ if (typeof(rulesPerName) == 'undefined') {
+ // Create an empty list.
+ rulesPerName = info[name] = {};
+ } else if (typeof(rulesPerName[nodeHash]) != 'undefined') {
+;;; kukit.E = 'Mismatch in bind registry,[ ' + name;
+;;; kukit.E += '] already bound to node in this instance.';
+ throw new Error(kukit.E);
+ }
+ return rulesPerName;
+};
+
+this.bindOper = function (oper) {
+ // Marks binding between binder, eventName, node.
+ var name = oper.eventRule.kssSelector.name;
+ var nodeHash = kukit.rd.hashNode(oper.node);
+ var rulesPerName = this.checkOperBindable(oper, name, nodeHash);
+ rulesPerName[nodeHash] = oper;
+ // also store per node info
+ var rulesPerNode = this.infoPerNode[nodeHash];
+ if (typeof(rulesPerNode) == 'undefined') {
+ // Create an empty list.
+ rulesPerNode = this.infoPerNode[nodeHash] = {};
+ }
+ rulesPerNode[name] = oper;
+};
- // XXX This will need refactoring.
- /// We would only want to lookup from our registry and not the other way
around.
- this.processBindingEvents =
- function (binder) {
- var eventRegistry = kukit.eventsGlobalRegistry;
- for (var i=0; i < eventRegistry.eventSets.length; i++) {
- var eventSet = eventRegistry.eventSets[i];
- // Only process binding events (and ignore non-binding ones)
- if (eventSet.bindMethodName) {
- if (binder.__eventNamespace__ == eventSet.namespace) {
- // Process the binding event set.
- // This will call the actual bindmethods
- // according to the specified iterator.
- var iterator = er.getBindIterator(eventSet.iterName);
- iterator.call(this, eventSet, binder);
- }
+// XXX This will need refactoring.
+/// We would only want to lookup from our registry and not the other way
around.
+this.processBindingEvents =
+ function (binder) {
+ var eventRegistry = kukit.eventsGlobalRegistry;
+ for (var i=0; i < eventRegistry.eventSets.length; i++) {
+ var eventSet = eventRegistry.eventSets[i];
+ // Only process binding events (and ignore non-binding ones)
+ if (eventSet.bindMethodName) {
+ if (binder.__eventNamespace__ == eventSet.namespace) {
+ // Process the binding event set.
+ // This will call the actual bindmethods
+ // according to the specified iterator.
+ var iterator = er.getBindIterator(eventSet.iterName);
+ iterator.call(this, eventSet, binder);
}
}
- };
+ }
+};
- // XXX The following methods will probably disappear as iterators
- // replace their functionality.
+// XXX The following methods will probably disappear as iterators
+// replace their functionality.
- this.getBoundOperForNode = function (name, node) {
- // Get the oper that is bound to a given eventName
- // to a node in this binder
- // returns null, if there is no such oper.
- var rulesPerName = this.infoPerName[name];
- if (typeof(rulesPerName) == 'undefined') {
- return null;
- }
- var nodeHash = kukit.rd.hashNode(node);
- var oper = rulesPerName[nodeHash];
- if (typeof(oper) == 'undefined') {
- return null;
- }
- // Return it
- return oper;
- };
+this.getBoundOperForNode = function (name, node) {
+ // Get the oper that is bound to a given eventName
+ // to a node in this binder
+ // returns null, if there is no such oper.
+ var rulesPerName = this.infoPerName[name];
+ if (typeof(rulesPerName) == 'undefined') {
+ return null;
+ }
+ var nodeHash = kukit.rd.hashNode(node);
+ var oper = rulesPerName[nodeHash];
+ if (typeof(oper) == 'undefined') {
+ return null;
+ }
+ // Return it
+ return oper;
+};
- this.getBoundOpers = function (name) {
- // Get the opers bound to a given eventName (to any node)
- // in this binder
- var opers = [];
- var rulesPerName = this.infoPerName[name];
- if (typeof(rulesPerName) != 'undefined') {
- // take the values as a list
- for (var nodeHash in rulesPerName) {
- opers.push(rulesPerName[nodeHash]);
- }
+this.getBoundOpers = function (name) {
+ // Get the opers bound to a given eventName (to any node)
+ // in this binder
+ var opers = [];
+ var rulesPerName = this.infoPerName[name];
+ if (typeof(rulesPerName) != 'undefined') {
+ // take the values as a list
+ for (var nodeHash in rulesPerName) {
+ opers.push(rulesPerName[nodeHash]);
}
- // Return it
- return opers;
- };
-
-
- this.callBindMethod =
- function (eventSet, binder, p1, p2, p3, p4, p5, p6) {
- var method = binder[eventSet.bindMethodName];
- // Protect the binding for better logging
-;;; try {
- method.call(binder, p1, p2, p3, p4, p5, p6);
-;;; } catch(e) {
-;;; var names = eventSet.names;
-;;; var namespace = eventSet.namespace;
-;;; kukit.E = kukit.err.eventBindError(e, names, namespace);
-;;; throw new Error(kukit.E);
-;;; }
- };
-
+ }
+ // Return it
+ return opers;
+};
+this.callBindMethod =
+ function (eventSet, binder, p1, p2, p3, p4, p5, p6) {
+ var method = binder[eventSet.bindMethodName];
+ // Protect the binding for better logging
+;;; try {
+ method.call(binder, p1, p2, p3, p4, p5, p6);
+;;; } catch(e) {
+;;; var names = eventSet.names;
+;;; var namespace = eventSet.namespace;
+;;; kukit.E = kukit.err.eventBindError(e, names, namespace);
+;;; throw new Error(kukit.E);
+;;; }
+};
+this.initialize.apply(this, arguments);
};
er.makeId = function(namespace, name) {
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins