-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Helper for a mixin to override parent's method. #11
Comments
So yea, this can be a big discussion. How to provide in some way multiple inheritance. The approach we are currently taking is that component has to provide an explicit extension point by calling one of In some way, in OOP by creating a method you create such an extension point. Which then child implementations can extend. If you do not put a piece of logic into a method then children are unable to extend that piece of logic. Currently we in some way require definition of an extension point twice: by creating a method and by calling In some way parent methods do not call |
One question to consider is what if component does not provide this method. Probably then mixin should just set it. But then maybe we do not need anymore that template helpers are searched in mixins and components, but just components, and if mixin wants to add a template helper, it overrides (or sets) it on the component. Same could be done also for event handlers. |
After more thought I think the main confusion is coming from the fact that mixins in current design in some way come after a component. So component is called first. So if component Same goes for dependencies mixin I think it is a good design that we allow overriding or extending only in one direction. In this way it works the same as your If you want some functionality to be overridden by a mixin, you have to move it to a mixin which comes after your mixin. |
This is a potential function for
BlazeMixin
(theBlazeComponent
extension that might or might not be part of the package).I have a hard time coming to terms that the implementer of the component needs to know what functions the mixins are overriding (or the component is overriding from them, depending which way you look at it).
We'll see in practice how often this would be useful, but if more simple cases like
PersistentInputMixin
(previouslyFrozen
) from the demo could function by simply augmenting the parent class, a helper for that might be worth it.So you would say:
This is exactly how we have written this function through inheritance:
(We could also go for
Super
instead of_super
.)I did not test what happens if two mixins override the same function … I guess they would just get chained in order of mixins (assuming they are instantiated in that order), so it's like inheritance from the component on top and mixins going from first to last. So the last mixin is also at the bottom of this 'inheritance' chain. It's up to them to call
_super()
to travel up the chain to the component on top. Which is not the nicest, since the idea of composition is that mixins shouldn't have to worry about each other.Anyway, the code to make
override
work is:I wonder if I could modify the code so that all mixins who overrided a function are called in parallel instead of as a chain. And they all get the same
_super
that is component's implementation. A downside of this is that_super
can get called multiple times, which doesn't play well with functions that have side effects. Neither is it clear what to actually return as the final value from the function (first result? last?).The text was updated successfully, but these errors were encountered: