atom.io 0.24.7 → 0.25.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/data/dist/index.cjs +40 -62
- package/data/dist/index.d.ts +3 -3
- package/data/dist/index.js +41 -63
- package/data/src/join.ts +47 -64
- package/dist/index.cjs +26 -8
- package/dist/index.d.ts +37 -15
- package/dist/index.js +27 -9
- package/internal/dist/index.cjs +224 -117
- package/internal/dist/index.d.ts +12 -7
- package/internal/dist/index.js +225 -118
- package/internal/src/families/dispose-from-store.ts +56 -3
- package/internal/src/get-state/get-from-store.ts +58 -25
- package/internal/src/molecule/make-molecule-in-store.ts +59 -23
- package/internal/src/not-found-error.ts +29 -6
- package/internal/src/selector/create-readonly-selector.ts +7 -2
- package/internal/src/selector/create-writable-selector.ts +7 -5
- package/internal/src/selector/register-selector.ts +59 -9
- package/internal/src/selector/trace-selector-atoms.ts +6 -8
- package/internal/src/selector/update-selector-atoms.ts +3 -1
- package/internal/src/set-state/set-into-store.ts +48 -1
- package/internal/src/store/store.ts +4 -4
- package/internal/src/transaction/build-transaction.ts +10 -9
- package/internal/src/transaction/create-transaction.ts +2 -2
- package/internal/src/transaction/index.ts +2 -2
- package/package.json +6 -6
- package/react/dist/index.cjs +4 -1
- package/react/dist/index.js +5 -2
- package/react/src/use-o.ts +11 -3
- package/realtime/dist/index.cjs +0 -1
- package/realtime/dist/index.js +0 -1
- package/realtime/src/realtime-continuity.ts +0 -1
- package/realtime-server/dist/index.cjs +7 -7
- package/realtime-server/dist/index.js +7 -7
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +7 -7
- package/src/dispose-state.ts +32 -3
- package/src/get-state.ts +37 -4
- package/src/molecule.ts +20 -7
- package/src/set-state.ts +19 -2
- package/src/silo.ts +11 -4
- package/src/transaction.ts +9 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"drizzle-kit": "0.22.7",
|
|
65
65
|
"drizzle-orm": "0.31.2",
|
|
66
66
|
"eslint": "npm:eslint@8.57.0",
|
|
67
|
-
"eslint-v9": "npm:eslint@9.
|
|
68
|
-
"framer-motion": "11.2.
|
|
67
|
+
"eslint-v9": "npm:eslint@9.6.0",
|
|
68
|
+
"framer-motion": "11.2.12",
|
|
69
69
|
"happy-dom": "14.12.3",
|
|
70
70
|
"http-proxy": "1.18.1",
|
|
71
71
|
"npmlog": "7.0.1",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"tmp": "0.2.3",
|
|
80
80
|
"tsup": "8.1.0",
|
|
81
81
|
"typescript": "5.5.2",
|
|
82
|
-
"vite": "5.3.
|
|
82
|
+
"vite": "5.3.2",
|
|
83
83
|
"vite-tsconfig-paths": "4.3.2",
|
|
84
84
|
"vitest": "1.6.0"
|
|
85
85
|
},
|
|
@@ -250,7 +250,7 @@
|
|
|
250
250
|
}
|
|
251
251
|
},
|
|
252
252
|
"scripts": {
|
|
253
|
-
"manifest": "tsx __scripts__/manifest-build.node",
|
|
253
|
+
"manifest": "tsx __scripts__/manifest-build.node.ts",
|
|
254
254
|
"clean:build": "find . -type d -name 'dist' -not -path '*/node_modules/*' | xargs rm -rf",
|
|
255
255
|
"build": "bun run clean:build && concurrently \"npm:build:*\"",
|
|
256
256
|
"build:main": "tsup",
|
|
@@ -279,7 +279,7 @@
|
|
|
279
279
|
"test:coverage": "vitest run --coverage",
|
|
280
280
|
"test:once": "bun run test:manifest && cross-env IMPORT=dist vitest run",
|
|
281
281
|
"test:once:public": "cross-env IMPORT=dist vitest run public",
|
|
282
|
-
"test:manifest": "tsx __scripts__/manifest-test.node",
|
|
282
|
+
"test:manifest": "tsx __scripts__/manifest-test.node.ts",
|
|
283
283
|
"test:semver": "bun ../break-check/src/break-check.x.ts --verbose"
|
|
284
284
|
}
|
|
285
285
|
}
|
package/react/dist/index.cjs
CHANGED
|
@@ -41,7 +41,10 @@ function useI(token, key) {
|
|
|
41
41
|
}
|
|
42
42
|
function useO(token, key) {
|
|
43
43
|
const store = React5__namespace.useContext(StoreContext);
|
|
44
|
-
const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` || token.type === `readonly_selector_family` ? internal.
|
|
44
|
+
const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` || token.type === `readonly_selector_family` ? internal.seekInStore(token, key, store) : token;
|
|
45
|
+
if (!stateToken) {
|
|
46
|
+
throw new internal.NotFoundError(token, store);
|
|
47
|
+
}
|
|
45
48
|
const id = React5__namespace.useId();
|
|
46
49
|
return React5__namespace.useSyncExternalStore(
|
|
47
50
|
(dispatch) => internal.subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
|
package/react/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../../dist/chunk-S4N6XNPH.js';
|
|
2
|
-
import { IMPLICIT, findInStore, setIntoStore, subscribeToState, getFromStore, getJsonToken, withdraw, subscribeToTimeline } from 'atom.io/internal';
|
|
2
|
+
import { IMPLICIT, findInStore, setIntoStore, seekInStore, NotFoundError, subscribeToState, getFromStore, getJsonToken, withdraw, subscribeToTimeline } from 'atom.io/internal';
|
|
3
3
|
import * as React5 from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
import { undo, redo } from 'atom.io';
|
|
@@ -19,7 +19,10 @@ function useI(token, key) {
|
|
|
19
19
|
}
|
|
20
20
|
function useO(token, key) {
|
|
21
21
|
const store = React5.useContext(StoreContext);
|
|
22
|
-
const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` || token.type === `readonly_selector_family` ?
|
|
22
|
+
const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` || token.type === `readonly_selector_family` ? seekInStore(token, key, store) : token;
|
|
23
|
+
if (!stateToken) {
|
|
24
|
+
throw new NotFoundError(token, store);
|
|
25
|
+
}
|
|
23
26
|
const id = React5.useId();
|
|
24
27
|
return React5.useSyncExternalStore(
|
|
25
28
|
(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
|
package/react/src/use-o.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ReadableFamilyToken, ReadableToken } from "atom.io"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
getFromStore,
|
|
4
|
+
NotFoundError,
|
|
5
|
+
seekInStore,
|
|
6
|
+
subscribeToState,
|
|
7
|
+
} from "atom.io/internal"
|
|
3
8
|
import type { Json } from "atom.io/json"
|
|
4
9
|
import * as React from "react"
|
|
5
10
|
|
|
@@ -17,13 +22,16 @@ export function useO<T, K extends Json.Serializable>(
|
|
|
17
22
|
key?: K,
|
|
18
23
|
): T {
|
|
19
24
|
const store = React.useContext(StoreContext)
|
|
20
|
-
const stateToken: ReadableToken<any> =
|
|
25
|
+
const stateToken: ReadableToken<any> | undefined =
|
|
21
26
|
token.type === `atom_family` ||
|
|
22
27
|
token.type === `mutable_atom_family` ||
|
|
23
28
|
token.type === `selector_family` ||
|
|
24
29
|
token.type === `readonly_selector_family`
|
|
25
|
-
?
|
|
30
|
+
? seekInStore(token, key as K, store)
|
|
26
31
|
: token
|
|
32
|
+
if (!stateToken) {
|
|
33
|
+
throw new NotFoundError(token, store)
|
|
34
|
+
}
|
|
27
35
|
const id = React.useId()
|
|
28
36
|
return React.useSyncExternalStore<T>(
|
|
29
37
|
(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
|
package/realtime/dist/index.cjs
CHANGED
|
@@ -24,7 +24,6 @@ var InvariantMap = class extends Map {
|
|
|
24
24
|
var _SyncGroup = class _SyncGroup {
|
|
25
25
|
constructor(key) {
|
|
26
26
|
this.key = key;
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
28
27
|
this.type = `continuity`;
|
|
29
28
|
this.globals = [];
|
|
30
29
|
this.actions = [];
|
package/realtime/dist/index.js
CHANGED
|
@@ -22,7 +22,6 @@ var InvariantMap = class extends Map {
|
|
|
22
22
|
var _SyncGroup = class _SyncGroup {
|
|
23
23
|
constructor(key) {
|
|
24
24
|
this.key = key;
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
26
25
|
this.type = `continuity`;
|
|
27
26
|
this.globals = [];
|
|
28
27
|
this.actions = [];
|
|
@@ -410,41 +410,41 @@ var createRoomTX = AtomIO__namespace.transaction({
|
|
|
410
410
|
});
|
|
411
411
|
var joinRoomTX = AtomIO__namespace.transaction({
|
|
412
412
|
key: `joinRoom`,
|
|
413
|
-
do: (
|
|
413
|
+
do: (tools, roomId, userId, enteredAtEpoch) => {
|
|
414
414
|
const meta = { enteredAtEpoch };
|
|
415
415
|
data.editRelationsInStore(
|
|
416
416
|
realtime.usersInRooms,
|
|
417
417
|
(relations) => {
|
|
418
418
|
relations.set({ room: roomId, user: userId }, meta);
|
|
419
419
|
},
|
|
420
|
-
|
|
420
|
+
tools.env().store
|
|
421
421
|
);
|
|
422
422
|
return meta;
|
|
423
423
|
}
|
|
424
424
|
});
|
|
425
425
|
var leaveRoomTX = AtomIO__namespace.transaction({
|
|
426
426
|
key: `leaveRoom`,
|
|
427
|
-
do: (
|
|
427
|
+
do: (tools, roomId, userId) => {
|
|
428
428
|
data.editRelationsInStore(
|
|
429
429
|
realtime.usersInRooms,
|
|
430
430
|
(relations) => {
|
|
431
431
|
relations.delete({ room: roomId, user: userId });
|
|
432
432
|
},
|
|
433
|
-
|
|
433
|
+
tools.env().store
|
|
434
434
|
);
|
|
435
435
|
}
|
|
436
436
|
});
|
|
437
437
|
var destroyRoomTX = AtomIO__namespace.transaction({
|
|
438
438
|
key: `destroyRoom`,
|
|
439
|
-
do: (
|
|
439
|
+
do: (tools, roomId) => {
|
|
440
440
|
data.editRelationsInStore(
|
|
441
441
|
realtime.usersInRooms,
|
|
442
442
|
(relations) => {
|
|
443
443
|
relations.delete({ room: roomId });
|
|
444
444
|
},
|
|
445
|
-
|
|
445
|
+
tools.env().store
|
|
446
446
|
);
|
|
447
|
-
|
|
447
|
+
tools.set(realtime.roomIndex, (s) => (s.delete(roomId), s));
|
|
448
448
|
}
|
|
449
449
|
});
|
|
450
450
|
function redactTransactionUpdateContent(visibleStateKeys, updates) {
|
|
@@ -370,41 +370,41 @@ var createRoomTX = AtomIO.transaction({
|
|
|
370
370
|
});
|
|
371
371
|
var joinRoomTX = AtomIO.transaction({
|
|
372
372
|
key: `joinRoom`,
|
|
373
|
-
do: (
|
|
373
|
+
do: (tools, roomId, userId, enteredAtEpoch) => {
|
|
374
374
|
const meta = { enteredAtEpoch };
|
|
375
375
|
editRelationsInStore(
|
|
376
376
|
usersInRooms,
|
|
377
377
|
(relations) => {
|
|
378
378
|
relations.set({ room: roomId, user: userId }, meta);
|
|
379
379
|
},
|
|
380
|
-
|
|
380
|
+
tools.env().store
|
|
381
381
|
);
|
|
382
382
|
return meta;
|
|
383
383
|
}
|
|
384
384
|
});
|
|
385
385
|
var leaveRoomTX = AtomIO.transaction({
|
|
386
386
|
key: `leaveRoom`,
|
|
387
|
-
do: (
|
|
387
|
+
do: (tools, roomId, userId) => {
|
|
388
388
|
editRelationsInStore(
|
|
389
389
|
usersInRooms,
|
|
390
390
|
(relations) => {
|
|
391
391
|
relations.delete({ room: roomId, user: userId });
|
|
392
392
|
},
|
|
393
|
-
|
|
393
|
+
tools.env().store
|
|
394
394
|
);
|
|
395
395
|
}
|
|
396
396
|
});
|
|
397
397
|
var destroyRoomTX = AtomIO.transaction({
|
|
398
398
|
key: `destroyRoom`,
|
|
399
|
-
do: (
|
|
399
|
+
do: (tools, roomId) => {
|
|
400
400
|
editRelationsInStore(
|
|
401
401
|
usersInRooms,
|
|
402
402
|
(relations) => {
|
|
403
403
|
relations.delete({ room: roomId });
|
|
404
404
|
},
|
|
405
|
-
|
|
405
|
+
tools.env().store
|
|
406
406
|
);
|
|
407
|
-
|
|
407
|
+
tools.set(roomIndex, (s) => (s.delete(roomId), s));
|
|
408
408
|
}
|
|
409
409
|
});
|
|
410
410
|
function redactTransactionUpdateContent(visibleStateKeys, updates) {
|
|
@@ -31,14 +31,14 @@ export const joinRoomTX = AtomIO.transaction<
|
|
|
31
31
|
(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta
|
|
32
32
|
>({
|
|
33
33
|
key: `joinRoom`,
|
|
34
|
-
do: (
|
|
34
|
+
do: (tools, roomId, userId, enteredAtEpoch) => {
|
|
35
35
|
const meta = { enteredAtEpoch }
|
|
36
36
|
editRelationsInStore(
|
|
37
37
|
usersInRooms,
|
|
38
38
|
(relations) => {
|
|
39
39
|
relations.set({ room: roomId, user: userId }, meta)
|
|
40
40
|
},
|
|
41
|
-
|
|
41
|
+
tools.env().store,
|
|
42
42
|
)
|
|
43
43
|
return meta
|
|
44
44
|
},
|
|
@@ -49,13 +49,13 @@ export const leaveRoomTX = AtomIO.transaction<
|
|
|
49
49
|
(roomId: string, userId: string) => void
|
|
50
50
|
>({
|
|
51
51
|
key: `leaveRoom`,
|
|
52
|
-
do: (
|
|
52
|
+
do: (tools, roomId, userId) => {
|
|
53
53
|
editRelationsInStore(
|
|
54
54
|
usersInRooms,
|
|
55
55
|
(relations) => {
|
|
56
56
|
relations.delete({ room: roomId, user: userId })
|
|
57
57
|
},
|
|
58
|
-
|
|
58
|
+
tools.env().store,
|
|
59
59
|
)
|
|
60
60
|
},
|
|
61
61
|
})
|
|
@@ -63,14 +63,14 @@ export type LeaveRoomIO = AtomIO.TransactionIO<typeof leaveRoomTX>
|
|
|
63
63
|
|
|
64
64
|
export const destroyRoomTX = AtomIO.transaction<(roomId: string) => void>({
|
|
65
65
|
key: `destroyRoom`,
|
|
66
|
-
do: (
|
|
66
|
+
do: (tools, roomId) => {
|
|
67
67
|
editRelationsInStore(
|
|
68
68
|
usersInRooms,
|
|
69
69
|
(relations) => {
|
|
70
70
|
relations.delete({ room: roomId })
|
|
71
71
|
},
|
|
72
|
-
|
|
72
|
+
tools.env().store,
|
|
73
73
|
)
|
|
74
|
-
|
|
74
|
+
tools.set(roomIndex, (s) => (s.delete(roomId), s))
|
|
75
75
|
},
|
|
76
76
|
})
|
package/src/dispose-state.ts
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
|
+
import type { Json } from "atom.io/json"
|
|
2
3
|
|
|
3
|
-
import type { ReadableToken } from "."
|
|
4
|
-
import type {
|
|
4
|
+
import type { ReadableFamilyToken, ReadableToken } from "."
|
|
5
|
+
import type {
|
|
6
|
+
MoleculeConstructor,
|
|
7
|
+
MoleculeFamilyToken,
|
|
8
|
+
MoleculeKey,
|
|
9
|
+
MoleculeToken,
|
|
10
|
+
} from "./molecule"
|
|
5
11
|
|
|
6
12
|
export function disposeState(
|
|
7
13
|
token: MoleculeToken<any> | ReadableToken<any>,
|
|
14
|
+
): void
|
|
15
|
+
|
|
16
|
+
export function disposeState<K extends Json.Serializable>(
|
|
17
|
+
token: ReadableFamilyToken<any, K>,
|
|
18
|
+
key: K,
|
|
19
|
+
): void
|
|
20
|
+
|
|
21
|
+
export function disposeState<M extends MoleculeConstructor>(
|
|
22
|
+
token: MoleculeFamilyToken<M>,
|
|
23
|
+
key: MoleculeKey<M>,
|
|
24
|
+
): void
|
|
25
|
+
|
|
26
|
+
export function disposeState(
|
|
27
|
+
token:
|
|
28
|
+
| MoleculeFamilyToken<any>
|
|
29
|
+
| MoleculeToken<any>
|
|
30
|
+
| ReadableFamilyToken<any, any>
|
|
31
|
+
| ReadableToken<any>,
|
|
32
|
+
key?: Json.Serializable,
|
|
8
33
|
): void {
|
|
9
|
-
|
|
34
|
+
if (key) {
|
|
35
|
+
Internal.disposeFromStore(token as any, key, Internal.IMPLICIT.STORE)
|
|
36
|
+
} else {
|
|
37
|
+
Internal.disposeFromStore(token as any, Internal.IMPLICIT.STORE)
|
|
38
|
+
}
|
|
10
39
|
}
|
package/src/get-state.ts
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
|
+
import type { Json } from "atom.io/json"
|
|
2
3
|
|
|
3
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
MoleculeConstructor,
|
|
6
|
+
MoleculeFamilyToken,
|
|
7
|
+
MoleculeToken,
|
|
8
|
+
ReadableFamilyToken,
|
|
9
|
+
ReadableToken,
|
|
10
|
+
} from "."
|
|
4
11
|
|
|
5
12
|
export function getState<T>(token: ReadableToken<T>): T
|
|
13
|
+
|
|
6
14
|
export function getState<M extends MoleculeConstructor>(
|
|
7
15
|
token: MoleculeToken<M>,
|
|
8
|
-
): InstanceType<M>
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
): InstanceType<M>
|
|
17
|
+
|
|
18
|
+
export function getState<T, K extends Json.Serializable>(
|
|
19
|
+
token: ReadableFamilyToken<T, K>,
|
|
20
|
+
key: K,
|
|
21
|
+
): T
|
|
22
|
+
|
|
23
|
+
export function getState<M extends MoleculeConstructor>(
|
|
24
|
+
token: MoleculeFamilyToken<M>,
|
|
25
|
+
key: Json.Serializable,
|
|
26
|
+
): InstanceType<M>
|
|
27
|
+
|
|
28
|
+
export function getState(
|
|
29
|
+
token:
|
|
30
|
+
| MoleculeFamilyToken<any>
|
|
31
|
+
| MoleculeToken<any>
|
|
32
|
+
| ReadableFamilyToken<any, any>
|
|
33
|
+
| ReadableToken<any>,
|
|
34
|
+
key?: Json.Serializable,
|
|
35
|
+
): any {
|
|
36
|
+
if (key) {
|
|
37
|
+
return Internal.getFromStore(
|
|
38
|
+
token as any,
|
|
39
|
+
key as any,
|
|
40
|
+
Internal.IMPLICIT.STORE,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
return Internal.getFromStore(token as any, Internal.IMPLICIT.STORE)
|
|
11
44
|
}
|
package/src/molecule.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
ActorToolkit,
|
|
2
3
|
Flat,
|
|
3
4
|
MoleculeCreation,
|
|
4
5
|
MoleculeDisposal,
|
|
@@ -10,7 +11,6 @@ import type {
|
|
|
10
11
|
ReadonlySelectorToken,
|
|
11
12
|
RegularAtomFamilyToken,
|
|
12
13
|
RegularAtomToken,
|
|
13
|
-
TransactorsWithRunAndEnv,
|
|
14
14
|
WritableFamilyToken,
|
|
15
15
|
WritableSelectorFamilyToken,
|
|
16
16
|
WritableSelectorToken,
|
|
@@ -26,8 +26,8 @@ import {
|
|
|
26
26
|
} from "atom.io/internal"
|
|
27
27
|
import { type Json, stringifyJson } from "atom.io/json"
|
|
28
28
|
|
|
29
|
-
export type
|
|
30
|
-
Omit<
|
|
29
|
+
export type CtorToolkit<K extends Json.Serializable> = Flat<
|
|
30
|
+
Omit<ActorToolkit, `find`> & {
|
|
31
31
|
bond<T extends Transceiver<any>, J extends Json.Serializable>(
|
|
32
32
|
family: MutableAtomFamilyToken<T, J, K>,
|
|
33
33
|
): MutableAtomToken<T, J>
|
|
@@ -36,10 +36,23 @@ export type MoleculeTransactors<K extends Json.Serializable> = Flat<
|
|
|
36
36
|
bond<T>(family: ReadonlySelectorFamilyToken<T, K>): ReadonlySelectorToken<T>
|
|
37
37
|
bond<T>(family: WritableFamilyToken<T, K>): WritableToken<T>
|
|
38
38
|
bond<T>(family: ReadableFamilyToken<T, K>): ReadableToken<T>
|
|
39
|
+
bond<J extends JoinToken<any, any, any, any>>(
|
|
40
|
+
joinToken: J,
|
|
41
|
+
role: {
|
|
42
|
+
as: J extends JoinToken<infer A, infer B, any, any> ? A | B : never
|
|
43
|
+
},
|
|
44
|
+
): J extends JoinToken<any, any, any, infer Content>
|
|
45
|
+
? Content extends null
|
|
46
|
+
? { relatedKeys: ReadonlySelectorToken<string[]> }
|
|
47
|
+
: {
|
|
48
|
+
relatedKeys: ReadonlySelectorToken<string[]>
|
|
49
|
+
relatedEntries: ReadonlySelectorToken<
|
|
50
|
+
[key: string, value: Content][]
|
|
51
|
+
>
|
|
52
|
+
}
|
|
53
|
+
: never
|
|
39
54
|
|
|
40
|
-
claim(below: MoleculeToken<any>, options: { exclusive: boolean })
|
|
41
|
-
|
|
42
|
-
join<J extends JoinToken<any, any, any, any>>(joinToken: J): J
|
|
55
|
+
claim(below: MoleculeToken<any>, options: { exclusive: boolean }): void
|
|
43
56
|
|
|
44
57
|
spawn<Key extends Json.Serializable, Ctor extends MoleculeConstructor>(
|
|
45
58
|
family: MoleculeFamilyToken<Ctor>,
|
|
@@ -49,7 +62,7 @@ export type MoleculeTransactors<K extends Json.Serializable> = Flat<
|
|
|
49
62
|
}
|
|
50
63
|
>
|
|
51
64
|
export type MoleculeConstructor = new (
|
|
52
|
-
|
|
65
|
+
toolkit: CtorToolkit<any>,
|
|
53
66
|
key: any,
|
|
54
67
|
...params: any
|
|
55
68
|
) => any
|
package/src/set-state.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
|
+
import type { Json } from "rel8"
|
|
2
3
|
|
|
3
|
-
import type { WritableToken } from "."
|
|
4
|
+
import type { WritableFamilyToken, WritableToken } from "."
|
|
4
5
|
|
|
5
6
|
export function setState<T, New extends T>(
|
|
6
7
|
token: WritableToken<T>,
|
|
7
8
|
value: New | ((oldValue: T) => New),
|
|
9
|
+
): void
|
|
10
|
+
|
|
11
|
+
export function setState<T, K extends Json.Serializable, New extends T>(
|
|
12
|
+
token: WritableFamilyToken<T, K>,
|
|
13
|
+
key: K,
|
|
14
|
+
value: New | ((oldValue: T) => New),
|
|
15
|
+
): void
|
|
16
|
+
|
|
17
|
+
export function setState<T, New extends T>(
|
|
18
|
+
token: WritableFamilyToken<T, Json.Serializable> | WritableToken<T>,
|
|
19
|
+
p1: Json.Serializable | New | ((oldValue: T) => New),
|
|
20
|
+
p2?: New | ((oldValue: T) => New),
|
|
8
21
|
): void {
|
|
9
|
-
|
|
22
|
+
if (p2) {
|
|
23
|
+
Internal.setIntoStore(token as any, p1 as any, p2, Internal.IMPLICIT.STORE)
|
|
24
|
+
} else {
|
|
25
|
+
Internal.setIntoStore(token as any, p1 as any, Internal.IMPLICIT.STORE)
|
|
26
|
+
}
|
|
10
27
|
}
|
package/src/silo.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createStandaloneSelector,
|
|
8
8
|
createTimeline,
|
|
9
9
|
createTransaction,
|
|
10
|
+
disposeFromStore,
|
|
10
11
|
findInStore,
|
|
11
12
|
getFromStore,
|
|
12
13
|
setIntoStore,
|
|
@@ -17,6 +18,7 @@ import type { Json } from "atom.io/json"
|
|
|
17
18
|
|
|
18
19
|
import type {
|
|
19
20
|
AtomToken,
|
|
21
|
+
disposeState,
|
|
20
22
|
getState,
|
|
21
23
|
MutableAtomFamily,
|
|
22
24
|
MutableAtomFamilyOptions,
|
|
@@ -47,6 +49,7 @@ export class Silo {
|
|
|
47
49
|
public findState: typeof findState
|
|
48
50
|
public getState: typeof getState
|
|
49
51
|
public setState: typeof setState
|
|
52
|
+
public disposeState: typeof disposeState
|
|
50
53
|
public subscribe: typeof subscribe
|
|
51
54
|
public undo: typeof undo
|
|
52
55
|
public redo: typeof redo
|
|
@@ -84,10 +87,14 @@ export class Silo {
|
|
|
84
87
|
this.transaction = (options) => createTransaction(options, s)
|
|
85
88
|
this.timeline = (options) => createTimeline(options, s)
|
|
86
89
|
this.findState = (token, key) => findInStore(token, key, s) as any
|
|
87
|
-
this.getState = (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
this.getState = ((...params: Parameters<typeof getState>) =>
|
|
91
|
+
getFromStore(...params, s)) as typeof getState
|
|
92
|
+
this.setState = ((...params: Parameters<typeof setState>) => {
|
|
93
|
+
setIntoStore(...params, s)
|
|
94
|
+
}) as typeof setState
|
|
95
|
+
this.disposeState = ((...params: Parameters<typeof disposeState>) => {
|
|
96
|
+
disposeFromStore(...params, s)
|
|
97
|
+
}) as typeof disposeState
|
|
91
98
|
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s)
|
|
92
99
|
this.undo = (token) => {
|
|
93
100
|
timeTravel(`undo`, token, s)
|
package/src/transaction.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
MoleculeFamilyToken,
|
|
6
6
|
MoleculeParams,
|
|
7
7
|
MoleculeToken,
|
|
8
|
+
setState,
|
|
8
9
|
} from "atom.io"
|
|
9
10
|
import type { findState } from "atom.io/ephemeral"
|
|
10
11
|
import type { seekState } from "atom.io/immortal"
|
|
@@ -78,24 +79,19 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
78
79
|
output: ReturnType<F>
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
export type
|
|
82
|
+
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json` | `seek`>
|
|
83
|
+
export type SetterToolkit = Readonly<{
|
|
82
84
|
get: typeof getState
|
|
83
|
-
set:
|
|
84
|
-
state: WritableToken<S>,
|
|
85
|
-
newValue: New | ((oldValue: S) => New),
|
|
86
|
-
) => void
|
|
85
|
+
set: typeof setState
|
|
87
86
|
find: typeof findState
|
|
88
87
|
seek: typeof seekState
|
|
89
88
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
90
89
|
state: MutableAtomToken<T, J>,
|
|
91
90
|
) => WritableSelectorToken<J>
|
|
92
91
|
}>
|
|
93
|
-
export type
|
|
92
|
+
export type ActorToolkit = Readonly<{
|
|
94
93
|
get: typeof getState
|
|
95
|
-
set:
|
|
96
|
-
state: WritableToken<S>,
|
|
97
|
-
newValue: New | ((oldValue: S) => New),
|
|
98
|
-
) => void
|
|
94
|
+
set: typeof setState
|
|
99
95
|
find: typeof findState
|
|
100
96
|
seek: typeof seekState
|
|
101
97
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
@@ -106,23 +102,19 @@ export type TransactorsWithRunAndEnv = Readonly<{
|
|
|
106
102
|
run: typeof runTransaction
|
|
107
103
|
env: () => EnvironmentData
|
|
108
104
|
}>
|
|
109
|
-
export type ReadonlyTransactors = Pick<
|
|
110
|
-
Transactors,
|
|
111
|
-
`find` | `get` | `json` | `seek`
|
|
112
|
-
>
|
|
113
105
|
|
|
114
106
|
export type Read<F extends Func> = (
|
|
115
|
-
|
|
107
|
+
toolkit: GetterToolkit,
|
|
116
108
|
...parameters: Parameters<F>
|
|
117
109
|
) => ReturnType<F>
|
|
118
110
|
|
|
119
111
|
export type Write<F extends Func> = (
|
|
120
|
-
|
|
112
|
+
toolkit: SetterToolkit,
|
|
121
113
|
...parameters: Parameters<F>
|
|
122
114
|
) => ReturnType<F>
|
|
123
115
|
|
|
124
116
|
export type Transact<F extends Func> = (
|
|
125
|
-
|
|
117
|
+
toolkit: ActorToolkit,
|
|
126
118
|
...parameters: Parameters<F>
|
|
127
119
|
) => ReturnType<F>
|
|
128
120
|
|