Skip to content

Commit

Permalink
Remove some typegen-specific types (#4600)
Browse files Browse the repository at this point in the history
* Remove a bunch of typegen types

* interpreter.ts -> createActor.ts

* Remove offending tests

* Deprecate AreAllImplementationsAssumedToBeProvided

* remove more stuff

* Remove redundant test cases

* Add changeset

* Update .changeset/mean-pillows-move.md

Co-authored-by: Mateusz Burzyński <[email protected]>

---------

Co-authored-by: Mateusz Burzyński <[email protected]>
  • Loading branch information
davidkpiano and Andarist authored Dec 23, 2023
1 parent 4dde96a commit 1f2ccb9
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 994 deletions.
8 changes: 8 additions & 0 deletions .changeset/mean-pillows-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@xstate/svelte': patch
'@xstate/react': patch
'@xstate/vue': patch
'xstate': patch
---

Typegen-based types for detecting missing implementations have been removed internally.
86 changes: 25 additions & 61 deletions packages/core/src/State.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isDevelopment from '#is-development';
import { $$ACTOR_TYPE } from './interpreter.ts';
import { $$ACTOR_TYPE } from './createActor.ts';
import type { StateNode } from './StateNode.ts';
import type { StateMachine } from './StateMachine.ts';
import { getStateValue } from './stateUtils.ts';
Expand Down Expand Up @@ -52,7 +52,7 @@ interface MachineSnapshotBase<
TStateValue extends StateValue,
TTag extends string,
TOutput,
TResolvedTypesMeta = TypegenDisabled
_TUnusedButLeftForCompatReasons = never
> {
machine: StateMachine<
TContext,
Expand All @@ -65,8 +65,7 @@ interface MachineSnapshotBase<
TStateValue,
TTag,
unknown,
TOutput,
TResolvedTypesMeta
TOutput
>;
tags: Set<string>;
value: TStateValue;
Expand Down Expand Up @@ -95,8 +94,7 @@ interface MachineSnapshotBase<
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>,
testValue: ToTestStateValue<TStateValue>
) => boolean;
Expand All @@ -112,8 +110,7 @@ interface MachineSnapshotBase<
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>,
tag: TTag
) => boolean;
Expand All @@ -133,8 +130,7 @@ interface MachineSnapshotBase<
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>,
event: TEvent
) => boolean;
Expand All @@ -146,8 +142,7 @@ interface MachineSnapshotBase<
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>
) => Record<string, any>;

Expand All @@ -158,8 +153,7 @@ interface MachineSnapshotBase<
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>
) => unknown;
}
Expand All @@ -170,16 +164,14 @@ interface ActiveMachineSnapshot<
TChildren extends Record<string, AnyActorRef | undefined>,
TStateValue extends StateValue,
TTag extends string,
TOutput,
TResolvedTypesMeta = TypegenDisabled
TOutput
> extends MachineSnapshotBase<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
> {
status: 'active';
output: undefined;
Expand All @@ -192,16 +184,14 @@ interface DoneMachineSnapshot<
TChildren extends Record<string, AnyActorRef | undefined>,
TStateValue extends StateValue,
TTag extends string,
TOutput,
TResolvedTypesMeta = TypegenDisabled
TOutput
> extends MachineSnapshotBase<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
> {
status: 'done';
output: TOutput;
Expand All @@ -214,16 +204,14 @@ interface ErrorMachineSnapshot<
TChildren extends Record<string, AnyActorRef | undefined>,
TStateValue extends StateValue,
TTag extends string,
TOutput,
TResolvedTypesMeta = TypegenDisabled
TOutput
> extends MachineSnapshotBase<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
> {
status: 'error';
output: undefined;
Expand All @@ -236,16 +224,14 @@ interface StoppedMachineSnapshot<
TChildren extends Record<string, AnyActorRef | undefined>,
TStateValue extends StateValue,
TTag extends string,
TOutput,
TResolvedTypesMeta = TypegenDisabled
TOutput
> extends MachineSnapshotBase<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
> {
status: 'stopped';
output: undefined;
Expand All @@ -259,43 +245,32 @@ export type MachineSnapshot<
TStateValue extends StateValue,
TTag extends string,
TOutput,
TResolvedTypesMeta = TypegenDisabled
_TUnusedButLeftForCompatReasons = never
> =
| ActiveMachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
>
| DoneMachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>
| DoneMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput>
| ErrorMachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>
| StoppedMachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>;

const machineSnapshotMatches = function matches(
Expand Down Expand Up @@ -363,20 +338,11 @@ export function createMachineSnapshot<
TEvent extends EventObject,
TChildren extends Record<string, AnyActorRef | undefined>,
TStateValue extends StateValue,
TTag extends string,
TResolvedTypesMeta = TypegenDisabled
TTag extends string
>(
config: StateConfig<TContext, TEvent>,
machine: AnyStateMachine
): MachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
undefined,
TResolvedTypesMeta
> {
): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, undefined> {
return {
status: config.status as never,
output: config.output,
Expand Down Expand Up @@ -412,17 +378,15 @@ export function getPersistedSnapshot<
TChildren extends Record<string, AnyActorRef | undefined>,
TStateValue extends StateValue,
TTag extends string,
TOutput,
TResolvedTypesMeta = TypegenDisabled
TOutput
>(
snapshot: MachineSnapshot<
TContext,
TEvent,
TChildren,
TStateValue,
TTag,
TOutput,
TResolvedTypesMeta
TOutput
>,
options?: unknown
): Snapshot<unknown> {
Expand Down
Loading

0 comments on commit 1f2ccb9

Please sign in to comment.