@mittwald/flow-react-components 1.2.0-next.32 → 1.2.0-next.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MIGRATION.md
CHANGED
|
@@ -1011,18 +1011,39 @@ Only function **references** are affected. An inline arrow
|
|
|
1011
1011
|
(`onAction={() => …}`), a zero-parameter function, and anything already
|
|
1012
1012
|
accepting `unknown` are all fine.
|
|
1013
1013
|
|
|
1014
|
-
A codemod renames the prop
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1014
|
+
A codemod renames the prop and wraps the reference.
|
|
1015
|
+
|
|
1016
|
+
Whether a reference _needs_ wrapping is not decidable from the source — that
|
|
1017
|
+
needs type information. Performing the wrap does not need it: `() => fn()` calls
|
|
1018
|
+
what `Action` would have called, and `onAction` takes no arguments. So the wrap
|
|
1019
|
+
fixes the reference that needed it and changes nothing for the rest, which makes
|
|
1020
|
+
the decision unnecessary.
|
|
1021
|
+
|
|
1022
|
+
Wrapped: a plain identifier and a member expression (`close`,
|
|
1023
|
+
`controller.close`, `this.handleSave`). Left alone: an arrow function and a
|
|
1024
|
+
function expression, which already are the handler; a call (`makeHandler()`,
|
|
1025
|
+
`close.bind(controller)`), which produces it; and anything that is not one
|
|
1026
|
+
reference (`isOpen ? close : open`, `onClose ?? noop`, `controller?.close`).
|
|
1027
|
+
|
|
1028
|
+
Two wraps are worth a look afterwards. A handler that read the event `Action`
|
|
1029
|
+
forwards — undocumented, but it does forward the trigger's event — stops
|
|
1030
|
+
receiving it. And `onAction={props.onAction}`, where the reference may be
|
|
1031
|
+
`undefined`: passing it was fine, calling it is not, so TypeScript now reports
|
|
1032
|
+
the call and wants a guard.
|
|
1018
1033
|
|
|
1019
1034
|
**Apply:** Rename the `action` prop on `Action` to `onAction`. Not only a
|
|
1020
1035
|
rename: the new prop is typed `ActionFn` (`(...args: unknown[]) => unknown`), so
|
|
1021
1036
|
a function _reference_ that declares a parameter no longer type-checks and needs
|
|
1022
1037
|
wrapping — `onAction={() => controller.close()}` rather than
|
|
1023
|
-
`onAction={controller.close}`.
|
|
1024
|
-
|
|
1025
|
-
|
|
1038
|
+
`onAction={controller.close}`. A codemod does both. It wraps every bare
|
|
1039
|
+
reference (`close`, `controller.close`), because the wrap is a no-op for a
|
|
1040
|
+
reference that did not need it. It leaves a value that already is the handler or
|
|
1041
|
+
produces one — an arrow function, a function expression, a call like
|
|
1042
|
+
`makeHandler()` or `close.bind(controller)` — and anything that is not one
|
|
1043
|
+
reference, such as `isOpen ? close : open` or `controller?.close`. Two wraps to
|
|
1044
|
+
look at afterwards: a handler that read the event `Action` forwards stops
|
|
1045
|
+
receiving it, and a possibly-undefined reference (`onAction={props.onAction}`)
|
|
1046
|
+
becomes a call TypeScript rejects — add the guard it asks for.
|
|
1026
1047
|
|
|
1027
1048
|
```shell
|
|
1028
1049
|
npx @mittwald/flow-codemods@latest action-prop-to-on-action src
|