18

Let's assume I have defined several new components -MyComponent1, MyComponent2, ..., which extend Ext.Component.

Now I wnat to extend all this widgets with the same functionality - I want to add close button which would appear at the top-right position of MyComponentX.el.

What should I use: mixin? plugin? or something else?
And in general: mixin vs plugin, what is the best practise?

Molecular Man
  • 22,277
  • 3
  • 72
  • 89

3 Answers3

19

I like to think about it as -

mixin is what you use to achieve 'multiple inheritence'
plugin is what you use to enhance an existing component. plugin's lifecycle is managed by the component. (no lifecycle managemen for mixin. think of mixin as base class equivalent)

Amol Katdare
  • 6,740
  • 2
  • 33
  • 36
14

Mixin properties and functions are injected into the class directly so they are part of the class definition.

plugins are added at the instance level

user732456
  • 2,638
  • 2
  • 35
  • 49
1

Plugins will add functionality to the Ext.Component class or the class extending Ext.Component. Scope of any method in plugin is in plugin itself.

Mixins can be used to add functionality to any other class. mixins methods will be available directly into the class.