Skip to content

Commit

Permalink
- added test for ext classes promoted from modules
Browse files Browse the repository at this point in the history
  • Loading branch information
canonic-epicure committed Nov 11, 2009
1 parent 6207d02 commit eb9b270
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 82 deletions.
149 changes: 77 additions & 72 deletions 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 <a href="http://code.google.com/p/joose-js/">Joose</a> Classes.
* After including this package you can derive new classes in standard way
<pre>
Ext.myWindow = Joose.Bridge.Ext.my.extend(Ext.Window, {
initComponent : function (){
Ext.myWindow.superclass.initComponent.call(this)
this.width = 800
}
})
</pre>
or in the native Joose way:
<pre>
ExtClass('Ext.myWindow', {
isa : Ext.Window,
after : {
initComponent : function (){
this.width = 800
}
}
})
</pre>
in both cases you can use any of Joose features with your classes, for example - apply Roles, either statically, during creation:
<pre>
Role('Joosificator', {
before : {
render : function(){
this.title = "Joosified: " + this.title
}
}
})
ExtClass('Ext.myWindow', {
isa : Ext.Window,
does : [Joosificator],
...
})
</pre>
or dynamically, at run-time:
<pre>
Ext.myWindow.meta.extend({
does : [Joosificator]
})
</pre>
* <br/>See the <a href="http://extjs.com/forum/showthread.php?t=55968">forum thread</a> for additional details and <a href="http://code.google.com/p/joose-js/">Joose</a> home page for complete manual on Joose.
* @version 0.1
* @author <a href="http://extjs.com/forum/member.php?u=36826">SamuraiJack</a>
* @license <a href="http://www.gnu.org/licenses/lgpl.html">LGPL 3.0</a>
*/

Class('JooseX.Bridge.Ext', {

meta : Joose.Meta.Class,
Expand All @@ -66,14 +8,15 @@ Class('JooseX.Bridge.Ext', {
defaultConstructor : function () {
var jooseConstructor = this.SUPER()

this.adaptConstructor(jooseConstructor)

return function () {

var self = this

if (!this.__JOOSE_INIT_DONE__) {
this.__JOOSE_INIT_DONE__ = true

jooseConstructor.meta = this.meta
self = jooseConstructor.apply(this, arguments) || self
}

Expand All @@ -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
Expand All @@ -125,15 +66,6 @@ Class('JooseX.Bridge.Ext', {

methods : {

/**
* Improved <b>Ext.ux.extend</b>. Provides exactly the same interface as standard <b>Ext.ux.extend</b> plus it converts both classes into Joose Classes..<br>
* @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'){
Expand Down Expand Up @@ -168,6 +100,21 @@ Class('JooseX.Bridge.Ext', {
})


Joose.Namespace.Manager.my.register('ExtClass', JooseX.Bridge.Ext)



/**
* Improved <b>Ext.ux.extend</b>. Provides exactly the same interface as standard <b>Ext.ux.extend</b> plus it converts both classes into Joose Classes..<br>
* @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 <a href="http://code.google.com/p/joose-js/wiki/BuildingAClass">this page</a> for examples. This function is copied into global scope and is using for creation of new classes.
Expand All @@ -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)


/**
* @class
* @name Joose.Bridge.Ext
* @desc This package provides fully backward-compatible drop-in replacement for Ext.extend, which turns standard Ext classes into <a href="http://code.google.com/p/joose-js/">Joose</a> Classes.
* After including this package you can derive new classes in standard way
<pre>
Ext.myWindow = Joose.Bridge.Ext.my.extend(Ext.Window, {
initComponent : function (){
Ext.myWindow.superclass.initComponent.call(this)
this.width = 800
}
})
</pre>
or in the native Joose way:
<pre>
ExtClass('Ext.myWindow', {
isa : Ext.Window,
after : {
initComponent : function (){
this.width = 800
}
}
})
</pre>
in both cases you can use any of Joose features with your classes, for example - apply Roles, either statically, during creation:
<pre>
Role('Joosificator', {
before : {
render : function(){
this.title = "Joosified: " + this.title
}
}
})
ExtClass('Ext.myWindow', {
isa : Ext.Window,
does : [Joosificator],
...
})
</pre>
or dynamically, at run-time:
<pre>
Ext.myWindow.meta.extend({
does : [Joosificator]
})
</pre>
* <br/>See the <a href="http://extjs.com/forum/showthread.php?t=55968">forum thread</a> for additional details and <a href="http://code.google.com/p/joose-js/">Joose</a> home page for complete manual on Joose.
* @version 0.1
* @author <a href="http://extjs.com/forum/member.php?u=36826">SamuraiJack</a>
* @license <a href="http://www.gnu.org/licenses/lgpl.html">LGPL 3.0</a>
*/
18 changes: 9 additions & 9 deletions t/010_instantiation.t.js
Expand Up @@ -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')

Expand All @@ -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')

Expand All @@ -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')

Expand Down
48 changes: 48 additions & 0 deletions 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")

})
3 changes: 2 additions & 1 deletion t/index.html
Expand Up @@ -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'
)
</script>
</body>
Expand Down

0 comments on commit eb9b270

Please sign in to comment.