Author: gotcha
Date: Sun Dec 28 13:23:08 2008
New Revision: 60713
Modified:
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
Log:
bind explicitely
Modified:
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
Sun Dec 28 13:23:08 2008
@@ -53,16 +53,6 @@
* singleton registry object has to be provided. The items are
* bound on this registry.
*
- * registrar.bindItems(registry);
- *
- * In most cases, the registry can simply be a normal object. So
- * the usual setup what we have a registry for plugins is:
- *
- * registrar.bindItems({});
- *
- * However a registry could have attributes inherited with
- * a prototype, and if we want to have this, we could bind the items
- * on an object with a different prototype.
*
* After being bound, the registry set up,
* will appear directly accessable from registries.
@@ -128,7 +118,7 @@
return factory;
};
- this.bindItems = function(registries, registry) {
+ this.bindItems = function() {
// Check if we are finalized.
if (this.bound) {
;;; kukit.E = 'Attempt to bind already bound registry [';
@@ -137,6 +127,7 @@
}
;;; kukit.E = 'Binding registry [' + this.registryName + ']';
;;; kukit.logDebug(kukit.E);
+ var registry = {};
for (var name in this.factories) {
var factory = this.factories[name];
var item = factory.create();
@@ -145,11 +136,9 @@
registry[name] = item;
};
};
- // Store the registry itself on the registries
- // this means that it can be accessed as registries.registryname
- registries[this.registryName] = registry;
// Set bound state.
this.bound = true;
+ return registry;
};
this.initialize.apply(this, arguments);
@@ -439,11 +428,11 @@
reg.finalizeGlobalRegistries = function() {
var registrars = kukit.registrars;
kukit.plugins = {};
- registrars.events.bindItems(kukit.plugins, {});
- registrars.bindsequences.bindItems(kukit.plugins, {});
- registrars.actions.bindItems(kukit.plugins, {});
- registrars.valueproviders.bindItems(kukit.plugins, {});
- registrars.services.bindItems(kukit, {});
+ kukit.plugins.events = registrars.events.bindItems();
+ kukit.plugins.bindsequences = registrars.bindsequences.bindItems();
+ kukit.plugins.actions = registrars.actions.bindItems();
+ kukit.plugins.valueproviders = registrars.valueproviders.bindItems();
+ kukit.services = registrars.services.bindItems();
};
// At this point we setup the registries used by kukit,
Modified:
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
==============================================================================
---
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
(original)
+++
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
Sun Dec 28 13:23:08 2008
@@ -83,13 +83,13 @@
called = [];
//
// At this point we are also ready to bind the items the registrar.
- registrar.bindItems(this.registries, s);
+ this.dummytest = registrar.bindItems();
// This binds all the items.
this.assertListEquals(called, ['FUNC fooItem', 'FUNC barItem']);
called = [];
// At the same time it also set up these on the class prototype.
- this.assertEquals(this.registries.dummytest.fooItem, 'FUNC fooItem');
- this.assertEquals(this.registries.dummytest.barItem, 'FUNC barItem');
+ this.assertEquals(this.dummytest.fooItem, 'FUNC fooItem');
+ this.assertEquals(this.dummytest.barItem, 'FUNC barItem');
};
}; /* end RegistriesTestCase */
@@ -150,12 +150,12 @@
getter: function() {return function() {return 'fourth/extra';}}});
//
// Now bind the items.
- registrar.bindItems(this.registries, s);
+ this.dummyservice = registrar.bindItems();
// We can call the methods on it,
- this.assertEquals(this.registries.dummyservice.first(), 'first/core');
- this.assertEquals(this.registries.dummyservice.second(),
'second/extra');
- this.assertEquals(this.registries.dummyservice.third(), 'third/core');
- this.assertEquals(this.registries.dummyservice.fourth(),
'fourth/extra');
+ this.assertEquals(this.dummyservice.first(), 'first/core');
+ this.assertEquals(this.dummyservice.second(), 'second/extra');
+ this.assertEquals(this.dummyservice.third(), 'third/core');
+ this.assertEquals(this.dummyservice.fourth(), 'fourth/extra');
};
this.testChecker = function() {
@@ -183,9 +183,9 @@
getter: function() {return function() {return 'first/extra';}}});
//
// Now bind the items.
- registrar.bindItems(this.registries, s);
+ this.dummyservice = registrar.bindItems();
// call it
- this.assertEquals(this.registries.dummyservice.first(), 'first/core');
+ this.assertEquals(this.dummyservice.first(), 'first/core');
// Check that the checker has been called.
this.assertEquals(checker_counter, 1);
};
@@ -205,9 +205,9 @@
registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']});
// Now bind the items.
- registrar.bindItems(this.registries, s);
+ this.dummyservice = registrar.bindItems();
// We can call the methods on it,
- this.assertEquals(this.registries.dummyservice.first(), 'first/core');
+ this.assertEquals(this.dummyservice.first(), 'first/core');
};
this.testFinalizeTwice = function() {
@@ -223,10 +223,10 @@
registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']});
// Now bind all items.
- registrar.bindItems(this.registries, s);
+ registrar.bindItems();
// Bind it again.
this.assertThrows(function() {
- registrar.bindItems(this.registries, s);
+ registrar.bindItems();
},
Error);
};
@@ -242,7 +242,7 @@
getter: function() {return function() {return 'first/core';}}});
// Now bind all items.
this.assertThrows(function() {
- registrar.bindItems(this.registries, s);
+ registrar.bindItems();
},
Error)
};
@@ -292,7 +292,7 @@
getter: function() {return function() {return 'first/crap';}}});
// Now bind all items.
this.assertThrows(function() {
- registrar.bindItems(this.registries, s);
+ registrar.bindItems();
},
Error);
};
@@ -355,13 +355,13 @@
bindMethodName: 'bind'});
//
// Now bind all items.
- events.bindItems(this.registries, {});
- bindsequences.bindItems(this.registries, {});
+ this.dummyevents = events.bindItems();
+ this.dummybindsequences = bindsequences.bindItems();
// We can call the methods on it,
-
this.assertEquals(this.registries.dummyevents.click.defaultActionMethodName,
null);
-
this.assertEquals(this.registries.dummyevents.keydown.defaultActionMethodName,
null);
-
this.assertEquals(this.registries.dummyevents.timeout.defaultActionMethodName,
null);
- this.assertEquals(this.registries.dummybindsequences.timeout.iterName,
'Each');
+ this.assertEquals(this.dummyevents.click.defaultActionMethodName,
null);
+ this.assertEquals(this.dummyevents.keydown.defaultActionMethodName,
null);
+ this.assertEquals(this.dummyevents.timeout.defaultActionMethodName,
null);
+ this.assertEquals(this.dummybindsequences.timeout.iterName, 'Each');
};
this.testPluginNoDoubleReg = function() {
@@ -412,12 +412,12 @@
binderClass: MSub,
bindMethodName: 'bind'});
// bind
- bindsequences.bindItems(this.registries, {});
+ this.dummybindsequences = bindsequences.bindItems();
// Check that our classes are set as expected.
-
this.assertEquals(this.registries.dummybindsequences.click.binderClass, M);
-
this.assertEquals(this.registries.dummybindsequences.timeout.binderClass, M);
-
this.assertEquals(this.registries.dummybindsequences.keydown.binderClass, MSub);
-
this.assertEquals(this.registries.dummybindsequences.keypress.binderClass,
MSub);
+ this.assertEquals(this.dummybindsequences.click.binderClass, M);
+ this.assertEquals(this.dummybindsequences.timeout.binderClass, M);
+ this.assertEquals(this.dummybindsequences.keydown.binderClass, MSub);
+ this.assertEquals(this.dummybindsequences.keypress.binderClass, MSub);
// Check that both classes have a class name.
this.assert(M.prototype.__className__);
this.assert(MSub.prototype.__className__);
@@ -433,10 +433,10 @@
// Just call up the factoryr: this will create it with config=null.
events.getItemFactory('click');
// bind
- events.bindItems(this.registries, {});
+ this.dummyevents = events.bindItems();
// Check that click is not defined at all. (in particular, it should
not be null or {}.)
// Since other code that uses it, depends that if it has a value, it
is the real config.
- this.assertEquals(typeof(this.registries.dummyevents.click),
'undefined');
+ this.assertEquals(typeof(this.dummyevents.click), 'undefined');
};
this.testRegisterPlugins = function() {
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins