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: Refactor ActionWithPayload/ActionWithoutPayload to be uniform #605

Merged
merged 9 commits into from
May 17, 2023

Conversation

sseppola
Copy link
Contributor

No description provided.

@sseppola sseppola changed the title fix: add failing ts test case fix: Refactor ActionWithPayload/ActionWithoutPayload to be uniform Mar 20, 2023
@sseppola sseppola requested a review from rafaa2 March 20, 2023 17:10
@sseppola sseppola marked this pull request as ready for review March 20, 2023 17:10
Comment on lines -27 to -31
type ActionCreatorWithoutPayload_is_not_assibleable_to_UnknownActionCreatorWithPayload =
AssertFalse<
Has<ActionCreatorWithoutPayload, UnknownActionCreatorWithPayload<unknown>>
>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test case did not make sense.

Comment on lines +29 to +43
// Add letter representations to marble map
for (let i = 'A'.charCodeAt(0); i < 'Z'.charCodeAt(0); i++) {
const letter = String.fromCharCode(i);
marbleMap[letter] = letter;
}
// Add number representations to marble map
for (let i = 0; i < 10; i++) {
// Create marble representations of the 10 first characters
// eg. { A: 'A', B: 'B', ...etc }
const charCodeA = 'A'.charCodeAt(0);
const letter = String.fromCharCode(charCodeA + i);
marbleMap[letter] = letter;
// Create marble representations of the 10 first numbers from 0
marbleMap[`${i}`] = i;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to change these tests because it was using the lengths of the action types.. which obviously changes when you enforce the ActionName type.
Now the tests are more robust.

Comment on lines +11 to +15
type ExtractPayload_extracts_payload2 = AssertTrue<
IsExact<ExtractPayload<ActionCreatorWithPayload>, void>
>;
// type aaa = ExtractPayload<VoidFn>; // weakness of ExtractPayload
// type aaa3 = ExtractPayload<unknown>; // weakness of ExtractPayload
Copy link
Contributor Author

Choose a reason for hiding this comment

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

InferPayloadFromActionCreator is the same as ExtractPayload, although a bit more flexible.
Thinking of renaming the former to the latter, so we use the most flexible version.

Copy link
Contributor

@michaltaberski michaltaberski left a comment

Choose a reason for hiding this comment

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

I don't know the rxbeach codebase a lot, but this looks fine to me.

@rafaa2
Copy link
Contributor

rafaa2 commented Mar 21, 2023

I don't think this is working correctly.
image

src/actionCreator.ts Outdated Show resolved Hide resolved
@sseppola
Copy link
Contributor Author

@rafaa2 what's wrong with your screenshot? The actionCreator functions have a type attribute, and rxbeach relies on it.

@rafaa2
Copy link
Contributor

rafaa2 commented Mar 22, 2023

@sseppola But it should show ActionCreator not the whole object

@sseppola
Copy link
Contributor Author

The type that appears is a function signature, so it is an action creator.
I don't know if I understand what you mean.

@rafaa2
Copy link
Contributor

rafaa2 commented Mar 22, 2023

@sseppola I am not talking about type

when you use the action creator, the new object should be displayed when you hover on it as ActionCreator instead of showing its shape:

This:
image

instead of:
image

@sseppola
Copy link
Contributor Author

They are equivalent. Let's have a call tomorrow

Co-authored-by: Rafaa <10600830+rafaa2@users.noreply.github.com>
type ExtractPayload_extracts_payload = AssertTrue<
IsExact<ExtractPayload<ActionCreatorWithPayload<Payload>>, Payload>
>;
type ExtractPayload_extracts_payload2 = AssertTrue<
Copy link
Contributor

Choose a reason for hiding this comment

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

I love this form of documentation ❤️

Copy link
Contributor

@AlicjaMajewska AlicjaMajewska left a comment

Choose a reason for hiding this comment

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

Great work 💯

@sseppola sseppola changed the title fix: Refactor ActionWithPayload/ActionWithoutPayload to be uniform feat: Refactor ActionWithPayload/ActionWithoutPayload to be uniform May 17, 2023
@sseppola sseppola merged commit 05c138a into master May 17, 2023
@sseppola sseppola deleted the feat/refactorActionType branch May 17, 2023 14:45
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.

4 participants