Q"&之间的差异QUOT;和" Q"在angularjs和requirejs [英] Difference between "Q" and "q" in angularjs and requirejs

查看:170
本文介绍了Q"&之间的差异QUOT;和" Q"在angularjs和requirejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造建立在AngularJS,微风和RequireJS单页的应用程序。在建立与AMD与requirejs角和微风的工作,我遇到了微风对Q依赖的问题。如果Q配置规则是小写的,即使没有明确的出口在垫片,给人清风这个错误:

 未捕获的错误:无法初始化Q.见https://github.com/kriskowal/q
HTTP://本地主机:1498 /脚本/共享/ breeze.jsbreeze.js:1`

当需要配置的变化,从Q为Q的所有引用(即使没有出口)中,code ++工程。有谁知道为什么发生这种情况?

这是工作的要求配置:

  require.config({
    的baseUrl:../Scripts',
    路径:{
        角:共享/角',
        引导:共享/ UI自举,
        下拉菜单:应用程序/指令/下拉菜单',
        employeeApp:应用程序/模块/ employeeModule',
        控制器:应用程序/控制器的,
        日期:应用程序/指令/日期,
        jQuery的:共享/ jQuery的,
        问:'共享/ Q',
        清风:共享/清风,
        配置:应用程序/服务/配置,
        型号:应用程序/服务/模型',
        DataService的:应用程序/服务/ DataService的,
        expenseInfo:应用程序/服务/ expenseInfo
    },
    垫片:{
        '角':{'出口':'角'},
        引导:{DEPS:['角']},
        //'Q':{'出口':'Q'},
        清风:{DEPS:['Q','jQuery的'],'出口':'清风'}
    },
    优先级:['角','引导','下拉菜单','jQuery的',
                'Q','清风','employeeSearch','日期']
});


解决方案

技术原因是海风明确查找Q。要查找所有微风需要在源搜索requireLib'(而不是整个单词)。

微风总是寻找全球第一,且由于Q的全球是'Q'这是什么微风搜索

更多背景:(是的,我最近一直遇到一些微风+ RequireJS疼痛)

幸运的是你可以改变的需要路径。然而,随着淘汰赛+迪朗达尔这不起作用。微风需要'高',但迪朗达尔需要'淘汰赛'。解决方法是使用RequireJS图:

 图:{
    //由迪朗达尔,柯用基因敲除使用微风 - >柯随时要求,替代淘汰赛
    *:{こ':'淘汰赛'}
}

微风确实有一些问题,它RequireJS的依赖,因为它没有predefine它的依赖(不依赖于它的定义调用上市)。这可能是因为它的一些依赖是可配置的(你不想淘汰赛,但我这样做)。这就是为什么你需要的垫片,确保微风请求他们之前,他们被加载。

jQuery有不寻常的AMD行为。大多数图书馆查找AMD库它们运行时。如果他们发现一个AMD库(例如RequireJS)他们自己加载到其中(如定义(...)),并跳过加载自己作为一个全球性的。 jQuery不会的两个如果它可以(有充分理由)。这意味着微风总是能看到并加载了全球jQuery的,所以没必要创建微风的jQuery的地图来RequireJS的jQuery的

BTW即使没有出口是无关紧要的。在垫片出口属性用于:一旦加载,使用全局的'清风'作为模块值。没有点作为微风看到RequireJS,本身加载到它,而不是全球的,而忽略垫片出口。

I am creating a single page app built on AngularJS, Breeze, and RequireJS. In setting up AMD with requirejs to work with Angular and Breeze, I encountered an issue with Breeze's dependency on "q". If the configuration rule for "q" is lowercase, even if there is no explicit export in the "shim", Breeze gives this error:

Uncaught Error: Unable to initialize Q. See https://github.com/kriskowal/q
"http://localhost:1498/Scripts/shared/breeze.js"breeze.js:1`

When require config changes all references from "q" to "Q" (even without the export), the code works. Does anyone know why this is happening?

This is the working require config:

require.config({
    baseUrl: '../Scripts',
    paths: {
        angular: 'shared/angular',
        bootstrap: 'shared/ui-bootstrap',
        dropdowns: 'app/directives/dropdowns',
        employeeApp: 'app/modules/employeeModule',
        controllers: 'app/controllers',
        dates: 'app/directives/dates',
        jquery: 'shared/jquery',
        Q: 'shared/q',
        breeze: 'shared/breeze',
        config: 'app/services/config',
        model: 'app/services/model',
        dataservice: 'app/services/dataservice',
        expenseInfo: 'app/services/expenseInfo'
    },
    shim: {
        'angular': { 'exports': 'angular' },
        'bootstrap': { deps: ['angular'] },
        //'q': { 'exports': 'q' },
        'breeze': { deps: ['Q', 'jquery'], 'exports': 'breeze' }
    },
    priority: [ 'angular', 'bootstrap', 'dropdowns', 'jquery',
                'Q', 'breeze', 'employeeSearch', 'dates' ]
});

解决方案

Technical reason is that breeze explicitly looks for "Q". To find all the breeze requires search for 'requireLib' (not whole word) in the source.

Breeze always looks for global first, and since q's global is 'Q' that's what breeze searches for

More background: (yes I've been experiencing some Breeze + RequireJS pain lately)

Fortunately you can just change the require path. However with knockout + Durandal this does not work. Breeze requires 'ko', but Durandal requires 'knockout'. The workaround is to use RequireJS map:

map: {
    //knockout used by Durandal, ko used by breeze  --> anytime ko is requested, substitute knockout
    '*': { 'ko': 'knockout' }
}

Breeze does have some problems with its RequireJS dependencies, because it does not predefine its dependencies (no dependencies listed in its define call). This is probably because some of its dependencies are configurable (you don't want knockout, but I do). That's why you need the shim to ensure they are loaded before Breeze requests them.

jQuery has unusual AMD behaviour. Most libraries look for AMD libraries when they run. If they find a AMD library (e.g. RequireJS) they load themselves into it (e.g. define( ... )), and skip loading themselves as a global. jQuery does both if it can (for good reasons). This means Breeze always sees and loads the global jQuery, so no need to create a map from Breeze's 'jQuery' to RequireJS's 'jquery'.

BTW "even without the export" is irrelevant. The export property in the shim is used to: Once loaded, use the global 'breeze' as the module value. No point as breeze sees RequireJS, loads itself into it instead of the global, and shim ignores the export.

这篇关于Q"&之间的差异QUOT;和" Q"在angularjs和requirejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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