PDA

View Full Version : [CLOSED][DUP][4.0.1] Re-defining class results in error



Stanback
19 May 2011, 4:27 PM
The following is a quick and dirty test case showing how re-defining the model results in an error. To reproduce it, close the window twice.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Windows Example</title>
<link rel="stylesheet" type="text/css" href="http://dev.sencha.com/deploy/ext-4.0.1/examples/window/../../resources/css/ext-all.css" />
<script type="text/javascript" src="http://dev.sencha.com/deploy/ext-4.0.1/examples/window/../../bootstrap.js"></script>
<script type="text/javascript">
Ext.require([
'Ext.window.Window',
'Ext.tab.*',
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.state.*'
]);

Ext.onReady(function() {
var myData = [
['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],
['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],
['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am']
];

function showWindow() {
Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: [
'company',
'price',
'change',
'pctChange',
'lastChange'
]
});

var store = Ext.create('Ext.data.ArrayStore', {
model: 'MyModel',
data: myData
});

var win = Ext.create('Ext.Window', {
title: 'Close Bug',
layout: 'fit',
width: 865,
height: 565,
items: {
xtype: 'gridpanel',
loadMask: true,
stripeRows: true,
store: store,
columns: [
{
text : 'Company',
flex : 1,
sortable : false,
dataIndex: 'company'
},
{
text : 'Price',
width : 75,
sortable : true,
dataIndex: 'price'
},
{
text : 'Change',
width : 75,
sortable : true,
dataIndex: 'change'
},
{
text : '% Change',
width : 75,
sortable : true,
dataIndex: 'pctChange'
},
{
text : 'Last Updated',
width : 85,
sortable : true,
dataIndex: 'lastChange'
}
]
}
}).show().center();

win.on('close', function() {
setTimeout(showWindow, 500);
});
}

showWindow();
});
</script>
</head>
<body>
</body>
</html>The above is just a test case - what I'm actually doing is defining a model used by a grid panel within the extended grid panel class. When instantiating the class, the model always gets re-defined. I'm not sure whether this is a bug or not but it seems like inconsistent behavior.

Is there a best-practice for defining models or other classes in a web app? Should I group all models into a single file, define each model in its own file, put the model inside of it's related class file but outside the scope of the class (so the file is defining two classes), check for the existence of the class before defining it (which I assumed Ext.define would do for me, or at least throw an exception), or forget model altogether and just define fields: [] on the store?

mniland
19 May 2011, 4:38 PM
I'm experiencing the same issue in Chrome, Firefox 3 and Internet Explorer 9, but not Firefox 4 in Windows 7.

evant
19 May 2011, 9:27 PM
http://www.sencha.com/forum/showthread.php?131603-4.0.0-Defining-a-model-twice
http://www.sencha.com/forum/showthread.php?131502-Ext.define-should-raise-an-Error-when-extending-an-unknown-class