[KSS-checkins] r50031 - kukit/kukit.js/branch/finish-closures/kukit
gotcha at codespeak.net
gotcha at codespeak.net
Sun Dec 23 11:30:01 CET 2007
Author: gotcha
Date: Sun Dec 23 11:30:00 2007
New Revision: 50031
Modified:
kukit/kukit.js/branch/finish-closures/kukit/TODO.txt
kukit/kukit.js/branch/finish-closures/kukit/resourcedata.js
Log:
module and class closures
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 Sun Dec 23 11:30:00 2007
@@ -2,7 +2,6 @@
plugin.js
requestmanager.js
-resourcedata.js
utils.js move to kukit the names that are defined in kukit namespaces.
@@ -17,11 +16,8 @@
kssparser.js
kukit.js
oper.js
-plugin.js
providerreg.js
-requestmanager.js
resourcedata.js
selectorreg.js
serveraction.js
tokenizer.js
-utils.js
Modified: kukit/kukit.js/branch/finish-closures/kukit/resourcedata.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/resourcedata.js (original)
+++ kukit/kukit.js/branch/finish-closures/kukit/resourcedata.js Sun Dec 23 11:30:00 2007
@@ -19,12 +19,16 @@
/* Supplemental data that the parser builds up */
-kukit.rd = {};
+kukit.rd = new function() { /// MODULE START
+
+var rd = this;
/*
* class KssSelector
*/
-kukit.rd.KssSelector = function(isEvent, css, name, namespace, id, ppid) {
+rd.KssSelector = function() {
+
+this.initialize = function(isEvent, css, name, namespace, id, ppid, eventRegistry) {
this.isEventSelector = isEvent;
this.isMethodSelector = ! isEvent;
// XXX GC row and column are wrong...
@@ -66,25 +70,22 @@
this.className = null;
this.id = id;
this.ppid = ppid;
- // finish up the KSS on it
- // XXX We should not have this here, because this disables testing the parser
- // standalone, without a plugin registry. Original behaviour
- // should be reverted instead.
- this.setClassName();
+ this.setClassName(eventRegistry);
};
-
-kukit.rd.KssSelector.prototype.setClassName = function() {
+
+// finish up the KSS on it
+this.setClassName = function(eventRegistry) {
// Sets up id and class on the selector, based on registration info
// XXX GC instead of relying on exceptions, test if key exists
try {
- this.className = kukit.eventsGlobalRegistry.get(
+ this.className = eventRegistry.get(
this.namespace, this.name).className;
} catch(e) {
throw kukit.err.parsingError(e.message);
}
};
-kukit.rd.KssSelector.prototype.prepareId = function() {
+this.prepareId = function() {
if (this.ppid == null) {
if (this.id == null && this.ppid == null) {
// singleton for class
@@ -96,7 +97,7 @@
}
};
-kukit.rd.KssSelector.prototype.getId = function(node) {
+this.getId = function(node) {
// Gives the id depending on a node.
if (this.id) {
// Statically set.
@@ -122,7 +123,7 @@
}
};
-kukit.rd.KssSelector.prototype.getMergeId = function(node) {
+this.getMergeId = function(node) {
// Gives the merge id depending on a node.
if (this.mergeId) {
// Statically set.
@@ -133,6 +134,8 @@
this.mergeId = kukit.er.makeMergeId(id, this.namespace, this.name);
}
};
+this.initialize.apply(this, arguments);
+};
/*
* Kss parameter values. There are two kinds: text and method.
@@ -146,80 +149,81 @@
/*
* class KssTextValue
*/
-kukit.rd.KssTextValue = function(txt) {
+rd.KssTextValue = function(txt) {
// A text parameter in the format
// key: value;
+this.initialize = function(txt) {
this.txt = txt;
-};
+}
-kukit.rd.KssTextValue.prototype.isMethod = false;
-
-kukit.rd.KssTextValue.prototype.check = function(registry) {
+this.check = function(registry) {
// use the IdentityPP provider.
this.pprovider = new (registry.get(''))();
};
-kukit.rd.KssTextValue.prototype.evaluate =
+this.evaluate =
function(node, defaultParameters) {
// For normal string parms, this would return the string itself.
// In other execution contexts (like kssSelector, for example) this can
// do something else.
return this.pprovider.eval([this.txt], node, defaultParameters);
};
+this.initialize.apply(this, arguments);
+};
+rd.KssTextValue.prototype.isMethod = false;
/*
-* class KssTextValue
+* class KssMethodValue
*/
-kukit.rd.KssMethodValue = function(methodName, args) {
+rd.KssMethodValue = function(methodName, args) {
// A method parameter in the format
// key: methodName(v1, v2, ... vn);
this.methodName = methodName;
this.args = args;
-};
-
-kukit.rd.KssMethodValue.prototype.isMethod = true;
-
-kukit.rd.KssMethodValue.prototype.check = function(registry) {
- // Check syntax
- var f = registry.get(this.methodName);
- this.pprovider = new f();
- for(i=0; i < this.args.length; i++){
- // XXX We treat text values separetly because
- // they are now currently wrapped as KssTextValue
- // (as they should). TODO
- var arg = this.args[i];
- if(arg.check){
- // With the recursion we always use the global
- // provider registry
- arg.check(kukit.pprovidersGlobalRegistry);
+ this.check = function(registry) {
+ // Check syntax
+ var f = registry.get(this.methodName);
+ this.pprovider = new f();
+ for(i=0; i < this.args.length; i++){
+ // XXX We treat text values separetly because
+ // they are now currently wrapped as KssTextValue
+ // (as they should). TODO
+ var arg = this.args[i];
+ if(arg.check){
+ // With the recursion we always use the global
+ // provider registry
+ arg.check(kukit.pprovidersGlobalRegistry);
+ }
}
- }
-;;; this.pprovider.check(this.args);
-};
+ ;;; this.pprovider.check(this.args);
+ };
-kukit.rd.KssMethodValue.prototype.evaluate =
- function(node, defaultParameters) {
- // First recursivly evaluate all arguments
- var newArgs = [];
- for(var i=0; i < this.args.length; i++){
- // XXX We treat text values separetly because
- // they are now currently wrapped as KssTextValue
- // (as they should). TODO
- var arg = this.args[i];
- if(arg.evaluate){
- newArgs.push(arg.evaluate(node, defaultParameters));
- } else {
- newArgs.push(arg);
+ this.evaluate =
+ function(node, defaultParameters) {
+ // First recursivly evaluate all arguments
+ var newArgs = [];
+ for(var i=0; i < this.args.length; i++){
+ // XXX We treat text values separetly because
+ // they are now currently wrapped as KssTextValue
+ // (as they should). TODO
+ var arg = this.args[i];
+ if(arg.evaluate){
+ newArgs.push(arg.evaluate(node, defaultParameters));
+ } else {
+ newArgs.push(arg);
+ }
}
- }
- // return the value
- return this.pprovider.eval(newArgs, node, defaultParameters);
+ // return the value
+ return this.pprovider.eval(newArgs, node, defaultParameters);
+ };
};
+rd.KssMethodValue.prototype.isMethod = true;
+
/*
* class KssEventValue
*/
-kukit.rd.KssEventValue = function(methodName, arg) {
+rd.KssEventValue = function(methodName, arg) {
// A method parameter in the format
// methodname(v1)
// can be also:
@@ -227,19 +231,18 @@
// in both cases, arg is KssTextValue, or KssMethodValue
this.methodName = methodName;
this.arg = arg;
+ this.check = function() {};
};
+rd.KssEventValue.prototype.isMethod = true;
-kukit.rd.KssEventValue.prototype.isMethod = true;
-
-kukit.rd.KssEventValue.prototype.check = function() {
-};
-
-kukit.rd.EventRuleNr = 0; // just a counter
+rd.EventRuleNr = 0; // just a counter
/*
* class EventRule
*/
-kukit.rd.EventRule = function(kssSelector, parms, actions) {
+rd.EventRule = function() {
+
+this.initialize = function(kssSelector, parms, actions) {
if (typeof(parms) == 'undefined') {
// called for merging clone
// Setting up kssSelector is enough here. Parms and the rest
@@ -247,9 +250,9 @@
// on the rule after creation.
this.kssSelector = kssSelector;
} else {
- this.index = kukit.rd.EventRuleNr;
+ this.index = rd.EventRuleNr;
this.mergedIndex = null;
- kukit.rd.EventRuleNr = this.index + 1;
+ rd.EventRuleNr = this.index + 1;
;;; var namestr;
;;; if (kssSelector.namespace) {
;;; namestr = kssSelector.namespace + '-' + kssSelector.name;
@@ -265,7 +268,7 @@
}
};
-kukit.rd.EventRule.prototype.getIndex = function() {
+this.getIndex = function() {
if (this.mergedIndex) {
return this.mergedIndex;
} else {
@@ -273,7 +276,7 @@
}
};
-kukit.rd.EventRule.prototype.mergeForSelectedNodes =
+this.mergeForSelectedNodes =
function(ruletable, phase, inNodes) {
// Select all nodes within the inNodes for phase==2.
@@ -306,7 +309,7 @@
}
};
-kukit.rd.EventRule.prototype.getBinderInfo = function(node) {
+this.getBinderInfo = function(node) {
// Figure out what will be the "state id" for the kss event rule.
var id = this.kssSelector.getId(node);
// Gets the event instance for the rule.
@@ -326,7 +329,7 @@
*
*/
-kukit.rd.EventRule.prototype.bind = function(node) {
+this.bind = function(node) {
this.store(node);
// Creation of the binding oper
var oper = new kukit.op.Oper();
@@ -339,7 +342,7 @@
binderInfo.bindOper(oper);
};
-kukit.rd.EventRule.prototype.store = function(node) {
+this.store = function(node) {
if (node == null) {
// node == null is *always* valid, it means "document".
return;
@@ -350,19 +353,18 @@
}
node.kukitEventRules.push(this);
};
-
/*
* Merging event rules
*/
-kukit.rd.EventRule.prototype.isMerged = function() {
+this.isMerged = function() {
return (this.mergedIndex != null);
};
-kukit.rd.EventRule.prototype.cloneForMerge = function() {
+this.cloneForMerge = function() {
// Do not touch ourselves, make a new copy for the merge.
- var merged = new kukit.rd.EventRule(this.kssSelector);
- merged.actions = new kukit.rd.ActionSet();
+ var merged = new rd.EventRule(this.kssSelector);
+ merged.actions = new rd.ActionSet();
merged.parms = {};
merged.mergedIndex = 'X';
merged.merge(this);
@@ -370,7 +372,7 @@
return merged;
};
-kukit.rd.EventRule.prototype.merge = function(other) {
+this.merge = function(other) {
;;; if (! this.isMerged()) {
;;; throw new Error('Cannot merge into a genuine event rule');
;;; }
@@ -398,7 +400,7 @@
;;; }
};
-kukit.rd.EventRule.prototype.mergeIntoDict = function(dict, key) {
+this.mergeIntoDict = function(dict, key) {
// Merge into the given dictionary by given key.
// If possible, store the genuine rule first - if not,
// clone it and do a merge. Never destroy the genuine
@@ -417,29 +419,34 @@
mergedRule.merge(this);
}
};
+this.initialize.apply(this, arguments);
+};
+
/*
* class ActionSet
*/
-kukit.rd.ActionSet = function() {
+rd.ActionSet = function() {
+
+this.initialize = function() {
this.content = {};
};
-kukit.rd.ActionSet.prototype.hasActions = function() {
+this.hasActions = function() {
for (var name in this.content) {
return true;
}
return false;
};
-kukit.rd.ActionSet.prototype.merge = function(other) {
+this.merge = function(other) {
for (var key in other.content) {
var action = this.content[key];
var action2 = other.content[key];
if (typeof(action) == 'undefined') {
if (action2.type != 'X') {
// new action
- action = new kukit.rd.Action();
+ action = new _Action();
this.content[key] = action;
} else {
;;; var msg = 'Cannot action-delete unexisting action, [';
@@ -460,7 +467,7 @@
}
};
-kukit.rd.ActionSet.prototype.execute = function(oper) {
+this.execute = function(oper) {
for (var key in this.content) {
var action = this.content[key];
// do not execute error actions!
@@ -480,17 +487,17 @@
}
};
-kukit.rd.ActionSet.prototype.getOrCreateAction = function(name) {
+this.getOrCreateAction = function(name) {
var action = this.content[name];
if (typeof(action) == 'undefined') {
- action = new kukit.rd.Action();
+ action = new _Action();
action.setName(name);
this.content[name] = action;
}
return action;
};
-kukit.rd.ActionSet.prototype.getActionOrNull = function(name) {
+this.getActionOrNull = function(name) {
var action = this.content[name];
if (typeof(action) == 'undefined') {
action = null;
@@ -498,7 +505,7 @@
return action;
};
-kukit.rd.ActionSet.prototype.deleteAction = function(name) {
+this.deleteAction = function(name) {
var action = this.content[name];
;;; if (typeof(action) == 'undefined') {
;;; throw new Error('Action [' + name + '] does not exist and cannot be deleted.');
@@ -507,27 +514,31 @@
};
-kukit.rd.ActionSet.prototype.getDefaultAction = function() {
+this.getDefaultAction = function() {
return this.getActionOrNull('default');
};
-kukit.rd.ActionSet.prototype.getErrorActionFor = function(action) {
+this.getErrorActionFor = function(action) {
// Get the error action of a given action: or null,
// if the action does not define an error handler.
return this.getActionOrNull(action.error);
};
+this.initialize.apply(this, arguments);
+};
/*
-* class Action
+* class _Action
*/
-kukit.rd.Action = function() {
+var _Action = function() {
+
+this.initialize = function() {
this.name = null;
this.error = null;
this.parms = {};
this.type = null;
};
-kukit.rd.Action.prototype.setName = function(name) {
+this.setName = function(name) {
;;; if (this.name != null && this.name != name) {
;;; var msg = 'Error overriding action name [' + this.name;
;;; msg = msg + '] to [' + name + '] (Unmatching action names at merge?)';
@@ -544,7 +555,7 @@
}
};
-kukit.rd.Action.prototype.setType = function(type) {
+this.setType = function(type) {
// Allowed types:
//
// S = server
@@ -573,7 +584,7 @@
this.type = type;
};
-kukit.rd.Action.prototype.setError = function(error) {
+this.setError = function(error) {
;;; if (this.type != null && this.type != 'S') {
;;; var msg = 'Error setting action error handler on action [' + this.name;
;;; msg = msg + '], this is only allowed on server actions.';
@@ -582,7 +593,7 @@
this.error = error;
};
-kukit.rd.Action.prototype.merge = function(other) {
+this.merge = function(other) {
// Merge to the instance.
if (other.name != null) {
this.setName(other.name);
@@ -599,7 +610,7 @@
}
};
-kukit.rd.Action.prototype.makeActionOper = function(oper) {
+this.makeActionOper = function(oper) {
// Fill the completed action parms, based on the node
// The kssXxx parms, reserved for the action, are
// handled as appropriate.
@@ -630,7 +641,7 @@
return anOper;
};
-kukit.rd.Action.prototype.execute = function(oper) {
+this.execute = function(oper) {
oper = this.makeActionOper(oper);
switch (this.type) {
case 'D': {
@@ -652,31 +663,35 @@
} break;
}
};
+this.initialize.apply(this, arguments);
+};
/*
* class LoadActions
*/
-kukit.rd.LoadActions = function() {
+rd.LoadActions = function() {
+
+this.initialize = function() {
this.items = [];
};
-kukit.rd.LoadActions.prototype.empty = function() {
+this.empty = function() {
return (this.size() == 0);
};
-kukit.rd.LoadActions.prototype.size = function() {
+this.size = function() {
return this.items.length;
};
-kukit.rd.LoadActions.prototype.push = function(f) {
+this.push = function(f) {
if (this.items.length >= 100) {
throw ('Infinite recursion, stack full');
}
this.items.push(f);
};
-kukit.rd.LoadActions.prototype.execute = function() {
+this.execute = function() {
var f = this.items.shift();
if (f) {
f();
@@ -686,7 +701,7 @@
}
};
-kukit.rd.LoadActions.prototype.executeAll = function() {
+this.executeAll = function() {
var i = 0;
while(true) {
var success = this.execute();
@@ -697,7 +712,8 @@
}
return i;
};
-
+this.initialize.apply(this, arguments);
+};
/*
* class RuleTable
@@ -722,14 +738,16 @@
*
*/
-kukit.rd.RuleTable = function(loadScheduler) {
+rd.RuleTable = function() {
+
+this.initialize = function(loadScheduler) {
this.loadScheduler = loadScheduler;
this.nodes = {};
};
-kukit.rd.RuleTable.prototype.add = function(node, eventRule) {
+this.add = function(node, eventRule) {
// look up node
- var nodehash = kukit.rd.hashNode(node);
+ var nodehash = rd.hashNode(node);
var nodeval = this.nodes[nodehash];
if (typeof(nodeval) == 'undefined') {
nodeval = {'node': node, 'val': {}};
@@ -740,7 +758,7 @@
nodeval.val, eventRule.kssSelector.getMergeId(node));
};
-kukit.rd.RuleTable.prototype.bindall = function(phase) {
+this.bindall = function(phase) {
// Bind all nodes
var counter = 0;
for (var nodehash in this.nodes) {
@@ -762,10 +780,12 @@
;;; kukit.logDebug(count + ' load actions executed.');
}
};
+this.initialize.apply(this, arguments);
+};
-kukit.rd.uid = 0;
+rd.uid = 0;
-kukit.rd.hashNode = function(node) {
+rd.hashNode = function(node) {
// It is, generally, not possible to use a node as a key.
// However we try to set this right.
// We generate an uniqueID on the node. This does not work
@@ -776,9 +796,9 @@
}
var id = node.uniqueID;
if (typeof(id) == 'undefined') {
- id = kukit.rd.uid;
+ id = rd.uid;
node.uniqueID = id;
- kukit.rd.uid ++;
+ rd.uid ++;
}
return id;
};
@@ -791,13 +811,15 @@
* Unlike the rule table that is specific for each binding,
* this is unique to the page.
*/
-kukit.rd.MethodTable = function() {
+rd.MethodTable = function() {
+
+this.initialize = function() {
this.content = {};
this.content['document'] = {};
this.content['behaviour'] = {};
};
-kukit.rd.MethodTable.prototype.add = function(eventRule) {
+this.add = function(eventRule) {
// Get the entry by the type which is now at css
var category = eventRule.kssSelector.css;
var dict = this.content[category];
@@ -809,7 +831,7 @@
eventRule.mergeIntoDict(dict, eventRule.kssSelector.getMergeId());
};
-kukit.rd.MethodTable.prototype.getMergedRule =
+this.getMergedRule =
function(category, name, binder) {
// Returns the rule for a given event instance,
@@ -830,7 +852,7 @@
return mergedRule;
};
-kukit.rd.MethodTable.prototype.bindall = function() {
+this.bindall = function() {
// bind document events
var documentRules = this.content['document'];
var counter = 0;
@@ -841,3 +863,7 @@
}
;;; kukit.logDebug(counter + ' rules bound to document.');
};
+this.initialize.apply(this, arguments);
+};
+
+}(); /// MODULE END
More information about the Kukit-checkins
mailing list