Skip to content

[v5] Remove state.history#2882

Merged
davidkpiano merged 4 commits intonextfrom
v5/remove-state-history
Dec 23, 2021
Merged

[v5] Remove state.history#2882
davidkpiano merged 4 commits intonextfrom
v5/remove-state-history

Conversation

@davidkpiano
Copy link
Member

This PR removes the history property from the State object, for these reasons:

  • state.history breaks immutability from states since every penultimate state.history is deleted to prevent memory leaks
  • state.history is not used for the statechart history mechanism (state.historyValue is, and that is staying)
  • Users can/should keep track of previous state(s) themselves

I'm still on the fence whether this should be completely removed or just renamed to state.previous (cc. @Andarist) - I'd like to get an idea of how useful accessing the previous state is from within the machine, which is the most compelling use-case to keep this feature.

Note: This does not remove the history mechanism from XState machines.

@davidkpiano davidkpiano requested a review from Andarist December 20, 2021 17:38
@changeset-bot
Copy link

changeset-bot bot commented Dec 20, 2021

🦋 Changeset detected

Latest commit: 0096d9f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
xstate Major
@xstate/graph Major
@xstate/immer Major
@xstate/inspect Major
@xstate/react Major
@xstate/svelte Major
@xstate/test Major
@xstate/vue Major

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

@ghost
Copy link

ghost commented Dec 20, 2021

CodeSee Review Map:

Review these changes using an interactive CodeSee Map

Review in an interactive map

View more CodeSee Maps

Legend

CodeSee Map Legend

"count": 1,
"currentWeight": 1,
"relativeWeight": 1,
"count": 2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, it's somewhat surprising that this has been affected anyhow by this PR. Do you know why that is?

Copy link
Collaborator

Choose a reason for hiding this comment

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

👋

Copy link
Member Author

Choose a reason for hiding this comment

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

Disregard this, I want to rework @xstate/analytics (very old project) before releasing it.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason this has been affected is because it was using state.history, but now we have to use something different (which I added).

@Andarist
Copy link
Collaborator

Andarist commented Dec 21, 2021

I'm still on the fence whether this should be completely removed or just renamed to state.previous (cc. @Andarist)

Renaming would have the same downsides as the current solution. I think it's safe to remove this completely and to figure out a better solution in the future IF we find any compelling use cases to provide access to this.

@davidkpiano davidkpiano merged commit 606dc99 into next Dec 23, 2021
@davidkpiano davidkpiano deleted the v5/remove-state-history branch December 23, 2021 13:05
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.

2 participants