Search code examples
pluginsextjsextjs4mixins

mixin vs plugin. What to choose?


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?


Solution

  • 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)