Addon不工作 [英] Addon not working

查看:80
本文介绍了Addon不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ember Addon,我在Github这里放了:



https://github.com/lifegadget/ember-dictionary



它通过其所有单元测试并且在一个非 addon 表单中,它在我的一个项目中正常工作,但我希望将其解除该项目,并可以将其用作插件。我仍然清楚地忽略了如何揭示两个Ember类的一个步骤。这可以在虚拟应用程序中看到,它试图创建一个非常简单的模型,如下所示:

 从ember-data导入DS ; 
从'ember-dictionary'导入DictionaryModel;

导出默认DictionaryModel.extend({
foo:DS.attr('string')
});

然后当路由( tests / dummy / routes / index.js )尝试使用模型我得到以下错误:


处理路由时发生错误:index无法读取未定义的属性extendsTypeError:无法读取未定义的属性extend


对我来说,这感觉像是一个ES6 /命名空间问题,但我不知道如何克服它。我尝试了以下更明确的import语句:

 从'ember-dictionary / models / dictionary-model'导入DictionaryModel; 

但发生同样的错误。任何帮助将不胜感激。

解决方案

我碰到了足够的墙壁,我认为我至少可以部分回答我的问题,一些问题仍然存在,所以我不会将此答案正确地标记出来,希望别人可以发表更完整的答案。






我意识到自己没有足够清楚的第一个区别是,是否将Ember应用程序的命名空间定位到目标位置,或是针对插件的独立命名空间。在插件的 app 目录中定义的类将可用于在其自己的命名空间中使用Addon的任何应用程序。相反, addon 目录中的类将命名为addon的命名空间。



我已经看到很多人在插件的应用程序目录中定义了类,然后将其代理到 addon 目录中的东西:

  // addon / mixins / dictionary.js 
从'ember-dictionary / mixins / dictionary'导入DictionaryMixin;
导出默认DictionaryMixin;

虽然我已经看到这个,但我仍然遇到这些外部命名空间类工作的问题。我想可能还需要添加一个 index.js 入口点,然后在这里导出这些类。无论如何,我将离开这个区域,因为我决定先获得内部命名空间的解决方案。



我的内部命名空间解决方案的下一个问题是围绕作为附件创建过程的一部分构建的虚拟应用程序。我想要这个虚拟应用程序有一个模型,它将使用我在插件中创建的Mixin,我认为我可以将它引用为:

 从'ember-dictionary / mixins / dictionary'导入DictionaryMixin; 

但这不能被Dummy测试应用程序解决,所以我不得不诉诸于: p>

 从'../mixins/dictionary'导入DictionaryMixin; 

我认为我的外部命名空间解决方案尚未运行,这是合适的...需要退回内部命名空间的解决方案。


I have an Ember Addon which I've put up at Github here:

https://github.com/lifegadget/ember-dictionary

It passes all its unit tests and in a non addon form it is working fine in one of my projects but I'd like to lift it out the project and be able to use it as an addon. Still I'm clearly missing a step in how to expose the two Ember classes. This can be seen in the dummy app which tries to create a very simple model like so:

import DS from 'ember-data';
import DictionaryModel from 'ember-dictionary';

export default DictionaryModel.extend({
  foo: DS.attr('string')
});

Then when the route (tests/dummy/routes/index.js) tries to use the model I get the following error:

Error while processing route: index Cannot read property 'extend' of undefined TypeError: Cannot read property 'extend' of undefined

To me this feels like a ES6/namespacing issue but I'm not sure how to overcome it. I did try the following more explicit import statement:

import DictionaryModel from 'ember-dictionary/models/dictionary-model';

but the same error occurred. Any help would be greatly appreciated.

解决方案

I have bumped into enough walls that I think I can at least partially answer my question but some questions still remain so I won't mark this answer correct with the hope that others may post a more complete answer.


The first distinction I realised I hadn't been making clear enough for myself was whether to target the Ember App's namespace or to target an independent namespace for the addon. Classes defined in the app directory of the addon will be available to any application which uses the Addon in it's own namespace. In contrast, classes in the addon directory will be namespaced to the addon's namespace.

I have seen a lot people define classes in the addon's app directory and then proxy it through to the addon directory with something like:

// addon/mixins/dictionary.js
import DictionaryMixin from 'ember-dictionary/mixins/dictionary';
export default DictionaryMixin;

Although I've seen this I am still having problems getting these external namespaced classes to work. I think there may be another step needed to add a index.js entry point for the addon and then export these classes there. In any event, I'll leave this area alone as I decided to get the internal namespaced solution working first.

My next problem in the internal namespaced solution was centered around the dummy application that gets built as part of the addon creation process. I wanted this dummy application to have a model which would use the Mixin I created in the addon and I thought I'd be able to refer to it as:

import DictionaryMixin from 'ember-dictionary/mixins/dictionary';

but this couldn't be resolved by the Dummy test application so I had to resort to:

import DictionaryMixin from '../mixins/dictionary';

Which I guess is appropriate considering that my "external namespaced solution" isn't working yet ... falling back to the internally namespaced solution was required.

这篇关于Addon不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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