Ember CLI Hook /事件错误 [英] Ember CLI Hook/Event Error
问题描述
willTransition
钩子的插件中创建一个路由器mixin,但是我遇到的问题不限于此事件。 此时,mixin看起来像这样:
从ember导入Ember;
export default Ember.Mixin.create({
genericFunction:function(transition){
console.log('--- generic function ---');
} .on('willTransition')
});
当尝试使用mixin运行虚拟应用程序时,我会收到以下错误:
未捕获TypeError:(中间值)(中间值).on不是函数
在单独的应用程序中包含和使用插件时,没有错误,一切都按预期方式运行。对于在完整应用程序中使用的任何问题,没有任何警告,错误,其他任何提示。
虚拟应用程序和单独应用程序的环境配置是相同的,所以我排除了环境配置作为一个潜在的问题。
我不知道这是否仅仅是Ember中的功能被破坏或是否需要要采取一些额外的步骤,使虚拟应用程序的行为与使用钩子/事件时期望的一样。
任何帮助将不胜感激。
谢谢!
替代(更好)的解决方案是保留原型扩展禁用并使用非原型变体。这样,您不要强制应用程序使用不希望的原型扩展。
从ember导入Ember ;
const {
Mixin,
on
} = Ember;
导出默认Mixin.create({
genericFunction:on('willTransition',function(transition){
console.log('--- generic function ---' );
})
});
I'm using Ember CLI 1.13 and I'm attempting to create a router mixin in an addon that binds to the willTransition
hook, but the issue I'm encountering is not limited to this event.
At this point the mixin looks like such:
import Ember from 'ember';
export default Ember.Mixin.create({
genericFunction: function(transition) {
console.log('--- generic function ---');
}.on('willTransition')
});
When attempting to run the dummy app utilising the mixin, I get the following error:
Uncaught TypeError: (intermediate value)(intermediate value)(intermediate value).on is not a function
When including and using the addon in a separate application, there are no errors and everything functions as expected. There are no warnings, errors, anything else to hint towards any issues with its use in a full application.
The environment config of the dummy app and the separate application are identical, so I've ruled out environment config as a potential issue.
I'm not sure whether or not this is just broken functionality in Ember or whether I'm required to take some additional steps to make the dummy app behave as you'd expect it to when using hooks/events.
Any help would be greatly appreciated.
Thanks!
The alternative (and better) solution is to keep prototype extensions disabled and use the non-prototype variant. This way, you don't force apps to use the prototype extensions that don't wish to.
import Ember from 'ember';
const {
Mixin,
on
} = Ember;
export default Mixin.create({
genericFunction: on('willTransition', function(transition) {
console.log('--- generic function ---');
})
});
这篇关于Ember CLI Hook /事件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!