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

Deep initials #1041

Merged
merged 11 commits into from
Mar 8, 2020
Merged

Deep initials #1041

merged 11 commits into from
Mar 8, 2020

Conversation

Andarist
Copy link
Member

@Andarist Andarist commented Mar 3, 2020

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2020

🦋 Changeset is good to go

Latest commit: b24e47b

We got this.

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 3, 2020

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

Sandbox Source
relaxed-hugle-dj2th Configuration
misty-surf-x8l6l Configuration

@davidkpiano
Copy link
Member

I believe this will conflict with mine in the v5/microstep branch, which represents initial as a transition (InitialTransitionDefinition) rather than an array of states.

The transition definition's .target property can specify 1 or more state nodes, as this PR does.

Can you compare it to that branch? I'll make a PR for that soon

const mutStatesToEnter = new Set<StateNode<TContext, any, TEvent>>();
const mutStatesForDefaultEntry = new Set<StateNode<TContext, any, TEvent>>();

computeEntrySet(
Copy link
Member Author

Choose a reason for hiding this comment

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

this is quite hacky but solves the problem of resolving initial states recursively with the existing algorithm

i would like to refactor this in the future, but for the time being it seems OK - @davidkpiano's work on representing initial states as transitions will affect this anyway, so that would be a good time to refactor this

stateKey: string
): StateNode<TContext, any, TEvent> {
stateKey: string,
discardInvalidNodes: boolean = false
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like this flag at all, will look into removing it in the future. This has been introduced solely to pass this test:
https://github.com/davidkpiano/xstate/blob/797a53ad88767f649580628380bbdf86e9fc8a0c/packages/core/test/invalid.test.ts#L50
I'm not convinced if we should bother with this within core algorithms - it would be way easier if we could just assume valid values/configurations. If one migrates their schema they should be responsible for resolving conflicts - especially because we can't resolve all of them and a decision on how to migrate removed regions would be better done on the developer's side.

Copy link
Member Author

Choose a reason for hiding this comment

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

@davidkpiano thoughts on this one? should we bother "fixing" invalid inputs in the core?

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't, you're right. Let's assume valid values/configs.

});
} else {
getEffectiveTargetStates(
{ target: resolveHistoryTarget(s) } as TransitionDefinition<TC, TE>,
Copy link
Member Author

Choose a reason for hiding this comment

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

this is also a hack, as the only thing actually needed by getEffectiveTargetStates is the target property, but this will be refactored once we add a default transition to history states, that can be done in a followup PR after both this PR and the microstep work lands on the next branch

@@ -243,7 +241,6 @@ export function getValue<TC, TE extends EventObject>(
configuration: Configuration<TC, TE>
): StateValue {
const config = getConfiguration([rootNode], configuration);
Copy link
Member Author

Choose a reason for hiding this comment

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

im not sure why this accepts 2 arguments, i've removed the "prevStateNodes" one and all tests pass without it, should I remove it in a followup PR?

@@ -86,7 +86,6 @@ describe('algorithm', () => {
'a',
'b1',
'c1',
'c2',
Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed the implementation of the getConfiguration slightly and this was the only test that has failed in the result. As mentioned in another comment - I don't know why getStateNodes accepts prevNodes. What's the exact purpose of getConfiguration? I use it to resolve initial nodes & ancestors of input nodes.

Copy link
Member Author

Choose a reason for hiding this comment

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

@davidkpiano would love your commentary on that

Copy link
Member

Choose a reason for hiding this comment

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

The previous state nodes are needed if only a partial configuration was given, e.g., if a compound node was given and not the child nodes, we can determine the child nodes from the previous config.

Copy link
Member Author

Choose a reason for hiding this comment

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

So is this intended as the public API? Because as far as I can tell such a situation never happens internally.

Copy link
Member

Choose a reason for hiding this comment

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

Not public API. Can safely be removed.

@Andarist Andarist marked this pull request as ready for review March 4, 2020 16:04
@Andarist Andarist merged commit abc31bf into next Mar 8, 2020
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

2 participants