rxfy 0.2.0 → 0.2.1
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 +16 -1
- package/dist/index.cjs +25 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -0
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# rxfy
|
|
2
2
|
|
|
3
|
-
rxfy (/ɑɹ ɪks faɪ/) —
|
|
3
|
+
rxfy (/ɑɹ ɪks faɪ/) — stream-based data management. it utilizes rxjs under the hood.
|
|
4
4
|
|
|
5
5
|
# install
|
|
6
6
|
|
|
@@ -12,3 +12,18 @@ rxfy (/ɑɹ ɪks faɪ/) — observables-based data flow management
|
|
|
12
12
|
- Lens — lensed atom with getter and setter
|
|
13
13
|
- Store — where all the data stored
|
|
14
14
|
- Edge — data handler and accessor
|
|
15
|
+
|
|
16
|
+
# example
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import PQueue from "p-queue";
|
|
20
|
+
import { of } from "rxjs";
|
|
21
|
+
import { createAtom, createState, createStore } from "rxfy";
|
|
22
|
+
|
|
23
|
+
const queue = new PQueue({ concurrency: 5 });
|
|
24
|
+
const state = createAtom(createState({}));
|
|
25
|
+
const store = createStore(queue, state);
|
|
26
|
+
const userStore = store.factory("users", (id) => of({ id }));
|
|
27
|
+
const user$ = userStore.get("42").toObservable();
|
|
28
|
+
user$.subscribe((x) => console.log(x));
|
|
29
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -4883,6 +4883,31 @@ function createStore(queue, state$) {
|
|
|
4883
4883
|
});
|
|
4884
4884
|
return createStore(queue, lens);
|
|
4885
4885
|
},
|
|
4886
|
+
factory: (name, loader) => {
|
|
4887
|
+
const cache = Map().asMutable();
|
|
4888
|
+
return {
|
|
4889
|
+
get: (key) => {
|
|
4890
|
+
if (!cache.has(key)) {
|
|
4891
|
+
const lens = createLens(
|
|
4892
|
+
createLens(state$, {
|
|
4893
|
+
get: (x) => {
|
|
4894
|
+
const value = x.value[name];
|
|
4895
|
+
return value ?? toBranded("edge", createIdle());
|
|
4896
|
+
},
|
|
4897
|
+
set: (x, xs) => ({
|
|
4898
|
+
...xs,
|
|
4899
|
+
value: { ...xs.value, [name]: x }
|
|
4900
|
+
})
|
|
4901
|
+
}),
|
|
4902
|
+
keyLens("value")
|
|
4903
|
+
);
|
|
4904
|
+
const edge = createEdge(lens, queue, () => loader(key));
|
|
4905
|
+
cache.set(key, edge);
|
|
4906
|
+
}
|
|
4907
|
+
return cache.get(key);
|
|
4908
|
+
}
|
|
4909
|
+
};
|
|
4910
|
+
},
|
|
4886
4911
|
factoryBatch: (name, batch) => {
|
|
4887
4912
|
const lens = createLens(state$, {
|
|
4888
4913
|
get: (x) => x.value[name] ?? toBranded("map", {}),
|
package/dist/index.d.cts
CHANGED
|
@@ -73,6 +73,7 @@ type IStore<TState extends IStoreStateJS> = {
|
|
|
73
73
|
state$: IAtom<TState>;
|
|
74
74
|
collect: () => Promise<void>;
|
|
75
75
|
node: (name: string) => IStore<IStoreStateJS>;
|
|
76
|
+
factory: <TData>(name: string, loader: (key: string) => Observable<TData>) => IFactory<TData>;
|
|
76
77
|
factoryBatch: <TData>(name: string, batch: (key: string[]) => Observable<Record<string, TData>>) => IFactory<TData>;
|
|
77
78
|
};
|
|
78
79
|
declare function createState(val: IStoreState): IStoreStateJS;
|
package/dist/index.d.ts
CHANGED
|
@@ -73,6 +73,7 @@ type IStore<TState extends IStoreStateJS> = {
|
|
|
73
73
|
state$: IAtom<TState>;
|
|
74
74
|
collect: () => Promise<void>;
|
|
75
75
|
node: (name: string) => IStore<IStoreStateJS>;
|
|
76
|
+
factory: <TData>(name: string, loader: (key: string) => Observable<TData>) => IFactory<TData>;
|
|
76
77
|
factoryBatch: <TData>(name: string, batch: (key: string[]) => Observable<Record<string, TData>>) => IFactory<TData>;
|
|
77
78
|
};
|
|
78
79
|
declare function createState(val: IStoreState): IStoreStateJS;
|
package/dist/index.js
CHANGED
|
@@ -4843,6 +4843,31 @@ function createStore(queue, state$) {
|
|
|
4843
4843
|
});
|
|
4844
4844
|
return createStore(queue, lens);
|
|
4845
4845
|
},
|
|
4846
|
+
factory: (name, loader) => {
|
|
4847
|
+
const cache = Map().asMutable();
|
|
4848
|
+
return {
|
|
4849
|
+
get: (key) => {
|
|
4850
|
+
if (!cache.has(key)) {
|
|
4851
|
+
const lens = createLens(
|
|
4852
|
+
createLens(state$, {
|
|
4853
|
+
get: (x) => {
|
|
4854
|
+
const value = x.value[name];
|
|
4855
|
+
return value ?? toBranded("edge", createIdle());
|
|
4856
|
+
},
|
|
4857
|
+
set: (x, xs) => ({
|
|
4858
|
+
...xs,
|
|
4859
|
+
value: { ...xs.value, [name]: x }
|
|
4860
|
+
})
|
|
4861
|
+
}),
|
|
4862
|
+
keyLens("value")
|
|
4863
|
+
);
|
|
4864
|
+
const edge = createEdge(lens, queue, () => loader(key));
|
|
4865
|
+
cache.set(key, edge);
|
|
4866
|
+
}
|
|
4867
|
+
return cache.get(key);
|
|
4868
|
+
}
|
|
4869
|
+
};
|
|
4870
|
+
},
|
|
4846
4871
|
factoryBatch: (name, batch) => {
|
|
4847
4872
|
const lens = createLens(state$, {
|
|
4848
4873
|
get: (x) => x.value[name] ?? toBranded("map", {}),
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rxfy",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "stream-based data management",
|
|
4
5
|
"license": "MIT",
|
|
5
|
-
"description": "Stream-based state manager",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -19,15 +19,14 @@
|
|
|
19
19
|
"package.json"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
22
|
+
"p-queue": "^8.1.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/lodash": "^4.17.16",
|
|
26
26
|
"eslint": "^9.21.0",
|
|
27
|
-
"jiti": "^2.4.2",
|
|
28
27
|
"immutable": "^5.1.1",
|
|
28
|
+
"jiti": "^2.4.2",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
|
-
"p-queue": "^8.1.0",
|
|
31
30
|
"rimraf": "^6.0.1",
|
|
32
31
|
"rxjs": "^7.8.2",
|
|
33
32
|
"tsup": "^8.3.6",
|