-
Notifications
You must be signed in to change notification settings - Fork 2k
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
How to override computed property? #4974
Comments
I'm curious to know why override a computed property? IMHO, a computed property is computed by an element and this one knows better than me how to compute it (or there is a bug to fix). So, when I extend the element and the child has also a computed property, this one can't has the exact same value. There is something more or something less. Why not just use an other property? I'm thinking about if I want to use your-super-element that extend super-element and I want use the computed property (that you overwrote) of the parent of your-super-element. Should I override it again or directly extend super-element and re-implement the behaviors of yours? Maybe there is a pattern or something that I don't know. On principle I agree, child should overrides parent definitions. |
The main reason is: polymorphism My use case is the following:
The Now let's say I've got a child input component, which inherits from the abstract Now the reason why to compute another property is not a solution is because we lose polymorphism. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed after being marked stale. If you're still facing this problem with the above solution, please comment and we'll reopen! |
Description
How to override computed property?
For instance, how to add a dependency to the compute function, or replace the compute function with another, from the child class.
Live Demo
Here's a snippet where the parent class
A
computes theresult
property to be equal to thevalue
property, while its child classB
would recompute the result property to be equal tovalue + value2
.But the override doesn't work...
http://jsbin.com/hoqeyucize/1/edit?html,js,output
Here's the stackoverflow.
Expected Results
The computed property to be computed as the child class redefines the compute function.
Actual Results
The computed property is computed as the parent class defined the compute function, and cannot be overridable.
Versions
The text was updated successfully, but these errors were encountered: