From d9b057cadb135f3210badf23c1839807536143cb Mon Sep 17 00:00:00 2001 From: Kevin Maes Date: Mon, 12 Jun 2023 18:08:15 -0400 Subject: [PATCH 1/5] Explain how `.provide()` can not be called imperatively to override implementations --- versioned_docs/version-5/machines.mdx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/versioned_docs/version-5/machines.mdx b/versioned_docs/version-5/machines.mdx index 35278d908..2f61e9fa1 100644 --- a/versioned_docs/version-5/machines.mdx +++ b/versioned_docs/version-5/machines.mdx @@ -110,7 +110,7 @@ const feedbackMachine = createMachine( delays: { /* ... */ }, - } + }, ); ``` @@ -143,6 +143,26 @@ const feedbackActor = interpret(customFeedbackMachine).start(); // logs 'Doing something custom!' ``` +Note: `machine.provide()` is not imperative but rather returns a new machine that includes the implementation overrides. + +Modifying the previous example, if we were to imperatively call `.provide()` on an existing machine, that would not change the machine’s behavior with our implementations. + +```ts +const feedbackMachine = createMachine({...}); + +feedbackMachine.provide({ + actions: { + doSomething: () => { + console.log('Doing something custom!'); + }, + }, +}); + +// This will NOT utilize the provided implementations. +const feedbackActor = interpret(feedbackMachine).start(); + +``` + ## Specifying types You can specify TypeScript types inside the machine config using the `.types` property: @@ -246,4 +266,4 @@ const machineWithImpls = machine.provide({ /* ... */ }, }); -``` \ No newline at end of file +``` From 2713e4210102a995817508e9a7a286bc954507c2 Mon Sep 17 00:00:00 2001 From: Kevin Maes Date: Sat, 1 Jul 2023 10:50:53 -0400 Subject: [PATCH 2/5] Wrap text in warning admonition --- versioned_docs/version-5/machines.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/versioned_docs/version-5/machines.mdx b/versioned_docs/version-5/machines.mdx index 2f61e9fa1..f43edeb8e 100644 --- a/versioned_docs/version-5/machines.mdx +++ b/versioned_docs/version-5/machines.mdx @@ -143,7 +143,11 @@ const feedbackActor = interpret(customFeedbackMachine).start(); // logs 'Doing something custom!' ``` -Note: `machine.provide()` is not imperative but rather returns a new machine that includes the implementation overrides. +:::warningxstate + +`machine.provide()` is not imperative but rather returns a new machine that includes the implementation overrides. + +::: Modifying the previous example, if we were to imperatively call `.provide()` on an existing machine, that would not change the machine’s behavior with our implementations. From 2114c63eadc13b3fd4c058340f491c4872cf5704 Mon Sep 17 00:00:00 2001 From: Kevin Maes Date: Sat, 1 Jul 2023 10:53:22 -0400 Subject: [PATCH 3/5] Add code example comment specifying not to do what is in the example --- versioned_docs/version-5/machines.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/versioned_docs/version-5/machines.mdx b/versioned_docs/version-5/machines.mdx index f43edeb8e..3de5a5ffb 100644 --- a/versioned_docs/version-5/machines.mdx +++ b/versioned_docs/version-5/machines.mdx @@ -152,6 +152,7 @@ const feedbackActor = interpret(customFeedbackMachine).start(); Modifying the previous example, if we were to imperatively call `.provide()` on an existing machine, that would not change the machine’s behavior with our implementations. ```ts +// Do NOT do this! const feedbackMachine = createMachine({...}); feedbackMachine.provide({ From 7eb8ba52ba210a744b2895a2a05b3ad3c606efd0 Mon Sep 17 00:00:00 2001 From: Kevin Maes Date: Tue, 11 Jul 2023 11:19:17 +0200 Subject: [PATCH 4/5] Wrap the entire bad example in the warning admonition --- versioned_docs/version-5/machines.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/versioned_docs/version-5/machines.mdx b/versioned_docs/version-5/machines.mdx index 3de5a5ffb..c8fa41ebc 100644 --- a/versioned_docs/version-5/machines.mdx +++ b/versioned_docs/version-5/machines.mdx @@ -147,8 +147,6 @@ const feedbackActor = interpret(customFeedbackMachine).start(); `machine.provide()` is not imperative but rather returns a new machine that includes the implementation overrides. -::: - Modifying the previous example, if we were to imperatively call `.provide()` on an existing machine, that would not change the machine’s behavior with our implementations. ```ts @@ -168,6 +166,8 @@ const feedbackActor = interpret(feedbackMachine).start(); ``` +::: + ## Specifying types You can specify TypeScript types inside the machine config using the `.types` property: From 6049ad12095d83ecd313eb89e36c68393f2a9ab0 Mon Sep 17 00:00:00 2001 From: Kevin Maes Date: Tue, 11 Jul 2023 11:24:37 +0200 Subject: [PATCH 5/5] Emphasize the word "not" --- versioned_docs/version-5/machines.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versioned_docs/version-5/machines.mdx b/versioned_docs/version-5/machines.mdx index c8fa41ebc..3c8cf2a08 100644 --- a/versioned_docs/version-5/machines.mdx +++ b/versioned_docs/version-5/machines.mdx @@ -147,7 +147,7 @@ const feedbackActor = interpret(customFeedbackMachine).start(); `machine.provide()` is not imperative but rather returns a new machine that includes the implementation overrides. -Modifying the previous example, if we were to imperatively call `.provide()` on an existing machine, that would not change the machine’s behavior with our implementations. +Modifying the previous example, if we were to imperatively call `.provide()` on an existing machine, that would **not** change the machine’s behavior with our implementations. ```ts // Do NOT do this!