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

Do not mix data and methods in sharedSelector #116

Closed
wants to merge 5 commits into from

Conversation

vb
Copy link
Contributor

@vb vb commented Mar 6, 2023

As discussed on FE tech collab 2023-02-28

This PR propose a new type that ensures that the return type of the selector does not mix methods and data

  • ✅ Only data

CleanShot 2023-03-06 at 14 26 14@2x

  • ✅ Only functions/methods

CleanShot 2023-03-06 at 14 27 57@2x

  • 🛑 Mix data and methods

CleanShot 2023-03-06 at 14 28 46@2x

Discussion

  • Should this be implemented in other hooks?

Improvements

  • I wish I could make the error clearer for the consumer.

CleanShot 2023-03-06 at 14 24 36@2x

@@ -13,6 +13,15 @@ export interface EqualityCheck<T> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Value = string | number | boolean | undefined | null | [] | Record<string, any>
Copy link
Contributor Author

@vb vb Mar 6, 2023

Choose a reason for hiding this comment

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

Is this type to broad? The comment above says that functions is not supported, but Record<string, any> includes functions

CleanShot 2023-03-06 at 14 39 19@2x

I added type ValueWithoutFunction that does not accept functions

CleanShot 2023-03-06 at 14 40 16@2x

@vb vb marked this pull request as ready for review March 6, 2023 13:34
Copy link
Contributor

@xaviervia xaviervia left a comment

Choose a reason for hiding this comment

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

If I understand correctly, consumers that are using the library will have to update their sharedFacets if they want to update to a version of the library that includes this fix, right? Or this is an optional change? I'm deducing this from the fact that selectors return OnlyDataOrOnlyMethods<V>.

If we go that far, I think we should probably do that in the sharedFacet function. Alternatively we could provide new sharedFacet and sharedSelector functions that could be used for people not having to immediately migrate upon adoption.

@xaviervia
Copy link
Contributor

We talked a bit about this and figured out that it's probably best to create separate functions that implement the new types, to avoid breaking changes. We can mark the current shared facet functions as deprecated to remember to move away from them in the future.

Copy link
Contributor

@Shenato Shenato left a comment

Choose a reason for hiding this comment

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

Very nice, was really interesting to see how you solved it in typescript only! 👍

I do agree with @xaviervia 's comment though we should avoid breaking other people's code. However, I think we should locally run typechecking with the edited current sharedSelector to see where this ipotentially could cause the issues we had that gave rise to this task in the first place so we can nudge the teams responsible to migrate to the new 'sharedSelector' with typeguard.

Great work! 🙌
For now will click request changes, until we resolve the conversation with @xaviervia but I approve otherwise 👍

vb added 2 commits May 5, 2023 15:12
- Introduced safeSharedFacet, safeSharedSelector with safer type
- Made generic type passed to sharedFacet read-only
@Shenato
Copy link
Contributor

Shenato commented Feb 8, 2024

A new facet API might be introduced soon which will render this PR obselete, consider taking up the effort again after such change is done if it is not already included in the scope of the API change.

@Shenato Shenato closed this Feb 8, 2024
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