PDA

View Full Version : Possible Race Condition on Simulator/Device



TheStreet
26 Sep 2012, 9:43 AM
I am running some logic in the method posted below that works fine in a desktop browser but returns an undefined value in the device/simulator. I'm thinking this is some kind of race condition, but maybe someone can shine a light as to why I am seeing this inconsistent behavior. All of this is popping off when someone clicks on a dataview item.



onArticleSelect: function(view, record, eOpts) {
var store = view.getStore(),
first = store.first(),
recordId = record.getId(),
storeId = store.getStoreId().toString(),
sectionRaw = storeId.replace(/([A-Z])/g, ' $1'),
sectionTitle = sectionRaw.replace(/^\s+|\s+$/g, ""),
articleCarousel = this.getArticleCarousel(),
articlePanel = this.getArticlePanel(),
article = this.getArticle(),
//articleId = articleCarousel.getActiveItem().getId(),
dashboardPanel = this.getDashboardPanel(),
dashboard = this.getDashboard(),
splash = this.getSplash(),
dashboardCarousel = this.getDashboardCarousel(),
storeItems = storeId+'Items',
articleSection = this.getArticleSection(),
viewIdReplace = view.getId().replace(/Feed$/g, ''),
items = [];


view.deselectAll();


if(articleCarousel.items.length !== 0) {
console.log(articleCarousel.items.length); //returns length properly in desktop browser and simulator/device
console.log(articleCarousel.getActiveItem().sid); //returns sid property in desktop browser but returns undefined on simulator/device
console.log(articleCarousel.getActiveItem().id); //returns id property in desktop browser and simulator/device
console.log(viewIdReplace); //returns properly on both desktop browser and device
}



if(articleCarousel.items.length === 0) {
console.log('initializing all articles...');
console.log('store: ', store);
//articleCarousel.setMasked(true);
store.each(function(rec, offset) {
var recId = rec.data.articleId.toString(),
storeName = store.getStoreId();


items.push(Ext.create('TheStreet.view.Article', {
sid: storeName,
record: rec,
id: recId
}));
});
articleCarousel.setItems(items);
//articleCarousel.setMasked(false);
} else if ((articleCarousel.items.length !== 0) && (articleCarousel.getActiveItem().sid !== viewIdReplace)) {
console.log('replacing all articles...');
articleCarousel.removeAll();
//articleCarousel.setMasked(true);
store.each(function(rec, offset) {
var recId = rec.data.articleId.toString(),
storeName = store.getStoreId();

items.push(Ext.create('TheStreet.view.Article', {
sid: storeName,
record: rec,
id: recId
}));
});
articleCarousel.setItems(items);
//articleCarousel.setMasked(false);
}




articleSection.setHtml('<h4>News :: '+sectionTitle+'</h4>');
dashboardPanel.hide(true);
articlePanel.show(true);
articleCarousel.setActiveItem(Ext.getCmp(record.data.articleId.toString()));
}

TheStreet
27 Sep 2012, 7:36 AM
As an update I thought it might help someone to know that this is only an issue after the app has been built with SDK Tools and I was able to reproduce this behavior in the desktop browser when running the production build of my app. Any ideas why an object property would be defined running the app with the Loader in a test environment and not after it's been built?

TheStreet
28 Sep 2012, 6:07 AM
My bad dude. iOS 5.1 and 6.0 simulator and iOS device. Sencha Touch 2.0.1. PhoneGap 2.1.

TheStreet
1 Oct 2012, 11:04 AM
Anyone? I'm going to submit this as a bug if no one has any idea what I could possibly be doing wrong.