javascript – 在应用程序休息之前加载app.js

我想弄清楚如何在允许用户获取实际应用程序之前加载app.js.我试图做的是在我的所有类Ext.defines触发之前加载用户的配置文件…我想这样做的原因是因为Ext.defines实际上依赖于用户配置中的值.例如,在Ext.define中,我可以将title属性设置为从此全局用户配置var中提取.不,我不想要经历并改变所有这些属性以使用initComponent ……这可能需要相当长的时间.

相反,我想要做的是加载配置,然后让Ext.defines运行,但我需要Ext JS和我定义的一个类在其他类之前加载.这可能吗?我一直在研究Sencha Cmd的设置,但是我一直都没有成功实现这个功能.我正在玩bootstrap.manifest.exclude:“loadOrder”属性,它加载了classic.json,并没有定义我的类,但不幸的是,这也没有完全加载Ext JS,所以Ext.onReady不能使用…也不能使用我的模型加载配置.

我在下面有一个非常高级的例子(这里是Fiddle).

Ext.define('MyConfigurationModel', {
    extend: 'Ext.data.Model',
    singleton: true,

    fields: [{
        name: 'testValue',
        type: 'string'
    }],

    proxy: {
        type: 'ajax',
        url: '/configuration',
        reader: {
            type: 'json'
        }
    }
});
// Pretend this would be the class we're requiring in our Main file
Ext.define('MyApp.view.child.ClassThatUsesConfiguration', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.classThatUsesConfiguration',
    /* We get an undefined value here because MyConfigurationModel hasn't
     * actually loaded yet, so what I need is to wait until MyConfigurationModel
     * has loaded, and then I can include this class, so the define runs and
     * adds this to the prototype... and no, I don't want to put this in
     * initComponent, as that would mean I would have to update a ton of classes
     * just to accomplish this */
    title: MyConfigurationModel.get('testValue')
});
Ext.define('MyApp.view.main.MainView', {
    extend: 'Ext.Viewport',
    alias: 'widget.appMain',
    requires: [
        'MyApp.view.child.ClassThatUsesConfiguration'
    ],
    items: [{
        xtype: 'classThatUsesConfiguration'
    }]
});
Ext.define('MyApp.Application', {
    extend: 'Ext.app.Application',
    mainView: 'MyApp.view.main.MainView',
    launch: function() {
        console.log('launched');
    }
});

/* In app.js... right now, this gets called after classic.json is downloaded and
 * after our Ext.defines set up, but I basically want this to run first before
 * all of my classes run their Ext.define */
Ext.onReady(function() {
    MyConfigurationModel.load({
        callback: onl oadConfigurationModel
    })
});
function onl oadConfigurationModel(record, operation, successful) {
    if (successful) {
        Ext.application({
            name: 'MyApp',
            extend: 'MyApp.Application'
        });
    }
    else {
        // redirect to login page
    }
}

解决方法:

我将其称为“拆分构建”,因为它从Ext.app.Application类中删除了Ext.container.Viewport类的依赖关系树.所有Ext JS应用程序都有一个设置为主视图的视口.通过将所有需要的应用程序核心声明移动到viewport类,应用程序可以从应用程序类显式加载视口,并且可以将生成构建配置为输出两个单独的文件app.js和viewport.js.然后,在加载应用程序的核心之前,可以进行任意数量的操作.

// The app.js file defines the application class and loads the viewport
// file.
Ext.define('MyApp.Application', {
   extend: 'Ext.app.Application',
   requires: [
      // Ext JS
      'Ext.Loader'
   ],
   appProperty: 'application',
   name: 'MyApp',

   launch: function() {
      // Perform additional operations before loading the viewport
      // and its dependencies.
      Ext.Ajax.request({
         url: 'myapp/config',
         method: 'GET',
         success: this.myAppRequestSuccessCallback
      });
   },

   myAppRequestSuccessCallback: function(options, success, response) {
      // Save response of the request and load the viewport without
      // declaring a dependency on it.
      Ext.Loader.loadScript('classic/viewport.js');
   }
});

// The clasic/viewport.js file requires the viewport class which in turn
// requires the rest of the application.    
Ext.require('MyApp.container.Viewport', function() {
   // The viewport requires all additional classes of the application.
   MyApp.application.setMainView('MyApp.container.Viewport');
});

