From b0805282b9e617dbfab8efbac618e5aca3cf2754 Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Fri, 26 Apr 2024 10:36:13 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Bind=20.provide(=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/StateMachine.ts | 1 + packages/core/test/actorLogic.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/packages/core/src/StateMachine.ts b/packages/core/src/StateMachine.ts index d204aff983..8e3ad26958 100644 --- a/packages/core/src/StateMachine.ts +++ b/packages/core/src/StateMachine.ts @@ -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, diff --git a/packages/core/test/actorLogic.test.ts b/packages/core/test/actorLogic.test.ts index 9cba36d698..4d528886ef 100644 --- a/packages/core/test/actorLogic.test.ts +++ b/packages/core/test/actorLogic.test.ts @@ -1031,4 +1031,13 @@ describe('composable actor logic', () => { }) ); }); + + it('higher-level machine logic should work with persist()', () => { + const machine = createMachine({}); + const customLogic = { + ...machine + }; + + expect(customLogic.provide).toBeDefined(); + }); }); From 991689411db797467bb0b5f985c67caa3143bab2 Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Mon, 29 Apr 2024 20:32:42 -0400 Subject: [PATCH 2/2] Changeset --- .changeset/soft-rats-battle.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/soft-rats-battle.md diff --git a/.changeset/soft-rats-battle.md b/.changeset/soft-rats-battle.md new file mode 100644 index 0000000000..f11728d10f --- /dev/null +++ b/.changeset/soft-rats-battle.md @@ -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.