2

在构建应用程序时,设置控制器的最佳方式是什么?

我知道路由、事件侦听器和大多数交互性都应该由控制器管理,但是我的主控制器开始失控,我不确定如何最好地将我的逻辑分成单独的控制器而不保留它们“一直在奔跑……

4

2 回答 2

2

It's okay to have them all loaded at app start-up, even with hundreds thousands of controllers. It's the view rendering that takes time.

Make sure your app is minimized and concatenated though, using sencha cmd.

In a test, I created 1000 simple controllers, like this:

Ext.define('app.controller.ControllerN', {
    extend: 'Ext.app.Controller',
    init: function(application) {    
        this.control({
            buttonN1: {
                click: function() {
                }
            },
            buttonN2: {
                click:function(){}
            }, 
            ... 20 listeners
        });
    }
});

I concatenated them into one file, and loaded them in app.js like this:

Ext.application({
    name:'app',
    controllers:[
      'Controller0',
      'Controller1'
       ... 1000 controllers
    ],
    launch:function(){}
}

It took ONE second from browser refresh (Chrome) until the last controller's init method was called.

于 2013-05-11T01:55:14.997 回答
1

我有类似的问题,所以我根据它将支持的业务功能划分控制器,例如 userController 执行所有与用户相关的操作,如登录、注销、更新等,而 cartController 执行与购物车相关的所有操作,如添加到购物车、应用优惠券,支付等。由于单个视图可以具有与应用程序的不同区域相关的许多功能,因此您可以在多个控制器中向该视图添加参考,并仅监听相应控制器中的相关事件。

于 2013-05-10T06:56:59.753 回答