将 Bluebird 添加到 Aurelia 应用程序会引入错误
Adding Bluebird to Aurelia app introduces bugs
我今天在 IE Edge 中试用了我的 Aurelia 应用程序,加载首页大约需要 20 秒。切换页面也会花费不合理的时间,因此我 google aurelia 边缘性能,发现添加 Bluebird JS 库有助于提高 所有 浏览器的性能。除了在 system.js
.
之前添加它的说明外,我找不到确切 如何 添加此库的示例
所以现在不是这个:
<script src="/jspm_packages/system.js"></script>
<script src="/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
我有这个:
<script src="//cdn.jsdelivr.net/bluebird/3.4.1/bluebird.min.js"></script>
<script src="/jspm_packages/system.js"></script>
<script src="/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
整个应用程序像以前一样工作,我基本上尝试了每个视图及其功能,除了 一个 东西;
在每条路线成功时,我都会向 <html>
元素添加一个 id(出于样式目的)以匹配当前查看的路线。所以在主页上我会有 <html id="home-page">
和在登录页面上 <html id="login-page">
.
这是在 app.js
(根元素)的 attached()
方法中完成的,如下所示:
this.eventAggregator.subscribe('router:navigation:success', event => {
if (event.instruction && event.instruction.router && event.instruction.router.currentInstruction && event.instruction.router.currentInstruction.config) {
document.documentElement.id = event.instruction.router.currentInstruction.config.name + '-page';
}
});
出于某种原因,在第一个页面加载时,并且仅在第一个页面加载时,此事件永远不会触发。转到另一条路线工作正常,回到第一次从未触发事件的路线工作正常。只有在第一页加载时它才不会触发。
如果我删除 bluebird,它会再次开始工作。
有人任何知道是什么原因造成的吗?正如我所说,我所做的唯一更改是将 bluebird script
元素添加到 index.html
。我在实际的应用程序代码中根本没有做任何更改。
所以我解决这个问题的方法是,我现在在加载时以及在 router:navigation:success
事件中检查当前页面。这有点烦人,这件事停止与 Bluebird 合作,但与此同时,该网站现在可以在 IEdge 中使用,所以...
// Give <html> an ID representing the current page
if (this.router.currentInstruction) {
document.documentElement.id = this.router.currentInstruction.config.name + '-page';
}
// Listen to route navigation changes and change the ID
this.navigationSubscription = this.eventAggregator.subscribe('router:navigation:success', event => {
if (event.instruction && event.instruction.router && event.instruction.router.currentInstruction && event.instruction.router.currentInstruction.config) {
document.documentElement.id = event.instruction.router.currentInstruction.config.name + '-page';
}
});
我今天在 IE Edge 中试用了我的 Aurelia 应用程序,加载首页大约需要 20 秒。切换页面也会花费不合理的时间,因此我 google aurelia 边缘性能,发现添加 Bluebird JS 库有助于提高 所有 浏览器的性能。除了在 system.js
.
所以现在不是这个:
<script src="/jspm_packages/system.js"></script>
<script src="/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
我有这个:
<script src="//cdn.jsdelivr.net/bluebird/3.4.1/bluebird.min.js"></script>
<script src="/jspm_packages/system.js"></script>
<script src="/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
整个应用程序像以前一样工作,我基本上尝试了每个视图及其功能,除了 一个 东西;
在每条路线成功时,我都会向 <html>
元素添加一个 id(出于样式目的)以匹配当前查看的路线。所以在主页上我会有 <html id="home-page">
和在登录页面上 <html id="login-page">
.
这是在 app.js
(根元素)的 attached()
方法中完成的,如下所示:
this.eventAggregator.subscribe('router:navigation:success', event => {
if (event.instruction && event.instruction.router && event.instruction.router.currentInstruction && event.instruction.router.currentInstruction.config) {
document.documentElement.id = event.instruction.router.currentInstruction.config.name + '-page';
}
});
出于某种原因,在第一个页面加载时,并且仅在第一个页面加载时,此事件永远不会触发。转到另一条路线工作正常,回到第一次从未触发事件的路线工作正常。只有在第一页加载时它才不会触发。
如果我删除 bluebird,它会再次开始工作。
有人任何知道是什么原因造成的吗?正如我所说,我所做的唯一更改是将 bluebird script
元素添加到 index.html
。我在实际的应用程序代码中根本没有做任何更改。
所以我解决这个问题的方法是,我现在在加载时以及在 router:navigation:success
事件中检查当前页面。这有点烦人,这件事停止与 Bluebird 合作,但与此同时,该网站现在可以在 IEdge 中使用,所以...
// Give <html> an ID representing the current page
if (this.router.currentInstruction) {
document.documentElement.id = this.router.currentInstruction.config.name + '-page';
}
// Listen to route navigation changes and change the ID
this.navigationSubscription = this.eventAggregator.subscribe('router:navigation:success', event => {
if (event.instruction && event.instruction.router && event.instruction.router.currentInstruction && event.instruction.router.currentInstruction.config) {
document.documentElement.id = event.instruction.router.currentInstruction.config.name + '-page';
}
});