fix!: Allow to inherit from View to create custom classes#1067
fix!: Allow to inherit from View to create custom classes#1067
View to create custom classes#1067Conversation
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:
getContentsto 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 Viewwas called or a new subclass.