senca touch 中的前后置过滤器
今天偶然看到老外提到sencha touch 中的controller,并提到了
前后置过滤器,其实感觉是利用了ror中的BeforeFilters,或者
有点象JAVA AOP中的前后置过滤器了,例子如下:
Ext.Dispatcher.on('before-dispatch', function(interaction) { if(Ext.isFunction(interaction.controller.beforeFilter)) { return interaction.controller.beforeFilter.call(); }; return true;});
Ext.Dispatcher.on('dispatch', function(interaction) { if(Ext.isFunction(interaction.controller.afterFilter)) { return interaction.controller.afterFilter.call(); }; return true;});
Ext.regApplication({ // code, code, code... loggedIn: readCookie('user_credentials') || false, requireUser: function() { if(app.loggedIn) return true; app.flash.warning = 'Please login to continue.'; Ext.redirect('login'); return false; }, flash: { notice: '', warning: '' }});
Ext.regController('accounts', { beforeFilter: app.requireUser, model: 'Account', index: function(options) { app.views.viewport.setActiveItem( app.views.accountsList, options.animation ); }, // other actions here...});