Last active
August 29, 2015 14:05
-
-
Save ChezCrawford/5f3aa05632c6028d141f to your computer and use it in GitHub Desktop.
Sencha Touch Listeners in a Static Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define('SenchaSandbox.util.NotificationManager', { | |
alternateClassName: 'NotificationManager', | |
requires: ['Ext.MessageBox'], | |
mixins: ['Ext.mixin.Observable'], | |
singleton: true, | |
constructor: function(config) { | |
this.initConfig(config); | |
// Works correctly for a singleton class | |
this.addListener({ | |
initEvent: function() { | |
Ext.Msg.alert('Test Event', 'The initEvent added via the constructor has been fired.'); | |
} | |
}); | |
}, | |
// Does not seem to work for a singleton | |
listeners: { | |
configEvent: function() { | |
Ext.Msg.alert('Read Event', 'The configEvent added by the listeners config has been fired.'); | |
} | |
} | |
}); | |
Ext.define('SenchaSandbox.view.Main', { | |
extend: 'Ext.tab.Panel', | |
xtype: 'main', | |
requires: ['Ext.TitleBar', 'Ext.Button'], | |
config: { | |
tabBarPosition: 'bottom', | |
items: [{ | |
title: 'Welcome', | |
iconCls: 'home', | |
styleHtmlContent: true, | |
scrollable: true, | |
items: [ | |
{ | |
docked: 'top', | |
xtype: 'titlebar', | |
title: 'Single Class Event Tests' | |
}, | |
{ | |
xtype: 'button', | |
text: 'Fire initEvent', | |
listeners: { | |
tap: function () { | |
NotificationManager.fireEvent('initEvent'); | |
} | |
} | |
}, | |
{ | |
xtype: 'button', | |
text: 'Fire configEvent', | |
listeners: { | |
tap: function () { | |
NotificationManager.fireEvent('configEvent'); | |
} | |
} | |
} | |
], | |
html: "Hello World" | |
}] | |
} | |
}); | |
Ext.application({ | |
name: 'SenchaSandbox', | |
requires: ['Ext.MessageBox', 'SenchaSandbox.util.NotificationManager'], | |
views: ['SenchaSandbox.view.Main'], | |
launch: function() { | |
// Initialize the main view | |
Ext.Viewport.add(Ext.create('SenchaSandbox.view.Main')); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment