2016-09-11 6 views
2

Discourse_dockのメソッドを変更したい。変更コードはプラグインに配置されます。Emberコンポーネントのメソッドを変更

は、ここでそのファイルからの短い抜粋です:

export default Ember.Component.extend({ 
    elementId: 'topic-progress-wrapper', 
    classNameBindings: ['docked', 'hidden'], 

    ... 
    _dock() { 
    ... 
    }, 

}); 

この方法を変更する方法は?私はこのコンポーネントを再オープンすべきですか?そのための構文は何ですか?

答えて

1

thisthisガイドをご覧ください。 あなたは、新しいコンポーネントを作成するには、このようなものが必要:

// components/my-discourse-component.js 
import MyDiscourseComponent from 'discourse/components/topic-progress'; 

MyDiscourseComponent.extend({ 
    // Here you can extend the function. Don't forget 
    // this._super(...arguments) if you want to use the original function. 
}); 

MyDiscourseComponent.reopenClass({ 
    // Here you can completly override the function. 
}); 

export default MyDiscourseComponent; 

とちょうどあなたのtemlateで{{my-discourse-component}}を使用しています。

アドオンのコードをミックスインにコピーして、そのミックスインで新しいコンポーネントを単に拡張することができます。

+0

私のケースでは、reopenClassが最も適していると思います。しかし、Emberコンポーネントは 'elementId'にバインドされていますが、ここで実際にクラス名は何ですか? – megas

+0

classNames、classNameBindingsおよびattributeBindingsは、コンポーネントの連結プロパティです。したがって、classNamesまたはclassNameBindingsを拡張するだけで、アドオンからすべてのクラスを取得し、コンポーネントで定義するクラス名を取得できます。これを参照してください:http://emberjs.com/api/classes/Ember.Object.html#property_concatenatedProperties – lependu

+0

classNameBindingsには2つの文字列の配列がありますが、コンポーネントの名前は何ですか? – megas

関連する問題