命名混合与Ember-CLI [英] Naming Mixins with Ember-CLI

查看:93
本文介绍了命名混合与Ember-CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ember插件,它使用几个Mixin来提供它的功能。不幸的是,当我在Ember Inspector中看到这个对象时,我得到一个装载了未知的mixin桶的小船,我的状态分散在:





我没关系那里有很多 但我真的很想让他们命名。在Ember-CLI环境/环境中工作时,如何做到这一点。



p.s。我在Ember-CLI 0.2.3与Ember 1.11.1和最新版本的Ember Inspector(截至2015年4月11日)。






有人建议,一个 toString()函数可能会解决这个问题,但似乎并没有对我有影响:





您在上图中看到的是在应用以下建议的更改后在检查器中显示的内容:

  / addon / mixins / ui-shared-animation.js 

从ember导入Ember;

var AnimationSupport = Ember.Mixin.create({
classNameBindings:['_animateClass'],

animate:null,
_animator:Ember。观察者(...),
animateEnabled:null,
animateDisabled:null,
_disabledObserver:Ember.observer(...),
animateEnter:null,
_enterAnimationObserver:Ember.observer(...),
_processAnimation:function(animate){...}
}
});

AnimationSupport.toString = function(){return'ui-shared-animation'; };
导出默认的AnimationSupport;


解决方案

好的,我回答了我的问题Ember Inspector的封闭问题并拉出了这个宝石:


https://github.com/emberjs/ember-inspector/issues/284


在Ember-CLI中,您需要为mixin做的所有操作如下:

  // addon /mixins/ui-shared-animation.js 

从ember导入Ember;

var AnimationSupport = Ember.Mixin.create({
classNameBindings:['_animateClass'],

animate:null,
_animator:Ember。观察者(...),
animateEnabled:null,
animateDisabled:null,
_disabledObserver:Ember.observer(...),
animateEnter:null,
_enterAnimationObserver:Ember.observer(...),
_processAnimation:function(animate){...}
}
});

AnimationSupport [Ember.NAME_KEY] ='animation-support';
导出默认的AnimationSupport;

Yay!我的6混合方法的插件得到了更多的合理。 :)


I have an ember addon which uses several Mixins to provide its functionality. Unfortunately when I look at this object in the Ember Inspector I get a boat load of "unknown mixin" buckets where my state is scattered across:

I'm ok with there being a lot of "buckets" but I'd really like to have them named. How does one go about doing that when working within the Ember-CLI context/environment.

p.s. I'm on Ember-CLI 0.2.3 with Ember 1.11.1 and the latest build of Ember Inspector (as of 11 Apr 2015).


It was suggested that a toString() function might solve this problem but it does not seem to be having that effect for me:

What you see in the image above is what appears in the Inspector after applying the changes suggested below:

// addon/mixins/ui-shared-animation.js

import Ember from 'ember';

var AnimationSupport = Ember.Mixin.create({
  classNameBindings: ['_animateClass'],

  animate: null,
  _animator: Ember.observer( ... ),
  animateEnabled: null,
  animateDisabled: null,
  _disabledObserver: Ember.observer( ... ),
  animateEnter: null,
  _enterAnimationObserver: Ember.observer( ... ),
  _processAnimation: function(animate) { ... }
  }
});

AnimationSupport.toString = function() { return 'ui-shared-animation'; };
export default AnimationSupport; 

解决方案

Ok, I've answer my question by looking into the Ember Inspector's closed issues and pulling out this gem:

https://github.com/emberjs/ember-inspector/issues/284

Within Ember-CLI, all you need to do for a mixin is the following:

// addon/mixins/ui-shared-animation.js

import Ember from 'ember';

var AnimationSupport = Ember.Mixin.create({
  classNameBindings: ['_animateClass'],

  animate: null,
  _animator: Ember.observer( ... ),
  animateEnabled: null,
  animateDisabled: null,
  _disabledObserver: Ember.observer( ... ),
  animateEnter: null,
  _enterAnimationObserver: Ember.observer( ... ),
  _processAnimation: function(animate) { ... }
  }
});

AnimationSupport[Ember.NAME_KEY] = 'animation-support';
export default AnimationSupport; 

Yay! My 6 mixin approach to addons just got a lot more reasonable. :)

这篇关于命名混合与Ember-CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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