-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Feature: createModel() #1439
Feature: createModel() #1439
Conversation
🦋 Changeset detectedLatest commit: a4e129c The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 b04f5c8:
|
I was just thinking about how the current uncertainty around #989 and #1367 confounds this effort. The API surface area gets less elegant when once you have to require the developer to differentiate between But that begs the question... does it even make sense for the entire model shape to change (as in the |
Most of the time it doesn't, but there are usecases highlighted in those issues that demonstrate the need. |
Oh, for sure - definitely didn't mean to come across as dismissive of those needs at all. Just thinking aloud today as the 💡 slowly flickered on in my head, realizing that those concerns were really about the friction of representing a union type using a key/value store. (And the SCXML spec has essentially mandated a key/value store as the root data model type.) The imperfect emulation of that, and all the effort to emulate it, falls away when storing that union type as keyed value instead. Bonus: language support starts to come into play (both in TypeScript and Swift--which has enums with associated values). Obvious in retrospect, but I was just not seeing it clearly before. I think that means this cool new |
@@ -936,14 +951,18 @@ export type Assigner<TContext, TEvent extends EventObject> = ( | |||
meta: AssignMeta<TContext, TEvent> | |||
) => Partial<TContext>; | |||
|
|||
export type PartialAssigner< |
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.
I kinda feel like it would be more appropriate to name this a PropertyAssigner
and the other one a PartialAssigner
😅
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.
I know... we can change this for v5
packages/core/src/types.ts
Outdated
export interface TransitionConfig<TContext, TEvent extends EventObject> { | ||
cond?: Condition<TContext, TEvent>; | ||
actions?: Actions<TContext, TEvent>; | ||
export type RestrictedActions< |
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.
is this used anywhere? cant find any reference to this 🤔
@@ -224,6 +231,33 @@ describe('assign', () => { | |||
maybe: 'defined' | |||
}); | |||
}); | |||
|
|||
it('can assign from event', () => { |
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.
q: is this here just to validate types?
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.
Yep!
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.
This version feels better than some previous iterations with withAssigners
etc 👍 Good job.
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.
Please just remember about adding the appropriate changeset so the changelog entry gets correct attribution to PR etc :)
packages/core/src/types.ts
Outdated
TEvent extends { type: K } ? TEvent : never | ||
>; | ||
export type TransitionsConfigMap<TContext, TEvent extends EventObject> = { | ||
[K in TEvent['type']]?: TransitionConfigOrTarget<TContext, TEvent, K>; |
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.
Any particular reason behind this change? 🤔 seems a little bit stranger to pass TEvent
and K
around and compute at the end rather than pass a computed TEvent
from here
is it about TransitionConfigTarget
including a StateNode
target? wouldn't it be better to allow there any
at the TEvent
position as we should be able to target any state node in the given machine config? As this is going to be removed in v5 anyway (targeting with getters etc) I'm not sure if it's worth complicating the codebase for its sake
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.
I think this is an accidental commit, thanks for catching.
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.
Oh, I just discovered one of the reasons for this change: the raise()
event needs to be able to infer all possible events.
type: 'ALOHA' | ||
}), | ||
}) as any /* TODO: FIX */, |
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.
Hm, I've wanted to look into it and I've checked out your branch locally but after removing those casts and comments I couldn't see any TS errors. Could you recheck on your machine? That being said - inferred generics are off and I don't understand why the inferred type is assignable here to the expected one 😭
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.
Hm, I'll keep the comment in here for now.
This PR adds support for an opt-in helper function called
createModel()
, which is meant to assist in creating the datamodel (SCXML) for the machine: