Skip to content

Commit 882c9e5

Browse files
Remove prepend (#94)
* Bump pnpm * Add mantine to dev deps * Add type-test for mantine button * Make Mantine edge-case partially work * Add expect type checks * Try to fix other operators * Add notice to the docs * bump ts and update tests * Remove unused import * Update variant tests * Add another example * Remove prepend from docs and type-tests
1 parent e7ea886 commit 882c9e5

File tree

4 files changed

+5
-36
lines changed

4 files changed

+5
-36
lines changed

docs/pages/docs/reflect.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@ const $name = restore(changeName, '');
5151
const changeAge = createEvent<number>();
5252
const $age = restore(changeAge, 0);
5353

54-
const inputChanged = (event: ChangeEvent<HTMLInputElement>) => {
55-
return event.currentTarget.value;
56-
};
5754

5855
// Components
5956
const Name = reflect({
6057
view: Input,
6158
bind: {
6259
value: $name,
6360
placeholder: 'Name',
64-
onChange: changeName.prepend(inputChanged),
61+
onChange: (event) => changeName(event.currentTarget.value),
6562
},
6663
});
6764

@@ -70,7 +67,7 @@ const Age = reflect({
7067
bind: {
7168
value: $age,
7269
placeholder: 'Age',
73-
onChange: changeAge.prepend(parseInt).prepend(inputChanged),
70+
onChange: (event) => changeAge(parseInt(event.currentTarget.value)),
7471
},
7572
});
7673

docs/pages/learn/testing.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ Since [effector-react 22.5.0](https://github.com/effector/effector/releases/tag/
44

55
Just add `Provider` from `effector-react` to your app root, and you are good to go.
66

7-
For [SSR](https://effector.dev/docs/api/effector-react/useEvent) and `effector-react` before `2.5.0` release you will need to replace imports `@effector/reflect` -> `@effector/reflect/ssr`.
8-
9-
Also for this case you need to use `event.prepend(params => params.something)` instead `(params) => event(params.something)` in `bind` - this way `reflect` can detect effector's events and properly bind them to the current [scope](https://effector.dev/docs/api/effector/scope)
10-
117
```tsx
128
// ./ui.tsx
139
import React, { ChangeEvent, FC, MouseEvent, useCallback } from 'react';
@@ -49,7 +45,7 @@ const Name = reflect({
4945
view: Input,
5046
bind: {
5147
value: $name,
52-
onChange: changeName.prepend((event) => event.target.value),
48+
onChange: (event) => changeName(event.target.value),
5349
},
5450
});
5551

public-types/reflect.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type FinalProps<Props, Bind extends BindFromProps<Props>> = Show<
6464
* bind: {
6565
* value: $name,
6666
* placeholder: 'Name',
67-
* onChange: changeName.prepend(inputChanged),
67+
* onChange: (event) => nameChanged(event.target.value),
6868
* },
6969
* });
7070
* ```
@@ -100,7 +100,7 @@ export function reflect<
100100
* const Name = reflectInput({
101101
* value: $name,
102102
* placeholder: 'Name',
103-
* onChange: changeName.prepend(inputChanged),
103+
* onChange: (event) => nameChanged(event.target.value),
104104
* });
105105
* ```
106106
*/

type-tests/types-reflect.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,6 @@ import { expectType } from 'tsd';
3535
expectType<React.FC>(ReflectedInput);
3636
}
3737

38-
// reflect allows infer handlers for event.prepend
39-
{
40-
const Input: React.FC<{
41-
value: string;
42-
onChange: (event: { target: { value: string } }) => void;
43-
}> = () => null;
44-
const $value = createStore<string>('');
45-
const changed = createEvent<string>();
46-
47-
const ReflectedInput = reflect({
48-
view: Input,
49-
bind: {
50-
value: $value,
51-
// here typescript should infer types correctly
52-
onChange: changed.prepend((e) => {
53-
expectType<string>(e.target.value);
54-
return e.target.value;
55-
}),
56-
},
57-
});
58-
59-
expectType<React.FC>(ReflectedInput);
60-
}
61-
6238
// reflect should not allow wrong props
6339
{
6440
const Input: React.FC<{

0 commit comments

Comments
 (0)