What is the difference between Mixins and services on Emberjs

I try to follow Ember's best practices and their potentialities, and this question tells me what is the difference between Mixins and services and how do you use each of them?

I have several services / mixins and it works pretty well, but I want to be sure that I am doing it right.

+4
source share
1 answer

A mixin is when you want different objects to have the same behavior / data. Let's say you want multiple controllers to trigger the same action, but change one argument:

// app/mixins/change-name.js
export default Ember.Mixin.create({
  actions: {
    changeName(item) {
      item.set('name', this.get('name'));
    }
  }
});

// app/controllers/some-controller
import ChangeName from '<app-name>/mixins/change-name';

export default Ember.Controller.extend(ChangeName, {
  name: 'Some Controller'
});

, , , . mixins , _super().

. , , .

, , . , , , .

+11

Source: https://habr.com/ru/post/1627782/


All Articles