-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Inheritance (again) #463
Comments
@jods4 would a solution that lifts the |
@jdanyow Somehow, In our codebase, the only thing that we would need at the moment is have |
same here. @EisenbergEffect has suggested using decorators, but that takes much more effort compared to base class and if You happen to use TypeScript, then You really start to hate that approach (as TS compiler can't know at compile time what might be added at runtime to the class - so You either need to cast |
I'm really apposed to inheritance. That doesn't mean we can't do this. It's likely to take a lower priority for the team though since there are other ways to handle the solution and other features/fixes that are more critical. However...if someone were to submit a PR that made inheritance work...with tests...then there's a good likely hood it would get in pretty quickly. |
@EisenbergEffect Can you link some doc regarding the better ways? Thanks! |
I don't have a doc specifically on that subject. Perhaps search the internet for "using decorators for composition" or something like that. |
@jdanyow @EisenbergEffect I think the bindables from the base not being visible is the main issue and headache. After spending a few months on a big app, it starts being a headache maintaining a bunch of bindable decorators on extended elements after a change. Can you point us in the right direction to where to start for this change? |
Ok I commented on issue 210 but seems this is a more up to date ticket Having @bindable work using inheritance I think is very important the only alternative is lots of copy and paste code If there are some other options could a code example be provided |
@Infuser I found this decorate in one of the ui bridges. Maybe it can help us in some way? |
Thanks interesting I see people talking about it in this post not sure how to use it yet though need more time |
I highly recommend to use decorators. You can basically use them to meta-program your JS classes. They can dynamically add shared behavior. Because they are decorators, you can have as many as you need as opposed to inheritance which only allows for one base class. Decorators favor the composition style of OO which gives you a better set of options than inheritance usually. |
Hi Rob Thanks for the response I am sure you are correct using decorators is a better approach sadly not sure what you mean could please provide a code example for this in relation to the @bindable issue Thanks in advance |
Well I gave it a try and had no luck using this web site as a guide https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.g0voh5lni I get inputbase is not a function |
Ok here is a basic decorator that works with esnext I will try putting some bindables on it later export function superhero(isSuperHero) |
Finally got a chance to have another look at this ended up with code below seems to work would appreciate any comments/constructive criticism's export function inputbase()
} |
I have code ready for this, I'll prepare a PR with some explanations. |
@EisenbergEffect I was testing my code and I banged my head again on the metadata inheritance in ES5 code transpiled by TS: aurelia/polyfills#34, microsoft/TypeScript#4266. TL;DR: if you want to mix class inheritance and metadata in ES5 code generated by TS:
The last option is probably the best, because it gives you true ES6 This is not directly-related to the upcoming PR but it is prominently showcased. |
Is there some way that we could create a plugin for Aurelia that enabled inheritance. Things the plugin could do are: provide an alternate Reflect.metadata implementation, replace the __extends helper method if present, etc. |
@EisenbergEffect The best thing we could do is try to convince TypeScript guys (again) that in 2017 having an ES6 compliant code-gen in 90% of the browsers and have an unfixable edge-case in 10% is better than being consistently incorrect. Or ask them to provide an easy opt-in (or better opt-out!) flag to turn on/off compliance. This is even worse now with Other than that, Aurelia could change its Replacing |
@EisenbergEffect Great news, it seems MS might finally change their mind and have an ES-compliant |
It's 6 months down the line, this feature is still not implemented. I agree on the flexibility of composition > inheritance, and understand that by using composition one can achieve essentially the same result. @jods4 What ever came of your "Great news" EDIT: Yes, it's the @bindable decorator that is most appealing. I have a base component which offers a generic view that is configurable. I'd like to extend the component with hard coded configurations in a minimalistic manner, inheritance suits this approach. |
@tjad Agreed, it is a real headache to keep stumbling into this. As nice as it is to have a preferred approach for how to model the components, we should have the ability to use inheritance for our own tastes. |
I guess it can be closed when the PR is merged! The PR has been open for a long time now. |
You and I need to chat so I can get a full rundown on this and current
transpiler limitations, if any. I'll try to catch you online in the next
couple of days.
…On May 23, 2017 12:13 PM, "jods" ***@***.***> wrote:
I guess it can be closed when the PR is merged! The PR has been open for a
*long* time now.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#463 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIBnSdn87qf7qw8G1mhCQFq_k-MTfH2ks5r8y-1gaJpZM4J992I>
.
|
This can be closed. I've just tested it working in the latest release! |
Ran into a situation a few days ago where an easy solution was to bind to a base class in my custom components. Was pleasantly surprised to see such a long standing issue solved just in time for me to utilize this functionality. Great work! |
Could we reconsider supporting inheritance in behaviors (e.g. custom elements, custom attributes)?
This was brought up (and closed) several times in the past, e.g. #84, #249.
@EisenbergEffect said
Could you provide more guidance regarding mixins support?
Motivation
In our codebase, several times we define a common base class for similar custom elements or custom attributes, with just slightly different configuration choices.
For example, we have a better
<select>
control as a custom element, that is instantiated in two flavours: with a local list of items and with an AJAX lookup. The base class defines some common behaviour and options.This works for us, except that the metadata is not inherited. For example, the base class defines
But the
@bindable
annotation is lost on descendants and we have to copy-paste them on both the local and AJAX variations.An analysis of the code shows that the problem in this specific case is that all CustomElement-related metadata is stored in a single object with key
metadata.resource
.Because this dictionary exists in the derived class, properties of the base class are totally ignored.
I think that at least this part could be fixed by merging
metadata.resource
objects from derived to base class before usage by Aurelia.The text was updated successfully, but these errors were encountered: