You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(no-inline-implementation): allow built-in higher level guards with xstate v5
Parse "guard" as the guard declaration in xstate v5. Always allow the built-in higher level guards
to be inlined. Change the option "serviceCreatorRegex" to "actorCreatorRegex".
BREAKING CHANGE: Option "serviceCreatorRegex" has been renamed to "actorCreatorRegex".
Copy file name to clipboardExpand all lines: docs/rules/no-inline-implementation.md
+39-9Lines changed: 39 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,16 @@ Suggest moving implementations of actions, guards, activities and services into
7
7
Action/guard/activity/service implementation can be quickly prototyped by specifying inline functions directly in the machine config.
8
8
Although this is convenient, this makes it difficult to debug, test, serialize and accurately visualize actions. It is recommended to refactor inline implementations into the machine options object.
9
9
10
+
### XState v5
11
+
12
+
In XState v5 some built-in action creators were removed, so this rule will report an error when they are inlined:
13
+
-`respond`
14
+
-`send`: removed in favor of `raise` and `sendParent`
15
+
-`sendUpdate`
16
+
-`start`
17
+
18
+
XState v5 provides some built-in higher level guards: `and`, `or`, `not`, `stateIn`. These are always fine to use.
19
+
10
20
Examples of **incorrect** code for this rule:
11
21
12
22
```javascript
@@ -104,42 +114,62 @@ createMachine({
104
114
})
105
115
106
116
// ✅ inlined guard creator calls are ok if they match guardCreatorRegex
|`allowKnownActionCreators`| No |`false`| Inlined action creators are visualized properly (but still difficult to test, debug and serialize). Setting this option to `true` will turn off the rule for [known action creators](https://xstate.js.org/docs/guides/actions.html) used inline. |
154
184
|`guardCreatorRegex`| No |`''`| Use a regular expression to allow custom guard creators. |
155
185
|`actionCreatorRegex`| No |`''`| Use a regular expression to allow custom action creators. |
156
-
|`serviceCreatorRegex`| No |`''`| Use a regular expression to allow custom service creators. |
186
+
|`actorCreatorRegex`| No |`''`| Use a regular expression to allow custom actor creators. |
0 commit comments