@virentia/effector 0.1.1 → 0.2.0
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/README.md +40 -33
- package/dist/index.cjs +283 -485
- package/dist/index.d.cts +29 -181
- package/dist/index.d.mts +29 -181
- package/dist/index.mjs +284 -472
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -1,60 +1,67 @@
|
|
|
1
1
|
# @virentia/effector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Compatibility with the real Effector package.
|
|
4
4
|
|
|
5
|
-
Use this package when
|
|
6
|
-
|
|
7
|
-
## Links
|
|
8
|
-
|
|
9
|
-
- Documentation: [movpushmov.dev/virentia/effector](https://movpushmov.dev/virentia/effector/)
|
|
5
|
+
Use this package when Virentia models need to call Effector units, or existing Effector chains need to call Virentia units. It does not replace Effector.
|
|
10
6
|
|
|
11
7
|
## Install
|
|
12
8
|
|
|
13
9
|
```sh
|
|
14
|
-
pnpm add @virentia/effector
|
|
10
|
+
pnpm add @virentia/effector effector @virentia/core
|
|
15
11
|
```
|
|
16
12
|
|
|
17
|
-
##
|
|
13
|
+
## Basic usage
|
|
18
14
|
|
|
19
15
|
```ts
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const $count = createStore(0).on(incremented, (count, amount) => count + amount);
|
|
16
|
+
import { scope, scoped } from "@virentia/core";
|
|
17
|
+
import { createEffectorCompatibility } from "@virentia/effector";
|
|
18
|
+
import { allSettled, fork } from "effector";
|
|
24
19
|
|
|
25
|
-
const
|
|
20
|
+
const effector = createEffectorCompatibility();
|
|
21
|
+
const virentiaScope = scope();
|
|
22
|
+
const effectorScope = fork();
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const association = effector.associate({
|
|
25
|
+
virentia: virentiaScope,
|
|
26
|
+
effector: effectorScope,
|
|
30
27
|
});
|
|
31
|
-
|
|
32
|
-
console.log(appScope.getState($count)); // 2
|
|
33
28
|
```
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
A Virentia scope and an Effector scope are required. The association is only a disposable link between them.
|
|
36
31
|
|
|
37
|
-
|
|
38
|
-
const loadUserFx = createEffect<string, { id: string; name: string }>(async (id) => {
|
|
39
|
-
const response = await fetch(`/api/users/${id}`);
|
|
40
|
-
return response.json();
|
|
41
|
-
});
|
|
32
|
+
## Links
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
```ts
|
|
35
|
+
effector.link(virentiaSubmitted, effectorSubmitted, ({ id }) => id);
|
|
36
|
+
|
|
37
|
+
await scoped(virentiaScope, () =>
|
|
38
|
+
allSettled(effectorSubmitted, {
|
|
39
|
+
scope: effectorScope,
|
|
40
|
+
params: "user:1",
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
47
43
|
```
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
The association is only a lifetime handle. Use `scoped`, Effector `allSettled`, `scopeBind`, or UI Providers to choose scopes.
|
|
50
46
|
|
|
51
|
-
##
|
|
47
|
+
## Effector sample
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { sample } from "effector";
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
sample({
|
|
53
|
+
clock: effectorUserClicked,
|
|
54
|
+
source: $session,
|
|
55
|
+
fn: (session, userId) => ({ userId, token: session.token }),
|
|
56
|
+
target: effector.asEffector(virentiaUserOpened),
|
|
57
|
+
});
|
|
58
|
+
```
|
|
54
59
|
|
|
55
|
-
##
|
|
60
|
+
## Tests
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
```sh
|
|
63
|
+
pnpm --filter @virentia/effector test
|
|
64
|
+
```
|
|
58
65
|
|
|
59
66
|
## License
|
|
60
67
|
|