-
Notifications
You must be signed in to change notification settings - Fork 781
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
Update Types #1047
Update Types #1047
Conversation
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.
Overall I really like this update! 👍 👍 The utility types I could take or leave but the rest is great. I haven't actually tried it out in practice yet but I trust @icylace ;)
There is one thing I've been thinking about though. And it is the names of Action
, ActionTransform
and ActionWithPayload
.
As I see it, the one that users will most commonly import and use in their own code will be ActionTransform
. The others will mainly be used when users implement their own effects & subs I think.
So, compare:
const Add : ActionTransform<State, number> = (state, amount) => ({...
vs
const Add: Action<State, number> = (state, amount) => ({...
I would prefer the latter. I know - the latter already actually works, probably anyway, but I feel like there is something wrong with defining a const as some type which is actually a union type.
So I'm thinking what if we could rename:
ActionTransform
-> Action
Action
-> ??? maybe Handler
? or ActionType
Or just get rid of the current Action
and inline Action | ActionWithPayload
where it was.
... or of course we could leave things as they are for now and think more about this. But I wanted to raise the question anyway.
Works for me! 👍 |
I'd rather keep Also, there's another option: const Add = (state: State, amount: number): State => ({... |
Yeah if you're using the current But I do think we should keep considering renaming it to something else to free up the name "Action" to be used in place of "ActionTransform". The more I think about it the more important I think this is. At least, when I say "action" I always mean the function. I never think of or explain |
Makes sense to me. 👍 |
Just renamed |
Latest change removes |
Just updated the PR with the following changes:
|
Do you think you can make a CodeSandbox example or share a snippet to can see how you're using these types? |
Yeah, I'll be doing something along those lines to show how to use these types. Up until now I've been relying on my test suite to work them out but that code is not necessarily approachable. |
This PR was originally about
App<S>
but has evolved into a pervasive update.Changelog:
TypedH<S>
. It lets you define a version ofh
that has your app's state type "baked in" so you don't need to worry about whether or not you need to explicitly assign the generic type parameter forh
every time you call it.TypedH<S>
type. #1049AllOrNothing<T>
,AtLeastOne<T>
, andIndexableByKey
. They assist the implementation of some of the other types which are refactored accordingly.App<S>
to validate all combinations ofapp()
props usage.h("p", { onclick: [MyAction, 42] }, text("hi"))
.payload
parameter ofEffecter<S, P>
andSubscriber<S, P>
definite.EffectCreator<S, D>
. I don't believe it adds enough value even on a purely self-documenting code basis.Payload<P>
because in the places where it could appear either a parameter name or named tuple could express the same level of detail.State<S>
for partially the same reason as removingPayload<P>
. Another reason was I wanted to prevent potential confusion on the user's end about whetherState<S>
is required like howStateWithEffects<S>
is.Dispatchable<S>
. It simplifies a couple type definitions while adding more meaning. It can also be handy to the user when defining effecters and subscribers.Payload<P>
andState<S>
.types
reference toindex.d.ts
inpackage.json
per @talentlessguy's suggestion.Original PR title and text for posterity:
Improve the
App
typeThis fixes certain cases when using
App
. I've also added a little more commentary in some parts of the type definitions.Here are the relevant lines in the types test suite if you're curious: