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

[core] Bind .provide(…) #4871

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/soft-rats-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'xstate': patch
---

The `.provide(…)` method will now work as expected when implementing higher-level logic for machines.

See https://github.com/statelyai/xstate/issues/4868 for the original issue.
1 change: 1 addition & 0 deletions packages/core/src/StateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export class StateMachine<
this.getPersistedSnapshot = this.getPersistedSnapshot.bind(this);
this.restoreSnapshot = this.restoreSnapshot.bind(this);
this.start = this.start.bind(this);
this.provide = this.provide.bind(this);

this.root = new StateNode(config, {
_key: this.id,
Expand Down
9 changes: 9 additions & 0 deletions packages/core/test/actorLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,4 +1031,13 @@
})
);
});

it('higher-level machine logic should work with persist()', () => {
const machine = createMachine({});
const customLogic = {
...machine
};

expect(customLogic.provide).toBeDefined();

Check failure on line 1041 in packages/core/test/actorLogic.test.ts

View workflow job for this annotation

GitHub Actions / build

Property 'provide' does not exist on type '{ version?: string | undefined; schemas: unknown; implementations: MachineImplementationsSimplified<MachineContext, AnyEventObject, ProvidedActor, ParameterizedObject, ParameterizedObject>; ... 7 more ...; __TResolvedTypesMeta: ResolveTypegenMeta<...>; }'.
});
});
Loading