@virentia/effector 0.1.0 → 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 CHANGED
@@ -1,60 +1,67 @@
1
1
  # @virentia/effector
2
2
 
3
- Effector-shaped compatibility layer powered by `@virentia/core`.
3
+ Compatibility with the real Effector package.
4
4
 
5
- Use this package when existing code already has an Effector-style shape and you want to run it on Virentia primitives.
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
- ## Counter
13
+ ## Basic usage
18
14
 
19
15
  ```ts
20
- import { allSettled, createEvent, createStore, fork } from "@virentia/effector";
21
-
22
- const incremented = createEvent<number>();
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 appScope = fork();
20
+ const effector = createEffectorCompatibility();
21
+ const virentiaScope = scope();
22
+ const effectorScope = fork();
26
23
 
27
- await allSettled(incremented, {
28
- scope: appScope,
29
- params: 2,
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
- ## Effects
30
+ A Virentia scope and an Effector scope are required. The association is only a disposable link between them.
36
31
 
37
- ```ts
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
- const result = await allSettled(loadUserFx, {
44
- scope: appScope,
45
- params: "user:1",
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
- Effects expose Effector-shaped lifecycle units: `done`, `fail`, `finally`, `doneData`, `failData`, `pending`, and `inFlight`.
45
+ The association is only a lifetime handle. Use `scoped`, Effector `allSettled`, `scopeBind`, or UI Providers to choose scopes.
50
46
 
51
- ## Main API
47
+ ## Effector sample
48
+
49
+ ```ts
50
+ import { sample } from "effector";
52
51
 
53
- `createEvent`, `createStore`, `createEffect`, `sample`, `combine`, `split`, `createApi`, `restore`, `attach`, `fork`, `allSettled`, `serialize`, `hydrate`, `scopeBind`, `is`.
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
- ## Notes
60
+ ## Tests
56
61
 
57
- The bridge keeps Effector-shaped names around Virentia core primitives. `fork` creates a Virentia scope. `allSettled` uses `params`, while core `allSettled` uses `payload`.
62
+ ```sh
63
+ pnpm --filter @virentia/effector test
64
+ ```
58
65
 
59
66
  ## License
60
67