BreezeJS RequireJS支持不稳定(淘汰示例) [英] BreezeJS RequireJS support unstable (knockout example)

查看:119
本文介绍了BreezeJS RequireJS支持不稳定(淘汰示例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图用微风和requirejs编译我的项目进行生产时,我遇到了多个问题。展开此操作后,我尝试从淘汰RequireJS示例重新开始。
安装了MVS2013Pro之后,我能够运行该项目,但并非没有问题:


  1. window.breeze是定义,因此已泄漏到全局范围(此
    不应在RequireJS中发生)


  2. 命中F5刷新会因

    $而崩溃b
    $ b

    • 未捕获错误:找不到微风和/或Q(微风保存队列)

    • 未捕获类型错误:未定义函数(微风数据服务)


由于这些错误,我什至没有尝试建立我笨拙的requirejs(r优化程序)任务。



注意:我不是在寻找淘汰方案,我的堆栈实际上是:MongoDataService + Breeze + SaveQueueing + RequireJS + AngularJS + Socket.IO + Cordova

解决方案

window.breeze


您是对的, breeze 潜入 breeze.debug.js 底部的浏览器:

 如果(global.window){
global.window.breeze =微风;
}

我们不知道为什么要将其放入代码库中。没有人记得。

我在初步测试中将其注释掉了,这似乎可以解决问题。 window.breeze Todo-KO-Require 示例中变为未定义;在不使用 require.js 的示例中,它仍然(正确地)定义了。


我们认为这对任何人都不会有重大改变...并且补救措施也很简单:在应用程序的顶部自己定义。


除非我们发现有其他理由,否则我们可能会在下一个版本中删除这些行。

p>

F5失败了吗?


我根本无法复制它。我怀疑您是在将编写 breeze.savequeuing.js 的Angular应用程序的努力与误认为微风在全局命名空间中混淆了。


为什么我觉得呢?因为您描述的错误是在Angular应用中尝试使用 breeze.savequeuing.js 时出现的,而该应用在v.1.0的注释(第14行)中被明确禁止。 4:


取决于Breeze(已打补丁)和Q.js(尚未在Angular中使用...)


毫无疑问,您从所需的库中省略了 Q.js ,所有内容都从那里转移到了蛋ust。


我个人对 用户更改时保存任何内容过敏用户体验,因此有必要节省排队。我几乎对不起我写了它。


显然依赖于 Q.js 的原因是它不适用于所编写的Angular应用程序。现在使它变得可用于Angular实际上很容易,因为我们最近(安静地)使Breeze用于承诺的组件易于访问

  breeze.Q //返回Breeze 

当前使用的promise组件,因此,您可以将对行104的Q的引用更改为

  var deferredSave = breeze.Q.defer(); 

这在使用微风 v.1.4.14 及更高版本时应该可以使用。我尚未完全测试它。


此更改(或类似的内容)可能会进入 breeze.savequeuing.js v.1.1.0版中 (因为我刚刚推送了非发行版)。


As I'm trying to compile my project with breeze and requirejs for production, I'm running into multiple issues. Unrolling this, I tried starting fresh with the Knockout RequireJS example. After I installed MVS2013Pro I was able to run the project, but not without issues:

  1. window.breeze is defined so it has been leaked to global scope (this should not happen with RequireJS)

  2. Hitting F5 Refresh will crash with

    • Uncaught Error: Can't find breeze and/or Q (breeze savequeuing)
    • Uncaught TypeError: undefined is not a function (breeze dataservice)

With these errors I'm not even trying to establish my grunt requirejs (r optimizer) task. As these are the root of my problems.

Note: I'm not searching for a knockout solution, my stack actually is: MongoDataService+Breeze+SaveQueueing+RequireJS+AngularJS+Socket.IO+Cordova

解决方案

window.breeze

You're right that breeze sneaks back into the browser way down at the bottom of breeze.debug.js:

if (global.window) {
    global.window.breeze = breeze;
}

We don't know why we put that in the code base. No one remembers. Coming at the end as it does, it clearly isn't needed by Breeze itself.

I commented it out in preliminary testing and that seems to do the trick. The window.breeze becomes undefined in the Todo-KO-Require sample; it remains defined (properly) in samples that do not use require.js.

We don't think this would be a breaking change for anyone ... and the remedy is simple enough: define it yourself at the top of your app.

We'll probably remove these lines for the next release unless we discover a reason to do otherwise.

F5 fail?

I can't repro this at all. I suspect your are conflating your discovery that breeze is inadvertently in the global namespace with your efforts to write an Angular app that uses breeze.savequeuing.js.

Why do I think this? Because the error you describe arises when trying to use breeze.savequeuing.js in an Angular app which is explicitly disallowed in the comments (line #14) of v.1.0.4:

Depends on Breeze (which it patches) and Q.js (not for use in Angular ... yet)

You no doubt omitted Q.js from your required libraries and it all goes to custard from there.

I'm personally allergic to the "save-when-user-changes-anything" user experience that made save queuing necessary. I'm almost sorry I wrote it. But there it is.

The apparently dependence on Q.js is the reason it isn't available for Angular apps as written. It's actually pretty easy to make it Angular-ready now because we recently (quietly) made accessible the component that Breeze is using for promises

breeze.Q // returns the promises component currently used by Breeze

Therefore, you could change the one reference to Q on line #104 to

    var deferredSave = breeze.Q.defer();

This should work when using breeze v.1.4.14 and later. I haven't fully tested it yet.

This change (or something like it) likely will find its way into breeze.savequeuing.js v.1.1.0 (as I just pushed a non-release version of that).

这篇关于BreezeJS RequireJS支持不稳定(淘汰示例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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