Skip to content
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): smoother accessing of widgetRenderState #4558

Merged

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Oct 30, 2020

this kinda works @eunjae-lee, although some parts still seem to be inferred as any. The public API works though

I also made a small change: not using widgetRenderState as key, but spreading the renderer. This way the usage is so much smoother (and you can use it for the templates too, which comes up from time to time)

@@ -259,9 +259,8 @@ const panel: PanelWidget = widgetParams => {
const [renderOptions] = args;

const options = {
...(widget.getWidgetRenderState?.(renderOptions) || {}),
Copy link
Contributor Author

@Haroenv Haroenv Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible without casting since I reuse the type for TWidget for widgetFactory

collapsed({ widgetRenderState }) {
return widgetRenderState.canRefine;
collapsed({ canRefine }) {
return canRefine === false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your example used to be wrong

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 30, 2020

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 9a8b4db:

Sandbox Source
InstantSearch.js Configuration

@Haroenv Haroenv changed the title WIP feat(panel): smoother accessing of widgetRenderState Oct 30, 2020
@@ -151,11 +151,13 @@ storiesOf('Basics/Panel', module)
withHits(
({ search, container }) => {
const breadcrumbInPanel = panel<typeof breadcrumb>({
collapsed({ widgetRenderState }) {
return widgetRenderState.canRefine;
collapsed({ canRefine }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This usage is much better and eventually what we want to enable in next major version so if there can't be collision with the IS instance (which is also passed and spread) that's great!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't realize there cannot be collision. This looks so much better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I can tell there's no collision here, so this doesn't even need a major :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it makes sense there is no collision :)

Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks nice!

};
> = RenderOptions & ReturnType<TWidget>['getWidgetRenderState'] extends (
renderOptions: any
) => infer TRenderState
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't know about infer. looks nice 👍

@Haroenv Haroenv merged commit 73f4fbf into feat/widget-render-state-in-panel Nov 2, 2020
@Haroenv Haroenv deleted the chore/ehhh-doesnt-really-work branch November 2, 2020 10:30
eunjae-lee pushed a commit that referenced this pull request Nov 3, 2020
* update panel

* add a story

* provide an empty object to widgetRenderState by default

* add generic to panel

* update the story to infer the type instead of importing and using the type itself

* extract to PanelRenderOptions

* clean the code

* fix type error

* feat(panel): smoother accessing of widgetRenderState (#4558)

* WIP

* now it works

* better example

* revert for lower ts used here

* gotta be more generic

* WIP trying to replace any with unknown

* add UnknownWidgetFactory

* parenthesis, move back to any (unknown is stricter than any)

* reuse UnknownWidgetFactory in panel component

Co-authored-by: Haroen Viaene <[email protected]>
Haroenv added a commit that referenced this pull request Nov 30, 2020
* update panel

* add a story

* provide an empty object to widgetRenderState by default

* add generic to panel

* update the story to infer the type instead of importing and using the type itself

* extract to PanelRenderOptions

* clean the code

* fix type error

* feat(panel): smoother accessing of widgetRenderState (#4558)

* WIP

* now it works

* better example

* revert for lower ts used here

* gotta be more generic

* WIP trying to replace any with unknown

* add UnknownWidgetFactory

* parenthesis, move back to any (unknown is stricter than any)

* reuse UnknownWidgetFactory in panel component

Co-authored-by: Haroen Viaene <[email protected]>
Haroenv added a commit that referenced this pull request Nov 30, 2020
* update panel

* add a story

* provide an empty object to widgetRenderState by default

* add generic to panel

* update the story to infer the type instead of importing and using the type itself

* extract to PanelRenderOptions

* clean the code

* fix type error

* feat(panel): smoother accessing of widgetRenderState (#4558)

* WIP

* now it works

* better example

* revert for lower ts used here

* gotta be more generic

* WIP trying to replace any with unknown

* add UnknownWidgetFactory

* parenthesis, move back to any (unknown is stricter than any)

* reuse UnknownWidgetFactory in panel component

Co-authored-by: Haroen Viaene <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants