mixin vs plugin. What to choose?
Asked Answered
F

3

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?

Filature answered 4/9, 2011 at 10:33 Comment(1)
Mixin is inheritance but plugin are composition.Burma
J
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)

Jovitta answered 4/9, 2011 at 15:4 Comment(3)
Thank you for answer. So, which do you think is the best choice for my close-button example?Filature
I've got it. The best choice would be plugin as I want to enhance an existing component. Thanks, again.Filature
Also, since the OP asked about in general, you can only use plugins on Ext.ComponentsNevarez
P
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

Parthenon answered 18/11, 2011 at 15:14 Comment(0)
U
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.

Unwisdom answered 1/12, 2015 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.