-
31 Mar 2011 10:27 AM #1
Sencha Touch Inheritance Question
Sencha Touch Inheritance Question
Hi. We are currently building out a product prototype using Sencha Toucha and ExtJS 4.
I was under the assumption that Sencha Touch 1.1 and ExtJS 4 were going to use the same inheritance syntax as they both share the same core code. However, this doesn't seem to be the case. Sencha Touch 1.1's inheritance syntax uses ExtJS 3.x's Ext.extend(...) and not ExtJS4's Ext.define(...).
Sencha Touch Inheritance Syntax (much like ExtJS 3.x)
ExtJS4 Inheritance SyntaxCode:myPanel = Ext.extend(Ext.Panel, {...}); Ext.reg('myPanel', myPanel);
ExtJS 4's Ext.define(...) design is much more intuitive and elegant for defining classes and sub classes, and we would much rather use this method upfront vs. having to change our code later on.Code:Ext.define('MyPanel', {extend: 'Panel',...});
Does Sencha Touch plan on using Ext.define(...) to define classes in the near future?
If so when?
If not, why not?
-
6 Apr 2011 3:24 PM #2
Excuse my bumping, but I'd like some type of answer or opinion from anyone with the same concern.
-
25 May 2011 3:07 PM #3
Is there an answer to this?
-
12 Jul 2011 12:36 PM #4
Also interested...
Also interested...
[bump]
We're also interested and would appreciate a response.
-
12 Jul 2011 2:02 PM #5
Some info
Some info
I asked a contact I have access to at sencha about this and he indicated it should be resolved in Sencha Touch 2 coming out this fall some time. But, I don't really have anything definitive I can point to that promises that. I sure hope they fix it. It's a really big deal for me and I imagine many others trying to share come code between mobile and desktop code.
-
12 Jul 2011 2:12 PM #6
-
12 Jul 2011 2:15 PM #7
My understanding is that touch 1 uses the inheritance model from EXTJS 3 (or very close to that) and does not support ext.define that is part of EXTJS 4 until version 2. That is what I asked about.
It would be really nice if someone from sencha would chime in and provide an actual answer to this.
-
12 Jul 2011 7:32 PM #8
That's what I thought. Have you been able to get inheritance to work using the EXTJS 3 inheritance model? I've been looking at the API and can't seem to get my sub-class to inherit properly from its parent. Every time I call ...
... I get an error that says 'myBaseClass' is undefined. Yet, I've defined the class above it.Code:Ext.reg('myBaseClass', myBaseClass);
-
19 Nov 2011 12:59 PM #9
Workaround for define method and alias registration
Workaround for define method and alias registration
You can override the Ext.define method and work with the extend and reg method to accomplish this. Simply put the following code in before any defines:
Ext.define = Ext.define ? Ext.define :
function(name, config) {
var extendObj = {};
Ext.each(config.extend.split(/\./), function(item, index) {
extendObj = index === 0 ? window[item] : extendObj[item];
});
var newObj = {};
Ext.each(name.split(/\./), function(item, index){
newObj = index === 0 ? window[item] = {} : newObj[item] = {};
});
newObj = Ext.extend(extendObj, config);
var alias = config.alias;
if(alias) {
Ext.reg(alias.replace(/^(widget\.)/,''), newObj);
}
}
Then calling with:
(function() {
Ext.define('MySettings', {
extend: 'Ext.Panel',
alias: 'widget.mysettings',
html: 'Settings Panel'
});
})();
will be the equivalent of:
MySettings = Ext.extend(Ext.Panel,{
extend: 'Ext.Panel',
alias: 'widget.mysettings',
html: 'Settings Panel'
});
Ext.reg('mysettings', MySettings);
This provides a consistent behavior for extending an object using Ext.define. Not it is not handling a case with no extension. However, that should be pretty straight forward in that you would simply check for extension and if it doesn't exist don't call the extend method. Have not worked this out yet.
-
19 Nov 2011 1:07 PM #10
Update for workaround to handle not extending a base class
Update for workaround to handle not extending a base class
Ext.define = Ext.define ? Ext.define :
function(name, config) {
var newObj;
Ext.each(name.split(/\./), function(item, index){
newObj = index === 0 ? window[item] = {} : newObj[item] = {};
});
var extendName = config.extend;
var extendObj;
if(extendName) {
Ext.each(config.extend.split(/\./), function(item, index) {
extendObj = index === 0 ? window[item] : extendObj[item];
});
newObj = Ext.extend(extendObj, config);
}
var alias = config.alias;
if(alias) {
Ext.reg(alias.replace(/^(widget\.)/,''), newObj);
}
}
Similar Threads
-
Is Sencha working on native wrappers to package Sencha Touch apps for app stores?
By olin in forum Sencha Touch 1.x: DiscussionReplies: 10Last Post: 20 Jan 2012, 10:10 AM -
Newbie Question on Sencha touch framework
By mAuo in forum Sencha Touch 1.x: DiscussionReplies: 0Last Post: 2 Feb 2011, 11:31 AM -
Newbie Question to start Sencha Touch
By sideeque in forum Sencha Touch 1.x: DiscussionReplies: 4Last Post: 3 Dec 2010, 6:52 AM -
Sencha Touch Contest question
By qooleot in forum Sencha Touch 1.x: App ContestReplies: 2Last Post: 12 Oct 2010, 11:32 AM -
Question about inheritance
By mankz in forum Community DiscussionReplies: 17Last Post: 21 Oct 2009, 7:14 AM


Reply With Quote
