Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 430
Molecular Man Avatar asked Sep 04 '11 10:09

Molecular Man


2 Answers

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)

like image 154
Amol Katdare Avatar answered Oct 08 '22 22:10

Amol Katdare


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

like image 24
user732456 Avatar answered Oct 08 '22 22:10

user732456