使用Sencha Cmd的与动态加载控制器 [英] Using Sencha Cmd with dynamically loaded controllers

查看:186
本文介绍了使用Sencha Cmd的与动态加载控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用的Ext JS 4 控制器物业我的 app.js 仅包含一个应用主控制器:

I've created an application using Ext JS 4. controllers property in my app.js contains only the main controller:

Ext.application({
    name: 'MyApp',
    appFolder: 'app',

    controllers: [
        "main.App"
    ],

    loadController: function(controller) {
        var oController = this.getController(controller);
        oController.init(this);
        oController.onLaunch(this);
    }
});

MyApp.main.App 控制器负载的名字额外的控制器使用<一个href=\"http://docs.sencha.com/ext-js/4-1/#!/api/Ext.app.Application-method-getController\">getController()方法(见loadController()方法)。这些控制器动态加载和没有在我的上市的index.html 文件。

MyApp.main.App controller loads additional controllers by name using getController() approach (see loadController() method). These controllers are loaded dynamically and are not listed in my index.html file.

为了产生生产版本部署到服务器我使用煎茶Cmd的在我的应用程序文件夹发出以下命令:

In order to generate production version for deployment to server I am using Sencha Cmd by issuing the following command in my application folder:

sencha app build

工具通常和COM $ P $完成psses所有文件到一个大的全classes.js。问题是,我的动态加载控制器不包含在该文件中。

Tool finishes normally and compresses all files into one big all-classes.js. The problem is that my dynamically loaded controllers are not included in that file.

这是使动态加载的控制器(以上共100个)的正确的方式进行精缩和煎茶Cmd的处理?

Which is the correct way to make dynamically loaded controllers (over 100 in total) to be minified and processed by Sencha Cmd?

我知道,我可以在我的 app.js ,或包括使用一些文件 Ext.require ,但是我寻求在我的体型自动包括超过100多种不同的控制器,视图,模型和商店正确的做法。我相信其他用户的Ext JS,这是创建大规模应用,并以某种方式建立,我会为任何建议或只是成功案例感激,这将帮我找建设的正确方法。

I know, that I can list them in my app.js, or include in some file using Ext.require, but I am seeking for correct approach for including over than 100 different controllers, views, models and stores automatically in my build. I believe that are other users of Ext JS, which are creating large-scale applications and are building somehow and I'll be grateful for any suggestions or just success stories, which will help me to find the correct way to build.

推荐答案

我会把所有的控制器到 使用 阵列。这些应该强制工具,以保持对他们的跟踪,并将其纳入到构建。另一方面的使用的不需要的类可在定义的时间,但保证他们可用的时间的 onReady 的(其中一个是在应用程序内)嵌段(S )为被调用。

I would put all controllers into the uses array. These should force the tool to keep track on them and include them into the build. On the other hand uses does not require the class to be available at definition time but guarantee them to be available the time the onReady(one is within the application) block(s) is(are) called.

请注意,您将需要使用内部的完全限定名
  使用阵!

Note that you will need to use the fully qualified names within the uses array!

我不使用buildtool因此我无法测试它,但它应该工作。

从注释更新 例如通过 @bhovhannes 的规定

Update from the comments example provided by @bhovhannes

bhovhannes:我添加了一个code在build.xml中,收集的所有名称
  我控制器进入用途阵列时,我做的煎茶的应用程序版本。这样,我
  在开发过程中填写没什么用途的阵列,只需添加控制器
  到控制器的文件夹,因为所有的人都从动态加载

  我的应用程序

bhovhannes: I've added a code in build.xml, which collects all names of my controllers into uses array when I do sencha app build. This way I fill nothing in uses array during development, just add controllers into controller folder, because all them are loaded dynamically from my app

app.js

Ext.application({
    name: 'MyApp',
    appFolder: 'app',

    controllers: [
        "main.App"
    ],

    uses: [
        /*ant-generated-content-start*/ /*ant-generated-content-end*/
    ],

    autoCreateViewport: true,
});

的build.xml

<?xml version="1.0" encoding="utf-8"?>
<project name="MyApp" default=".help">
    <import file="${basedir}/.sencha/app/build-impl.xml"/>

    <target name="-before-build">

        <echo message="Collecting all controllers in application class property ... "/>
        <fileset id="app_controllers" dir="${app.dir}/app/controller" casesensitive="yes">
            <include name="**/*.js"/>
        </fileset>
        <pathconvert pathsep="," property="app_controller_names" refid="app_controllers" targetos="unix">
            <chainedmapper>
                <globmapper from="${app.dir}/app/*" to="${ant.project.name}/*" casesensitive="no" handledirsep="yes"/>
                <chainedmapper>
                    <regexpmapper from="^(.*)\.js$$" to='"\1"'/>
                    <filtermapper>
                        <replacestring from="/" to="."/>
                        <replacestring from="\" to="."/>
                    </filtermapper>
                </chainedmapper>
            </chainedmapper>
        </pathconvert>
        <echo message="Collected controllers: ${app_controller_names}"/>

        <echo message="Injecting into app.js ..."/>
        <replaceregexp file="${app.dir}/app/app.js"
                       match="/\*ant-generated-content-start\*/(.*)/\*ant-generated-content-end\*/"
                       replace="/*ant-generated-content-start*/ ${app_controller_names} /*ant-generated-content-end*/"
                       byline="true"
                />
    </target>

    <target name="-after-build">
        <echo message="Reverting to original app.js ..."/>
        <replaceregexp file="${app.dir}/app/app.js"
                       match="/\*ant-generated-content-start\*/(.*)/\*ant-generated-content-end\*/"
                       replace="/*ant-generated-content-start*/ /*ant-generated-content-end*/"
                       byline="true"
                />
    </target>

</project>

这篇关于使用Sencha Cmd的与动态加载控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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