初始化和解构控制器的最佳实践 [英] Best practices for initializing and deconstructing controllers

查看:96
本文介绍了初始化和解构控制器的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我明白路由,事件侦听器和大多数交互应该由控制器进行管理,但是我的主控制器开始失控,我不知道如何最好地将我的逻辑分离成单独的控制器,而不必使它们全部运行。

解决方案

即使使用数百个控制器也可以在app启动时加载它们。这是视图渲染需要时间。



确保您的应用程序已最小化并连接,但使用sencha cmd。



在测试中,我创建了1000个简单的控制器,如下所示:

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

我们将它们连接成一个文件,并将它们加载到这样的app.js中:

  Ext.application({
name:'app',
controllers:[
'Controller0'
'Controller1'
... 1000个控制器
],
启动:function(){}
}
/ pre>

浏览器刷新(Chrome)花了一秒钟,直到最后一个控制器的init方法被调用。


When building an application what is the best way to setup your controllers?

I understand that routing, event listeners, and most all interactivity should be managed by the controllers, but my main controller is starting to grow out of control and I'm not sure how to best separate my logic into separate controllers without keeping them all "running" all the time...

解决方案

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.

这篇关于初始化和解构控制器的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