Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify method in Ember Component

In the Discourse I want to modify method _dock. The modifying code will be placed in plugin.

Here's short snippet from that file:

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

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

});

How to modify this method? Should I reopen this component and what is a syntax for that?

like image 961
megas Avatar asked Sep 03 '26 12:09

megas


1 Answers

Take a look this and this guide. You need to create a new component, something like this:

// 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;

and just use {{my-discourse-component}} in your temlate.

Or you can copy the addon's code into a mixin, and simply extend your new component with that mixin.

like image 138
lependu Avatar answered Sep 05 '26 07:09

lependu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!