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(middleware): accept partial methods #4673

Merged
merged 9 commits into from
Apr 6, 2021
Merged

Conversation

eunjae-lee
Copy link
Contributor

Summary

This PR allows middlewares to have partial methods. A middleware had to contain all of subscribe, unsubscribe, onStateChange methods, which isn't necessary.

Result

It works the same as before except that the following is possible now:

search.use(() => ({
  onStateChange({ uiState }) {
    // ...
  }
});

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 9, 2021

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 b566664:

Sandbox Source
InstantSearch.js Configuration

@eunjae-lee eunjae-lee requested review from a team, Haroenv and shortcuts and removed request for a team March 9, 2021 15:29
@Haroenv Haroenv changed the title fix(middleware): accept partial methods feat(middleware): accept partial methods Mar 10, 2021
@eunjae-lee eunjae-lee requested a review from Haroenv March 10, 2021 16:08
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

I think this makes sense, but I remember that @francoischalifour originally wanted middlewares to not have optional keys. I wonder if this has changed?

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Make sense!

@francoischalifour
Copy link
Member

I think this makes sense, but I remember that @francoischalifour originally wanted middlewares to not have optional keys. I wonder if this has changed?

The original reason was that going from optional to required is a breaking change, while going the opposite isn't.

Besides, I tend to avoid fully optional structures—now a middleware can be an empty object.

@eunjae-lee
Copy link
Contributor Author

eunjae-lee commented Mar 17, 2021

The original reason was that going from optional to required is a breaking change, while going the opposite isn't.

→ makes sense

Besides, I tend to avoid fully optional structures—now a middleware can be an empty object.

→ do we want to avoid it?

@eunjae-lee
Copy link
Contributor Author

@francoischalifour

@francoischalifour
Copy link
Member

→ do we want to avoid it?

That's not easy to answer. It'll add overhead to both our code and the middleware usage with conditional requirements. We have the same problem with the widget definition where nothing is required, but you still have to provide either init or render. You can't type-check that. That's why I don't think that this PR is necessary personally.

@eunjae-lee
Copy link
Contributor Author

That's not easy to answer. It'll add overhead to both our code and the middleware usage with conditional requirements. We have the same problem with the widget definition where nothing is required, but you still have to provide either init or render. You can't type-check that. That's why I don't think that this PR is necessary personally.

This PR adds noop upfront, so I don't see it as an overhead. We can show a warning message if it's an empty object. And if we want, we can do it like this, although it's not the cleanest.

@eunjae-lee eunjae-lee requested a review from Haroenv March 22, 2021 10:24
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

I personally think with the "at least one", the downside of empty objects is alleviated, as well as it being instantiated with noops, so no new conditions need to be added. However we need to have a consensus on this as a team

@eunjae-lee
Copy link
Contributor Author

I personally think with the "at least one", the downside of empty objects is alleviated, as well as it being instantiated with noops, so no new conditions need to be added. However we need to have a consensus on this as a team

What do you mean by "no new conditions"?

@Haroenv
Copy link
Contributor

Haroenv commented Mar 30, 2021

conditions when using middleware, as it was needed in the initial version of the pr

@eunjae-lee eunjae-lee merged commit 8f2aad2 into master Apr 6, 2021
@eunjae-lee eunjae-lee deleted the fix/partial-middleware branch April 6, 2021 10:00
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.

None yet

4 participants