在生产中构建时,视口及其依赖项将不会包含在app.js中,因为它未在requires语句中声明.将以下内容添加到应用程序的build.xml文件中,以将视口及其所有依赖项编译为viewport.js.方便的是,开发和生产文件结构保持不变.

<target name="-after-js">
   <!-- The following is derived from the compile-js target in
        .sencha/app/js-impl.xml. Compile the viewport and all of its
        dependencies into viewport.js. Include in the framework
        dependencies in the framework file. -->
    <x-compile refid="${compiler.ref.id}">
        <![CDATA[
            union
              -r
              -class=${app.name}.container.Viewport
            and
            save
              viewport
            and
            intersect
              -set=viewport,allframework
            and
            include
              -set=frameworkdeps
            and
            save
              frameworkdeps
            and
            include
              -tag=Ext.cmd.derive
            and
            concat
              -remove-text-references=${build.remove.references}
              -optimize-string-references=${build.optimize.string.references}
              -remove-requirement-nodes=${build.remove.requirement.nodes}
              ${build.compression}
              -out=${build.framework.file}
              ${build.concat.options}
            and
            restore
              viewport
            and
            exclude
              -set=frameworkdeps
            and
            exclude
              -set=page
            and
            exclude
              -tag=Ext.cmd.derive,derive
            and
            concat
              -remove-text-references=${build.remove.references}
              -optimize-string-references=${build.optimize.string.references}
              -remove-requirement-nodes=${build.remove.requirement.nodes}
              ${build.compression}
              -out=${build.out.base.path}/${build.id}/viewport.js
              ${build.concat.options}
            ]]>
    </x-compile>

    <!-- Concatenate the file that sets the main view. -->
    <concat destfile="${build.out.base.path}/${build.id}/viewport.js" append="true">
       <fileset file="classic/viewport.js" />
    </concat>
</target>

<target name="-before-sass">
    <!-- The viewport is not explicitly required by the application,
         however, its SCSS dependencies need to be included. Unfortunately,
         the property required to filter the output, sass.name.filter, is
         declared as local and cannot be overridden. Use the development
         configuration instead. -->
    <property name="build.include.all.scss" value="true"/>
</target>

这个特定的实现将框架依赖性保存在他们自己的文件framework.js中.这被配置为app.json文件中输出声明的一部分.

"output": {
   ...
   "framework": {
      // Split the framework from the application.
      "enable": true
   }
}

https://docs.sencha.com/extjs/6.2.0/classic/Ext.app.Application.html#cfg-mainView
https://docs.sencha.com/extjs/6.2.0/classic/Ext.container.Viewport.html
https://docs.sencha.com/cmd/guides/advanced_cmd/cmd_build.html#advanced_cmd-_-cmd_build_-_introduction

原文地址:https://codeday.me/bug/20190611/1217198.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


我有一个问题,我不知道如何解决.我有一个Indy10HTTP服务器.我在许多应用程序中使用过Indy9和Indy10HTTP服务器,从未遇到任何问题.但现在我使用带有ExtJSjavascriptRAI框架的Indy10HTTP服务器.问题是当我提交包含非ansi字符的数据时.例如,当我提交1250代码页中的字母“č”(
我正在使用sdk1.17开发一个Firefox附加组件.它包含一个带有按钮的面板(使用ExtJs开发),我想在用户单击按钮时拍摄当前页面的屏幕截图.在GoogleChrome中,有一个API(chrome.page-capture)就在那里.但我在Firefox中找不到类似的那个.在firefox中如何从main.js完成此任务.解决方法:哦
Ext.define('PhysicsEvaluationSystemV1.view.base.BaseCharts',{extend:'Ext.panel.Panel',xtype:'basecharts',html:'<divid="main"style="width:600px;height:400px;"></div&
默认所有列(假设列3最大3列,动态显示),使用headerRowsEx中的rowspan实现双表头,第一层表头的width也必须要设置正确。使用"grid.getColumnModel().setHidden"即可实现列的隐藏,也不需要动态设置colspan。{xtype:'filtergrid',id:'grid1',cm:newExt.grid.Colu
序言   1.ExtJs是一套很好的后台框架。现在很流行的,我们要会。    2.这是我写ExtJs的第一篇,以后会写很多直到把这框架运用的炉火纯青,走火入魔。ExtJs中的命名空间      我是做.net的,这命名空间名字一样,功能也一样,都是对项目中类进行有效的管理,区分类
我在ExtJs中有这个表单.如果field1不为空,则field2不能为空.但即使听众正在解雇,它也无法正常工作.{xtype:'panel',title:'title1',items:[{xtype:'fieldset',title:'fieldA',items:[{xtype:'t
我可以将HTML元素(如文本和图像)放在面板标题中,如下所示:vargrid=newExt.grid.GridPanel({region:'center',style:'margin:10px',store:newExt.data.Store({data:myData,reader:myReader}),headerCfg:{tag:
解决方案来至于https://www.sencha.com/forum/showthread.php?471410-Bug-in-VS-Code-Plugin-since-VS-Code-Update-(-gt-1-31)在C:\Users\你的用户名\.vscode\extensions\sencha.vscode-extjs-1.0.1\out\src文件下找到Logger.js,打开它。找到代码fs.writeFile(path.join(Platfo
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>MyJSP'index.jsp'
Ext.isEmpty(str,[allowEmptyString])如果str为nullundefinedazero-lengtharrayazero-lengthstring (UnlesstheallowEmptyStringparameterissettotrue)//意思如果第二个参数设为true,则是允许str对象为空字符串该方法返回true 如果不为上面条件则返回fal
以编程方式关闭ExtJS选项卡的正确方法是什么?我需要在IE6中完成这项工作;虽然从TabPanel删除选项卡有效,但我看到IE警告:此页面包含安全和不安全的项目……当我单击选项卡上的X时,我看不到此警告.所以,当我点击X时,显然会发生一些聪明的事情.注意:当我使用tabPanel.remove(aTab,true
1.链接1.1.零散知识链接https://blog.csdn.net/zhaojianrun/article/details/701410711.2.系统教程http://extjs.org.cn/1.3.视频教程1.4.官方网站 
ExtJS有Ext.each()函数,但是有一个map()也隐藏在某个地方吗?我努力了,但没有找到任何可以填补这个角色的东西.这似乎是一件简单而微不足道的事情,一个像Ext这样庞大的JS库显然必须拥有.或者当Ext真的不包含它时,将它添加到Ext的最佳方法是什么.当然,我可以写:Ext.map=function(
我在一家使用Ext-JS的公司工作.该产品目前过度扩展了Ext-JS组件并覆盖了父功能.这使升级变得困难.我们正在保留Ext-JS,但我们正在考虑以非标准的方式使用它.似乎有两个阵营.在一个阵营中,成员们认为我们应该在Ext-JS之上编写一个抽象,以防我们决定在几年内改变框架,希望这样我们不
我想计算今天和给定日期之间的天数,并检查截至今天剩余的天数或今天过去的天数.vartoday=newDate();vardate_to_reply=newDate('2012-10-15');vartimeinmilisec=today.getTime()-date_to_reply.getTime();console.log(Math.floor(timeinmilisec/(1000*60*
我将JSON格式结果发送回保存$quot符号的客户端.由于某些未知原因,代码中断了.这是来自ext-all-debug的代码:doDecode=function(json){returneval("("+json+")");FAILSHERE},这是我的JSON,因为它离开了服务器(据我所知,我希望服务器没有花时间解码这个&quot的
我创建了Ext.Window,里面有一些Ext.form字段.但是当我调整窗口窗体时,元素仍然具有初始宽度和高度.是否需要在窗口大小调整时显式调整表单字段的大小?或者有一些选项可以自动调整表单字段的大小?示例代码:varf_1=newExt.form.TextField({fieldLabel:'Label1'});varf_2=n
我有一个简单的案例,我有一个附加商店的网格.有2个按钮.一个带有修改所选记录的处理程序.一个具有提交所选记录的处理程序.当我选择一个记录并推送编辑时–>编辑发生选择(看起来丢失)如果你调用grid.geSelectionModel().getSelection()你会看到记录仍然被选中.它只是没有这样显
我有这种ajax代码重复了很多地方.如何将其重构为单个方法,以便在成功或失败时仍允许不同的行为.Ext.Ajax.request({url:'ajax.php',params:{action:'getDate'},method:'GET',success:function(result,request){Ext.MessageBox.alert(
Ext.define('JsApp.com.Util',{  /**   *显示新建视图   *title:新建界面显示的标题   *xtype:新建界面的别名   */  showCreatingView:function(title,xtype){    this.shrink.formType='create';    this.shrink