-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix!: Allow to inherit from View
to create custom classes
#1067
base: main
Are you sure you want to change the base?
Conversation
Use case: You want to scope logic and state into the view rather than somewhere in a module. Problems: Currently there are two problem that prevent creating a child-class of view: 1. The view class did not implement the methods as methods but getters, this forces also child classes to use getters leading to really ugly code. 2. The constructor required `getContents` to be part of the `ViewData`, but for child classes this makes no sense, as you probably want to overwrite this with a member function instead. Fixed by checking if `new View` was called or a new subclass. Signed-off-by: Ferdinand Thiessen <[email protected]>
Bundle ReportChanges will increase total bundle size by 1.45kB ⬆️
|
This option is slightly breaking, but only for the files app as it need to check I think just extending ℹ️ See alternative PR here |
Why not keep it as getter? |
Because you can not overwrite it in a custom class, it always then has to be a getter not a method. class MyView extend View {
public emptyView(div: HTMLDivElement) {
// do something
}
} Instead you would need to do: class MyView extend View {
public get emptyView() {
return this.handleEmptyView.bind(this)
}
private handleEmptyView(div: HTMLDivElement) {
// ...
}
} |
(Thats the reason I also offer the alternative: #1068 ) |
Why would you need to overwrite it? |
Because e.g. I want to have a local scope, meaning the |
Use case:
You want to scope logic and state into the view rather than somewhere in a module.
Problems:
Currently there are two problem that prevent creating a child-class of view:
getContents
to be part of theViewData
, but for child classes this makes no sense, as you probably want to overwrite this with a member function instead. Fixed by checking ifnew View
was called or a new subclass.