Author: reebalazs
Date: Tue Dec 25 12:59:10 2007
New Revision: 50085
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/ (props changed)
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/oper.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
Log:
Make it work with event-binder demo
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
Tue Dec 25 12:59:10 2007
@@ -77,7 +77,7 @@
var events = kukit.interfaces.global.get('events',
kukit.interfaces.PluginMethodDescriptor);
events.getMethodDescriptor(eventName).register({
eventName: eventName,
- defaultMethodName: null,
+ defaultActionMethodName: defaultActionMethodName,
parmtypes: null // missing from this api.
});
}
@@ -258,13 +258,6 @@
;;; kukit.logDebug('Event [' + name + '] executed on ' + executed + ' nodes.');
};
-var _EventBinder_makeFuncToBind = function(name, node) {
- var executor = new er._LateBinder(this, name, node);
- return function() {
- executor.executeActions();
- };
-};
-
/*
*
* class _LateBinder
@@ -279,6 +272,13 @@
* By commenting it out I want to demonstrate that it's not
* used anyway
+var _EventBinder_makeFuncToBind = function(name, node) {
+ var executor = new er._LateBinder(this, name, node);
+ return function() {
+ executor.executeActions();
+ };
+};
+
var _LateBinder = function(binder, name, node) {
this.binder = binder;
this.name = name;
@@ -361,25 +361,27 @@
this.decorateEventBinderClass = function(cls) {
// See if we are set up already?
- // XXX XXX this will cause a problem if classes
- // are inherited from each other... then classNames
- // would not be set... hmm...
- var p = cls.prototype;
- if (p.__decorated_for_kss__) {
+ // We make a mark not on the class prototype,
+ // but on the class itself. This will make
+ // sure inherited classes get a distinct class name.
+ if (cls.__decorated_for_kss__) {
return;
}
+ var p = cls.prototype;
// Put inherited methods on it
p.__continueEvent__ = _EventBinder__continueEvent__;
p.__continueEvent_allNodes__ =
_EventBinder__continueEvent_allNodes__;
p._EventBinder_triggerEvent = _EventBinder_triggerEvent;
p._EventBinder_callMethod = _EventBinder_callMethod;
- p.__makeFuncToBind__ = _EventBinder_makeFuncToBind;
+// p.__makeFuncToBind__ = _EventBinder_makeFuncToBind; // only used by
LateBinder atm
// Generate a unique class name
p.__className__ = '' + _eventClassCounter;
_eventClassCounter ++;
- // mark decorated
- p.__decorated_for_kss__ = true;
+ // mark decorated. We store the class there
+ // so we can decide if this class has been
+ // decorated or not.
+ cls.__decorated_for_kss__ = true;
};
/* Event instance registry
@@ -402,7 +404,7 @@
er.BinderInfoRegistry.prototype.getOrCreateBinderInfo =
function (kssSelector, node) {
// We use the key as the selector's merge id.
- var key = kssSelector.getMergeId();
+ var key = kssSelector.getBindKey(node);
// Get or create the binder and the binder info.
var binderInfo = this.info[key];
if (typeof(binderInfo) == 'undefined') {
@@ -412,7 +414,7 @@
//kukit.logWarning(kssSelector.getBindIteration());
var binderClass = kssSelector.getBindIteration().binderClass;
-;;; var msg = 'Instantiating event binder with id [' + kssSelector.getId()
+ '], className [';
+;;; var msg = 'Instantiating event binder with id [' +
kssSelector.getId(node) + '], className [';
;;; msg += binderClass.prototype.__className__ + '].';
;;; kukit.logDebug(msg);
@@ -696,11 +698,12 @@
};
_OperRegistry.prototype.callBindMethod =
- function (iteration, binder, p1, p2, p3, p4, p5, p6) {
+ function (iteration, binder, p1, p2, p3, p4, p5) {
+ // get the method itself
var method = binder[iteration.bindMethodName];
// Protect the binding for better logging
;;; try {
- method.call(binder, p1, p2, p3, p4, p5, p6);
+ method.call(binder, p1, p2, p3, p4, p5);
;;; } catch(e) {
;;; kukit.E = kukit.err.eventBindError(e, iteration.eventNames);
;;; throw new Error(kukit.E);
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/oper.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/oper.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/oper.js
Tue Dec 25 12:59:10 2007
@@ -243,7 +243,7 @@
// in which case it is not present as an action.
//
var interface = kukit.interfaces.global;
- var methodName = interface.events[name].defaultActionMethodName;
+ var methodName =
interface.events[this.getEventName()].defaultActionMethodName;
return (typeof methodName != 'undefined');
} else
return false;
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
==============================================================================
---
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
(original)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
Tue Dec 25 12:59:10 2007
@@ -55,7 +55,11 @@
this.name = name;
this.id = id;
this.ppid = ppid;
+ // mergeId and bindKey store bindings on a given interface,
+ // in case this can be statically decided ie. there is
+ // no value provider used to define the id.
this.mergeId = null;
+ this.bindKey = null;
this.bindIteration = null;
// finish up the KSS on it
// XXX We should not have this here, because this disables testing the
parser
@@ -92,6 +96,7 @@
// at it depending on nodes.
// This step will access the interfaces already
// by calling getBindIteration.
+ this.bindKey = this.getBindKey();
this.mergeId = this.getMergeId();
} else {
// We have a value provider for the id. We cannot set the
@@ -152,11 +157,30 @@
kukit.rd.KssSelector.prototype.getMergeId = function(node) {
// Gives the merge id depending on a node.
- // In case the mergeId is statically set, it dies not
+ // This id will identify what other rules this rule can merge
+ // with, if they match on the same node. Only rules with the same
+ // merge id will match. Therefore the merge id contains the bind key,
+ // plus the event name.
+ // In case the mergeId is statically set, it does not
// depend on the node.
if (this.mergeId) {
// Statically set.
return this.mergeId;
+ } else {
+ return this.name + '@' + this.getBindKey(node);
+ }
+};
+
+kukit.rd.KssSelector.prototype.getBindKey = function(node) {
+ // Gives the bind key depending on a node.
+ // This key identifies the binder instance on which
+ // selector will operate. Therefore it consists of the
+ // classname and the event id.
+ // In case the mergeId is statically set, it does not
+ // depend on the node.
+ if (this.bindKey) {
+ // Statically set.
+ return this.bindKey;
} else {
// Evaluate the id depending on the node.
var id = this.getId(node);
@@ -166,11 +190,12 @@
// name cannot contain a @
// id can be any string
// so the merge id will be unique
- return className + '@' + this.name + '@' + id;
+ return className + '@' + id;
}
};
+
/*
* Kss parameter values. There are two kinds: text and method.
*
@@ -501,9 +526,11 @@
// Execute the default action in case of there is one but there were no
// parms so it was actually not entered as an action object
// otherwise, it would have been executed from action.execute already
+ // XXX This part will go away, as we want to make default actions
+ // explicitely needed in kss.
if (typeof(this.content['default']) == 'undefined') {
// this is conditional: if there is no default method, it's skipped.
- var name = oper.eventRule.kssSelector.name;
+ var name = oper.getEventName();
// Execution with no parms. (XXX ?)
oper = oper.clone({'parms': {}});
oper.executeDefaultAction(name, true);
@@ -665,7 +692,7 @@
switch (this.type) {
case 'D': {
// Default action.
- var name = oper.eventRule.kssSelector.name;
+ var name = oper.getEventName();
oper.executeDefaultAction(name);
} break;
case 'S': {
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
==============================================================================
---
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
(original)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
Tue Dec 25 12:59:10 2007
@@ -369,13 +369,13 @@
// somewhere else, core registers the methods:
events.getMethodDescriptor('click').register({
name: 'click',
- defaultMethodName: null,
+ defaultActionMethodName: null,
parmtypes: [
['preventDefault', 'bool', true],
['allowBubbling', 'bool', false]]});
events.getMethodDescriptor('keydown').register({
name: 'keydown',
- defaultMethodName: null,
+ defaultActionMethodName: null,
parmtypes: [
['preventDefault', 'bool', true],
['allowBubbling', 'bool', false]]});
@@ -389,7 +389,7 @@
// somewhere else, extras registers the methods:
events.getMethodDescriptor('timeout').register({
name: 'timeout',
- defaultMethodName: null,
+ defaultActionMethodName: null,
parmtypes: [
['millis', 'int'],
['renew', 'bool', false]]});
@@ -405,9 +405,9 @@
events.finalize({});
binditerations.finalize({});
// We can call the methods on it,
- this.assertEquals(this.interfaces.dummyevents.click.defaultMethodName,
null);
-
this.assertEquals(this.interfaces.dummyevents.keydown.defaultMethodName, null);
-
this.assertEquals(this.interfaces.dummyevents.timeout.defaultMethodName, null);
+
this.assertEquals(this.interfaces.dummyevents.click.defaultActionMethodName,
null);
+
this.assertEquals(this.interfaces.dummyevents.keydown.defaultActionMethodName,
null);
+
this.assertEquals(this.interfaces.dummyevents.timeout.defaultActionMethodName,
null);
this.assertEquals(this.interfaces.dummybinditerations.timeout.iterName, 'Each');
};
@@ -418,7 +418,7 @@
// somewhere a plugin registers something:
events.getMethodDescriptor('click').register({
name: 'click',
- defaultMethodName: null,
+ defaultActionMethodName: null,
parmtypes: [
['preventDefault', 'bool', true],
['allowBubbling', 'bool', false]]});
@@ -426,7 +426,7 @@
this.assertThrows(function() {
events.getMethodDescriptor('click').register({
name: 'click',
- defaultMethodName: null,
+ defaultActionMethodName: null,
parmtypes: [
['preventDefault', 'bool', true],
['allowBubbling', 'bool', false]]});
@@ -444,15 +444,31 @@
iterName: 'Each',
binderClass: M,
bindMethodName: 'bind'});
- // But another providing attempt is punished by an Error.
- this.assertThrows(function() {
- iface.getMethodDescriptor('').register({
- eventNames: ['keyDown', 'timeout'],
- iterName: 'Each',
- binderClass: M,
- bindMethodName: 'bind'});
- },
- Error);
+ // Suppose we have now a binder class that is a
+ // subclass of the previous one. In this case,
+ // it is essential to check that they got a different
+ // className.
+ var MSub = function() {
+ this.bind2 = function(oper) {};
+ };
+ MSub.prototype = new M();
+ iface.getMethodDescriptor('').register({
+ eventNames: ['keydown', 'keypress'],
+ iterName: 'Each',
+ binderClass: MSub,
+ bindMethodName: 'bind'});
+ // initialize
+ iface.finalize({});
+ // Check that our classes are set as expected.
+ this.assert(this.interfaces.dummybinditeration.click.binderClass, M);
+ this.assert(this.interfaces.dummybinditeration.timeout.binderClass, M);
+ this.assert(this.interfaces.dummybinditeration.keydown.binderClass,
MSub);
+ this.assert(this.interfaces.dummybinditeration.keypress.binderClass,
MSub);
+ // Check that both classes have a class name.
+ this.assert(M.prototype.__className__);
+ this.assert(MSub.prototype.__className__);
+ // Check the two classes have distinct class names
+ this.assertNotEquals(M.prototype.__className__,
MSub.prototype.__className__);
};
}; /* end PluginInterfacesTestCase */
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins