diff --git a/lib/JooseX/Bridge/Ext.js b/lib/JooseX/Bridge/Ext.js index 91592d3..6d7f780 100644 --- a/lib/JooseX/Bridge/Ext.js +++ b/lib/JooseX/Bridge/Ext.js @@ -1,61 +1,3 @@ -/** - * @class - * @name Joose.Bridge.Ext - * @desc This package provides fully backward-compatible drop-in replacement for Ext.extend, which turns standard Ext classes into Joose Classes. - * After including this package you can derive new classes in standard way -
-Ext.myWindow = Joose.Bridge.Ext.my.extend(Ext.Window, {
-    
-    initComponent : function (){
-        Ext.myWindow.superclass.initComponent.call(this)
-        this.width = 800
-    }
-    
-})
-
-or in the native Joose way: -
-ExtClass('Ext.myWindow', {
-    isa : Ext.Window,
-    
-    after : {
-        initComponent : function (){
-            this.width = 800
-        }
-    }
-    
-})
-
-in both cases you can use any of Joose features with your classes, for example - apply Roles, either statically, during creation: -
-Role('Joosificator', {
-    before : {
-        render : function(){
-            this.title = "Joosified: " + this.title
-        }
-    }
-})
-
-ExtClass('Ext.myWindow', {
-    isa : Ext.Window,
-    
-    does : [Joosificator],
-    
-    ...
-})
-
-or dynamically, at run-time: -
-Ext.myWindow.meta.extend({
-    does : [Joosificator]
-})
-
- *
See the forum thread for additional details and Joose home page for complete manual on Joose. - * @version 0.1 - * @author SamuraiJack - * @license LGPL 3.0 - */ - Class('JooseX.Bridge.Ext', { meta : Joose.Meta.Class, @@ -66,6 +8,8 @@ Class('JooseX.Bridge.Ext', { defaultConstructor : function () { var jooseConstructor = this.SUPER() + this.adaptConstructor(jooseConstructor) + return function () { var self = this @@ -73,7 +17,6 @@ Class('JooseX.Bridge.Ext', { if (!this.__JOOSE_INIT_DONE__) { this.__JOOSE_INIT_DONE__ = true - jooseConstructor.meta = this.meta self = jooseConstructor.apply(this, arguments) || self } @@ -96,13 +39,11 @@ Class('JooseX.Bridge.Ext', { }, - processSuperClass: function () { - var superClass = this.superClass + processSuperClass: function (superClass) { var superProto = superClass.prototype this.c.superclass = superProto - if (!superClass.meta) { var helperClass = new this.defaultSuperClass.meta.constructor(null, superProto).c @@ -125,15 +66,6 @@ Class('JooseX.Bridge.Ext', { methods : { - /** - * Improved Ext.ux.extend. Provides exactly the same interface as standard Ext.ux.extend plus it converts both classes into Joose Classes..
- * @name Joose.Bridge.Ext#extend - * @methodOf Joose.Bridge.Ext - * @param {Class} subClass The class inheriting the functionality - * @param {Class} superClass The class being extended - * @param {Object} [overrides] A literal with members which are copied into the subclass's prototype, and are therefore shared between all instances of the new class. - * @return {Class} The subclass constructor. - */ extend : function (subClass, superClass, extend) { if (typeof superClass == 'object'){ @@ -168,6 +100,21 @@ Class('JooseX.Bridge.Ext', { }) +Joose.Namespace.Manager.my.register('ExtClass', JooseX.Bridge.Ext) + + + +/** + * Improved Ext.ux.extend. Provides exactly the same interface as standard Ext.ux.extend plus it converts both classes into Joose Classes..
+ * @name Joose.Bridge.Ext#extend + * @methodOf Joose.Bridge.Ext + * @param {Class} subClass The class inheriting the functionality + * @param {Class} superClass The class being extended + * @param {Object} [overrides] A literal with members which are copied into the subclass's prototype, and are therefore shared between all instances of the new class. + * @return {Class} The subclass constructor. + */ + + /** * Class builder for meta-class Joose.ExtClass, which provide compatibility with Joose. This is the exact analog of standard Class function in Joose, * see this page for examples. This function is copied into global scope and is using for creation of new classes. @@ -177,4 +124,62 @@ Class('JooseX.Bridge.Ext', { * @param {Object} [overrides] A literal with members, from which the new Class is constructed. See Joose manual. * @return {Class} The class constructor. */ -Joose.Namespace.Manager.my.register('ExtClass', JooseX.Bridge.Ext) \ No newline at end of file + + +/** + * @class + * @name Joose.Bridge.Ext + * @desc This package provides fully backward-compatible drop-in replacement for Ext.extend, which turns standard Ext classes into Joose Classes. + * After including this package you can derive new classes in standard way +
+Ext.myWindow = Joose.Bridge.Ext.my.extend(Ext.Window, {
+    
+    initComponent : function (){
+        Ext.myWindow.superclass.initComponent.call(this)
+        this.width = 800
+    }
+    
+})
+
+or in the native Joose way: +
+ExtClass('Ext.myWindow', {
+    isa : Ext.Window,
+    
+    after : {
+        initComponent : function (){
+            this.width = 800
+        }
+    }
+    
+})
+
+in both cases you can use any of Joose features with your classes, for example - apply Roles, either statically, during creation: +
+Role('Joosificator', {
+    before : {
+        render : function(){
+            this.title = "Joosified: " + this.title
+        }
+    }
+})
+
+ExtClass('Ext.myWindow', {
+    isa : Ext.Window,
+    
+    does : [Joosificator],
+    
+    ...
+})
+
+or dynamically, at run-time: +
+Ext.myWindow.meta.extend({
+    does : [Joosificator]
+})
+
+ *
See the forum thread for additional details and Joose home page for complete manual on Joose. + * @version 0.1 + * @author SamuraiJack + * @license LGPL 3.0 + */ diff --git a/t/010_instantiation.t.js b/t/010_instantiation.t.js index bee5728..036fc70 100644 --- a/t/010_instantiation.t.js +++ b/t/010_instantiation.t.js @@ -22,22 +22,22 @@ StartTest(function(t) { Role('Joosificator', { before : { render : function(){ - this.title = 'Joosified! ' + this.title; + this.title = 'Joosified! ' + this.title } } - }); + }) Ext.Window.meta.extend({ does : [ Joosificator ] - }); + }) var win2 = new Ext.Window({ title : 'Joose Bridge', width : 300, height : 300 - }); + }) - win2.show(); + win2.show() t.ok(win2.title == 'Joosified! Joose Bridge', 'Ext.Window were jusified') @@ -49,14 +49,14 @@ StartTest(function(t) { isa : Ext.Panel, does : [ Joosificator ] - }); + }) var panel = new myPanel({ title : 'myPanel', width : 300, height : 300, renderTo : Ext.getBody() - }); + }) t.ok(panel.title == 'Joosified! myPanel', 'myPanel was succefully subclassed from Ext.Panel') @@ -67,9 +67,9 @@ StartTest(function(t) { ExtClass('aModule.aClass', { isa : Ext.util.Observable - }); + }) - var myOb = new aModule.aClass({}); + var myOb = new aModule.aClass({}) t.ok(myOb, 'Inheritance from Ext.util.Observable works correctly') diff --git a/t/041_extclass_promoted_from_module.t.js b/t/041_extclass_promoted_from_module.t.js new file mode 100644 index 0000000..9a20569 --- /dev/null +++ b/t/041_extclass_promoted_from_module.t.js @@ -0,0 +1,48 @@ +StartTest(function(t) { + + t.plan(6) + + // ================================================================================================================================================================================== + t.diag("Creating an Ext class, promoted from module") + + Module('My.Container', { + }) + + t.ok(My.Container, "Class 'My.Container' was created") + t.ok(My.Container.meta instanceof Joose.Namespace.Keeper, '.. and its a Module') + + Class('My.Container', { + isa : Ext.Container + }) + + t.ok(My.Container.meta instanceof JooseX.Bridge.Ext, '.. and it was successfully promoted to the class') + + + // ================================================================================================================================================================================== + t.diag("Further subclassing") + + + Class('Also.My.Container', { + + isa : My.Container + }) + + t.ok(Also.My.Container, "Class 'Also.My.Container' was created") + + + // ================================================================================================================================================================================== + t.diag("Instantiation #1") + + var cont = new My.Container() + + t.ok(cont, "'My.Container' was successfully instantiated") + + + // ================================================================================================================================================================================== + t.diag("Instantiation #2") + + var cont2 = new Also.My.Container() + + t.ok(cont2, "'Also.My.Container' was successfully instantiated") + +}) \ No newline at end of file diff --git a/t/index.html b/t/index.html index 731534c..1b8158f 100644 --- a/t/index.html +++ b/t/index.html @@ -53,7 +53,8 @@ '010_instantiation.t.js', '020_inheriting.t.js', '030_instantiation_with_traits.t.js', - '040_custom_grid_column.t.js' + '040_custom_grid_column.t.js', + '041_extclass_promoted_from_module.t.js' )