-
Notifications
You must be signed in to change notification settings - Fork 529
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
feat(panel): render templates on init with render state #4845
Conversation
Before this PR the initial render happens *before* widget init. This doesn't have a huge effect, although it got rendered with just an empty object. This makes things needlessly dynamic (more than the types were saying even, because the Template isn't super strict), and would make a template like `header({ widgetParams }) { return widgetParams.attribute }` throw, even though with this PR it is possible without conditionals or flashing. Under very strict conditions this could be construed as a breakign change, although it's closer to a fix, therefore I have classified it as a new feature.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit effa71b:
|
init(...args) { | ||
const [renderOptions] = args; | ||
|
||
if (typeof widget.dispose === 'function') { | ||
return widget.dispose.call(this, ...args); | ||
} | ||
const options = { | ||
...(widget.getWidgetRenderState | ||
? widget.getWidgetRenderState(renderOptions) | ||
: {}), | ||
...renderOptions, | ||
}; | ||
|
||
return undefined; | ||
renderPanel({ | ||
options, | ||
hidden: true, | ||
collapsible, | ||
collapsed: false, | ||
}); | ||
|
||
if (typeof widget.init === 'function') { | ||
widget.init.call(this, ...args); | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the main change, the rest is mostly types and tests
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e042d41:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we initially wanted to display the header and footer before the widget's init
method is called, but I don't really see why. Having consistent data passed to the templates is more important imo. Besides, the panel
widget is not a side effect anymore.
I think originally it might have made sense together with the |
Summary
Before this PR the initial render happens before widget init. This doesn't have a huge effect, although it got rendered with just an empty object. This makes things needlessly dynamic (more than the types were saying even, because the Template isn't super strict), and would make a template like
header({ widgetParams }) { return widgetParams.attribute }
throw, even though with this PR it is possible without conditionals or flashing.Under very strict conditions this could be construed as a breakign change, although it's closer to a fix, therefore I have classified it as a new feature.
Result
panel's templates always get called with render state, but also with init options. Before this PR it got called with either results or an empty object