Skip to content

Commit 7e4beee

Browse files
author
Sergey Sova
committed
add effector
1 parent ad95d3e commit 7e4beee

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ in your browser, and click the button very quickly. (check the console log)
291291
check with intensive auto increment
292292
✓ check 8: updated properly with auto increment (2944 ms)
293293
✕ check 9: no tearing with auto increment (1 ms)
294+
effector
295+
check with events from outside
296+
✓ check 1: updated properly (3249 ms)
297+
✕ check 2: no tearing during update (22 ms)
298+
✓ check 3: ability to interrupt render
299+
✓ check 4: proper update after interrupt (1518 ms)
300+
check with useTransition
301+
✓ check 5: updated properly with transition (3533 ms)
302+
✕ check 6: no tearing with transition (2 ms)
303+
✕ check 7: proper branching with transition (5423 ms)
304+
check with intensive auto increment
305+
✓ check 8: updated properly with auto increment (3055 ms)
306+
✕ check 9: no tearing with auto increment (2 ms)
294307
```
295308

296309
</details>
@@ -438,7 +451,7 @@ in your browser, and click the button very quickly. (check the console log)
438451
<td>:white_check_mark:</td>
439452
<td>:white_check_mark:</td>
440453
</tr>
441-
454+
442455
</tr>
443456
<th><a href="https://github.com/mobxjs/mobx-react-lite">mobx-react-lite</a></th>
444457
<td>:white_check_mark:</td>
@@ -528,6 +541,19 @@ in your browser, and click the button very quickly. (check the console log)
528541
<td>:white_check_mark:</td>
529542
<td>:x:</td>
530543
</tr>
544+
545+
<tr>
546+
<th><a href="https://github.com/zerobias/effector">effector</a></th>
547+
<td>:white_check_mark:</td>
548+
<td>:x:</td>
549+
<td>:white_check_mark:</td>
550+
<td>:white_check_mark:</td>
551+
<td>:white_check_mark:</td>
552+
<td>:x:</td>
553+
<td>:x:</td>
554+
<td>:white_check_mark:</td>
555+
<td>:x:</td>
556+
</tr>
531557
</table>
532558

533559
## Caution

__tests__/all_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const names = [
2121
'simplux',
2222
'react-apollo',
2323
'recoil',
24+
'effector',
2425
];
2526

2627
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"build:simplux": "cross-env NAME=simplux webpack",
3434
"build:react-apollo": "cross-env NAME=react-apollo webpack",
3535
"build:recoil": "cross-env NAME=recoil webpack",
36+
"build:effector": "cross-env NAME=effector webpack",
3637
"build-all": "run-s build:*"
3738
},
3839
"keywords": [
@@ -49,6 +50,8 @@
4950
"@simplux/react": "^0.13.0",
5051
"apollo-boost": "^0.4.9",
5152
"constate": "^2.0.0",
53+
"effector": "^20.15.0",
54+
"effector-react": "^20.7.2",
5255
"graphql": "^15.0.0",
5356
"mobx": "^5.15.4",
5457
"mobx-react-lite": "^2.0.6",

src/effector/index.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React, { unstable_useTransition as useTransition } from 'react';
2+
import { createStore, createEvent } from 'effector';
3+
import { useStore } from 'effector-react';
4+
5+
import {
6+
ids,
7+
initialState,
8+
reducer,
9+
syncBlock,
10+
useCheckTearing,
11+
useRegisterIncrementDispatcher,
12+
} from '../common';
13+
14+
const dispatch = createEvent();
15+
const $store = createStore(initialState)
16+
.on(dispatch, reducer);
17+
18+
const $count = $store.map((value) => value.count);
19+
20+
$store.watch((s) => console.log('store', s));
21+
$count.watch((c) => console.log('count', c));
22+
23+
const Counter = React.memo(() => {
24+
const count = useStore($count);
25+
syncBlock();
26+
return <div className="count">{count}</div>;
27+
});
28+
29+
const Main = () => {
30+
const count = useStore($count);
31+
useCheckTearing();
32+
useRegisterIncrementDispatcher(React.useCallback(() => {
33+
dispatch({ type: 'increment' });
34+
}, []));
35+
const [localCount, localIncrement] = React.useReducer((c) => c + 1, 0);
36+
const normalIncrement = () => {
37+
dispatch({ type: 'increment' });
38+
};
39+
const [startTransition, isPending] = useTransition();
40+
const transitionIncrement = () => {
41+
startTransition(() => {
42+
dispatch({ type: 'increment' });
43+
});
44+
};
45+
return (
46+
<div>
47+
<button type="button" id="normalIncrement" onClick={normalIncrement}>Increment shared count normally (two clicks to increment one)</button>
48+
<button type="button" id="transitionIncrement" onClick={transitionIncrement}>Increment shared count in transition (two clicks to increment one)</button>
49+
<span id="pending">{isPending && 'Pending...'}</span>
50+
<h1>Shared Count</h1>
51+
{ids.map((id) => <Counter key={id} />)}
52+
<div className="count">{count}</div>
53+
<h1>Local Count</h1>
54+
{localCount}
55+
<button type="button" id="localIncrement" onClick={localIncrement}>Increment local count</button>
56+
</div>
57+
);
58+
};
59+
60+
const App = () => (
61+
<Main />
62+
);
63+
64+
export default App;

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,18 @@ [email protected]:
31253125
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
31263126
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
31273127

3128+
effector-react@^20.7.2:
3129+
version "20.7.2"
3130+
resolved "https://registry.yarnpkg.com/effector-react/-/effector-react-20.7.2.tgz#e22ab98339b3c8737f0918a9d9fd87c406cd22ca"
3131+
integrity sha512-oVGD6hwKeZtym0lQL7voB09Pb3lFGFJPkQ4TIj8LiGPDTesZvowr3PhnTRIOWFJ1XAjuM/kDSjVZnZikJYeRBg==
3132+
3133+
effector@^20.15.0:
3134+
version "20.15.0"
3135+
resolved "https://registry.yarnpkg.com/effector/-/effector-20.15.0.tgz#5138ca72d2bc7f02cd68236831a7a5a325ddd5df"
3136+
integrity sha512-R1D4mtqL37Jjma+Sjw+QlBuP2nlMS2adROnvK3kmQMHs4MSHuwFYzdw9OVbaG0yL3a2aWsoh6LfdfhP2Ol1ftQ==
3137+
dependencies:
3138+
symbol-observable "^1.2.0"
3139+
31283140
electron-to-chromium@^1.3.413:
31293141
version "1.3.438"
31303142
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.438.tgz#56051a9b148842fec813b113e8070ae892a85920"

0 commit comments

Comments
 (0)