atom.io 0.40.5 → 0.40.7
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 +1 -1
- package/dist/data/index.d.ts +1 -1
- package/dist/employ-socket-D6wgByWh.js +12 -0
- package/dist/employ-socket-D6wgByWh.js.map +1 -0
- package/dist/has-role-hv4-hJMw.js +1149 -0
- package/dist/has-role-hv4-hJMw.js.map +1 -0
- package/dist/internal/index.d.ts +248 -248
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +570 -1712
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +1 -1
- package/dist/is-fn-DY1wZ-md.js +10 -0
- package/dist/is-fn-DY1wZ-md.js.map +1 -0
- package/dist/main/index.d.ts +33 -33
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +2 -2
- package/dist/main/index.js.map +1 -1
- package/dist/mutex-store-CSvxY9i3.js +11 -0
- package/dist/mutex-store-CSvxY9i3.js.map +1 -0
- package/dist/react/index.d.ts +5 -21
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.js +7 -7
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +7 -15
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +3 -33
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +5 -5
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +92 -69
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +17 -10
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js +41 -41
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +60 -53
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +592 -485
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts +1 -2
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/realtime-testing/index.js +25 -18
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/shared-room-store-COGGKqes.js +32 -0
- package/dist/shared-room-store-COGGKqes.js.map +1 -0
- package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
- package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
- package/dist/web/index.d.ts +3 -3
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/index.js +4 -3
- package/dist/web/index.js.map +1 -1
- package/package.json +12 -12
- package/src/internal/atom/create-regular-atom.ts +5 -4
- package/src/internal/atom/dispose-atom.ts +7 -2
- package/src/internal/atom/has-role.ts +3 -3
- package/src/internal/caching.ts +4 -2
- package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
- package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
- package/src/internal/families/create-regular-atom-family.ts +2 -1
- package/src/internal/families/create-writable-held-selector-family.ts +2 -1
- package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
- package/src/internal/families/dispose-from-store.ts +4 -4
- package/src/internal/families/find-in-store.ts +10 -10
- package/src/internal/families/get-family-of-token.ts +2 -2
- package/src/internal/families/index.ts +1 -0
- package/src/internal/families/mint-in-store.ts +54 -19
- package/src/internal/families/seek-in-store.ts +1 -1
- package/src/internal/get-state/get-fallback.ts +2 -2
- package/src/internal/get-state/get-from-store.ts +5 -5
- package/src/internal/get-state/read-or-compute-value.ts +1 -1
- package/src/internal/get-state/reduce-reference.ts +8 -6
- package/src/internal/index.ts +2 -220
- package/src/internal/molecule.ts +1 -2
- package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
- package/src/internal/mutable/create-mutable-atom.ts +4 -2
- package/src/internal/mutable/get-json-family.ts +1 -1
- package/src/internal/mutable/get-update-family.ts +1 -1
- package/src/internal/mutable/tracker-family.ts +2 -1
- package/src/internal/mutable/tracker.ts +5 -8
- package/src/internal/safe-compute.ts +1 -1
- package/src/internal/selector/create-readonly-held-selector.ts +2 -1
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
- package/src/internal/selector/create-writable-held-selector.ts +2 -1
- package/src/internal/selector/create-writable-pure-selector.ts +2 -1
- package/src/internal/selector/dispose-selector.ts +3 -2
- package/src/internal/selector/register-selector.ts +8 -5
- package/src/internal/selector/trace-selector-atoms.ts +2 -1
- package/src/internal/set-state/dispatch-state-update.ts +3 -2
- package/src/internal/set-state/evict-downstream.ts +1 -1
- package/src/internal/set-state/operate-on-store.ts +16 -22
- package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
- package/src/internal/set-state/reset-in-store.ts +5 -5
- package/src/internal/set-state/set-atom-or-selector.ts +2 -2
- package/src/internal/set-state/set-atom.ts +4 -2
- package/src/internal/set-state/set-into-store.ts +21 -39
- package/src/internal/set-state/set-selector.ts +3 -2
- package/src/internal/state-types.ts +228 -0
- package/src/internal/store/deposit.ts +4 -4
- package/src/internal/store/index.ts +0 -1
- package/src/internal/store/store.ts +9 -9
- package/src/internal/store/withdraw.ts +4 -4
- package/src/internal/subscribe/recall-state.ts +1 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
- package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
- package/src/internal/transaction/build-transaction.ts +3 -2
- package/src/internal/transaction/index.ts +1 -23
- package/src/internal/transaction/is-root-store.ts +4 -1
- package/src/internal/transaction/transaction-meta-progress.ts +22 -0
- package/src/main/atom.ts +1 -2
- package/src/main/find-state.ts +5 -5
- package/src/main/get-state.ts +4 -4
- package/src/main/realm.ts +2 -2
- package/src/main/set-state.ts +10 -10
- package/src/react/parse-state-overloads.ts +3 -3
- package/src/react/use-i.ts +6 -4
- package/src/react/use-loadable.ts +4 -30
- package/src/react/use-o.ts +6 -4
- package/src/react-devtools/store.ts +6 -6
- package/src/realtime/index.ts +1 -0
- package/src/realtime/mutex-store.ts +11 -0
- package/src/realtime/realtime-continuity.ts +1 -5
- package/src/realtime-client/pull-atom-family-member.ts +14 -17
- package/src/realtime-client/pull-atom.ts +1 -1
- package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
- package/src/realtime-client/pull-selector-family-member.ts +8 -35
- package/src/realtime-client/pull-selector-roots.ts +90 -0
- package/src/realtime-client/pull-selector.ts +2 -27
- package/src/realtime-client/push-state.ts +33 -5
- package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
- package/src/realtime-react/index.ts +2 -1
- package/src/realtime-react/realtime-context.tsx +9 -5
- package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
- package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
- package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
- package/src/realtime-react/use-push.ts +7 -3
- package/src/realtime-react/use-realtime-service.ts +11 -11
- package/src/realtime-react/use-single-effect.ts +11 -14
- package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +1 -1
- package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +1 -1
- package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +3 -5
- package/src/realtime-server/continuity/subscribe-to-continuity-actions.ts +1 -1
- package/src/realtime-server/employ-socket.ts +14 -0
- package/src/realtime-server/index.ts +2 -20
- package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
- package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
- package/src/realtime-server/ipc-sockets/parent-socket.ts +81 -58
- package/src/realtime-server/realtime-family-provider.ts +78 -29
- package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
- package/src/realtime-server/realtime-mutable-provider.ts +30 -22
- package/src/realtime-server/realtime-server-stores/index.ts +0 -2
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
- package/src/realtime-server/realtime-state-provider.ts +30 -29
- package/src/realtime-server/realtime-state-receiver.ts +62 -16
- package/src/realtime-server/server-config.ts +9 -0
- package/src/realtime-server/socket-interface.ts +14 -0
- package/src/realtime-testing/setup-realtime-test.tsx +56 -23
- package/src/web/index.ts +1 -1
- package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
- package/src/internal/store/mint-or-counterfeit.ts +0 -108
- package/src/realtime-react/on-mount.ts +0 -5
- package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
package/dist/web/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
//#region src/web/
|
|
2
|
-
const
|
|
1
|
+
//#region src/web/storage-sync.ts
|
|
2
|
+
const storageSync = (storage, { stringify, parse }, key) => ({ setSelf, onSet }) => {
|
|
3
|
+
if (!storage) return;
|
|
3
4
|
const savedValue = storage.getItem(key);
|
|
4
5
|
if (savedValue != null) setSelf(parse(savedValue));
|
|
5
6
|
onSet(({ newValue }) => {
|
|
@@ -12,5 +13,5 @@ const persistSync = (storage, { stringify, parse }, key) => ({ setSelf, onSet })
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
//#endregion
|
|
15
|
-
export {
|
|
16
|
+
export { storageSync };
|
|
16
17
|
//# sourceMappingURL=index.js.map
|
package/dist/web/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/web/
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/web/storage-sync.ts"],"sourcesContent":["import type { AtomEffect, ViewOf } from \"atom.io\"\n\nexport type StringInterface<T> = {\n\tstringify: (t: ViewOf<T>) => string\n\tparse: (s: string) => T\n}\n\nexport const storageSync =\n\t<T>(\n\t\tstorage: Storage | undefined,\n\t\t{ stringify, parse }: StringInterface<T>,\n\t\tkey: string,\n\t): AtomEffect<T> =>\n\t({ setSelf, onSet }) => {\n\t\tif (!storage) {\n\t\t\treturn\n\t\t}\n\t\tconst savedValue = storage.getItem(key)\n\t\tif (savedValue != null) setSelf(parse(savedValue))\n\n\t\tonSet(({ newValue }) => {\n\t\t\tif (newValue == null) {\n\t\t\t\tstorage.removeItem(key)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tstorage.setItem(key, stringify(newValue))\n\t\t})\n\t}\n"],"mappings":";AAOA,MAAa,eAEX,SACA,EAAE,WAAW,SACb,SAEA,EAAE,SAAS,YAAY;AACvB,KAAI,CAAC,QACJ;CAED,MAAM,aAAa,QAAQ,QAAQ;AACnC,KAAI,cAAc,KAAM,SAAQ,MAAM;AAEtC,QAAO,EAAE,eAAe;AACvB,MAAI,YAAY,MAAM;AACrB,WAAQ,WAAW;AACnB;;AAED,UAAQ,QAAQ,KAAK,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.7",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/core": "0.15.2",
|
|
64
|
-
"@storybook/addon-docs": "9.1.
|
|
65
|
-
"@storybook/addon-onboarding": "9.1.
|
|
66
|
-
"@storybook/react-vite": "9.1.
|
|
64
|
+
"@storybook/addon-docs": "9.1.4",
|
|
65
|
+
"@storybook/addon-onboarding": "9.1.4",
|
|
66
|
+
"@storybook/react-vite": "9.1.4",
|
|
67
67
|
"@testing-library/react": "16.3.0",
|
|
68
68
|
"@types/bun": "npm:bun-types@1.2.21",
|
|
69
69
|
"@types/eslint": "9.6.1",
|
|
@@ -72,15 +72,15 @@
|
|
|
72
72
|
"@types/npmlog": "7.0.0",
|
|
73
73
|
"@types/react": "19.1.12",
|
|
74
74
|
"@types/tmp": "0.2.6",
|
|
75
|
-
"@typescript-eslint/parser": "8.
|
|
76
|
-
"@typescript-eslint/rule-tester": "8.
|
|
77
|
-
"@typescript-eslint/utils": "8.
|
|
75
|
+
"@typescript-eslint/parser": "8.42.0",
|
|
76
|
+
"@typescript-eslint/rule-tester": "8.42.0",
|
|
77
|
+
"@typescript-eslint/utils": "8.42.0",
|
|
78
78
|
"@vitest/coverage-v8": "3.2.4",
|
|
79
79
|
"@vitest/ui": "3.2.4",
|
|
80
80
|
"concurrently": "9.2.1",
|
|
81
81
|
"drizzle-kit": "0.31.4",
|
|
82
82
|
"drizzle-orm": "0.44.5",
|
|
83
|
-
"eslint": "9.
|
|
83
|
+
"eslint": "9.35.0",
|
|
84
84
|
"happy-dom": "18.0.1",
|
|
85
85
|
"http-proxy": "1.18.1",
|
|
86
86
|
"motion": "12.23.12",
|
|
@@ -94,15 +94,15 @@
|
|
|
94
94
|
"recoverage": "0.1.11",
|
|
95
95
|
"socket.io": "4.8.1",
|
|
96
96
|
"socket.io-client": "4.8.1",
|
|
97
|
-
"storybook": "9.1.
|
|
97
|
+
"storybook": "9.1.4",
|
|
98
98
|
"tmp": "0.2.5",
|
|
99
99
|
"tsdown": "0.14.2",
|
|
100
100
|
"typescript": "5.9.2",
|
|
101
|
-
"vite": "7.1.
|
|
101
|
+
"vite": "7.1.4",
|
|
102
102
|
"vite-tsconfig-paths": "5.1.4",
|
|
103
103
|
"vitest": "3.2.4",
|
|
104
104
|
"zod": "3.25.76",
|
|
105
|
-
"break-check": "0.6.
|
|
105
|
+
"break-check": "0.6.15"
|
|
106
106
|
},
|
|
107
107
|
"main": "./dist/main/index.js",
|
|
108
108
|
"files": [
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
},
|
|
178
178
|
"scripts": {
|
|
179
179
|
"manifest": "./__scripts__/manifest-build.node.ts",
|
|
180
|
-
"build": "tsdown
|
|
180
|
+
"build": "tsdown",
|
|
181
181
|
"lint:biome": "biome check -- .",
|
|
182
182
|
"lint:eslint": "eslint -- .",
|
|
183
183
|
"lint:types": "tsgo --noEmit",
|
|
@@ -6,20 +6,21 @@ import type {
|
|
|
6
6
|
} from "atom.io"
|
|
7
7
|
import type { Canonical } from "atom.io/json"
|
|
8
8
|
|
|
9
|
-
import type { RegularAtom, RootStore } from ".."
|
|
10
|
-
import { resetInStore, setIntoStore } from ".."
|
|
11
9
|
import { newest } from "../lineage"
|
|
10
|
+
import { resetInStore, setIntoStore } from "../set-state"
|
|
11
|
+
import type { RegularAtom } from "../state-types"
|
|
12
12
|
import type { Store } from "../store"
|
|
13
13
|
import { deposit } from "../store"
|
|
14
14
|
import { Subject } from "../subject"
|
|
15
15
|
import { subscribeToState } from "../subscribe"
|
|
16
|
-
import type {
|
|
16
|
+
import type { RootStore } from "../transaction"
|
|
17
|
+
import type { InternalRole } from "./has-role"
|
|
17
18
|
|
|
18
19
|
export function createRegularAtom<T, K extends Canonical, E>(
|
|
19
20
|
store: Store,
|
|
20
21
|
options: RegularAtomOptions<T, E>,
|
|
21
22
|
family: FamilyMetadata<K> | undefined,
|
|
22
|
-
internalRoles?:
|
|
23
|
+
internalRoles?: InternalRole[],
|
|
23
24
|
): RegularAtomToken<T, K, E> {
|
|
24
25
|
const type = `atom`
|
|
25
26
|
const { key } = options
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { AtomDisposalEvent, AtomToken, StateLifecycleEvent } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import type { Store, Subject } from ".."
|
|
4
|
-
import { getUpdateToken, hasRole, isChildStore, newest, withdraw } from ".."
|
|
5
3
|
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
4
|
+
import { newest } from "../lineage"
|
|
5
|
+
import { getUpdateToken } from "../mutable"
|
|
6
|
+
import type { Store } from "../store"
|
|
7
|
+
import { withdraw } from "../store"
|
|
8
|
+
import type { Subject } from "../subject"
|
|
9
|
+
import { isChildStore } from "../transaction"
|
|
10
|
+
import { hasRole } from "./has-role"
|
|
6
11
|
|
|
7
12
|
export function disposeAtom(
|
|
8
13
|
store: Store,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Atom } from "
|
|
1
|
+
import type { Atom } from "../state-types"
|
|
2
2
|
|
|
3
3
|
export const INTERNAL_ROLES = [`tracker:signal`] as const
|
|
4
|
-
export type
|
|
4
|
+
export type InternalRole = (typeof INTERNAL_ROLES)[number]
|
|
5
5
|
|
|
6
|
-
export function hasRole(atom: Atom<any, any>, role:
|
|
6
|
+
export function hasRole(atom: Atom<any, any>, role: InternalRole): boolean {
|
|
7
7
|
if (`internalRoles` in atom === false) {
|
|
8
8
|
return false
|
|
9
9
|
}
|
package/src/internal/caching.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { ReadableState, Transceiver } from "."
|
|
2
|
-
import { closeOperation, isChildStore, openOperation, Tracker } from "."
|
|
3
1
|
import { Future } from "./future"
|
|
2
|
+
import { Tracker, type Transceiver } from "./mutable"
|
|
3
|
+
import { closeOperation, openOperation } from "./operation"
|
|
4
4
|
import {
|
|
5
5
|
evictDownstreamFromAtom,
|
|
6
6
|
evictDownstreamFromSelector,
|
|
7
7
|
} from "./set-state/evict-downstream"
|
|
8
|
+
import type { ReadableState } from "./state-types"
|
|
8
9
|
import type { Store } from "./store"
|
|
10
|
+
import { isChildStore } from "./transaction"
|
|
9
11
|
|
|
10
12
|
export function writeToCache<T, E>(
|
|
11
13
|
target: Store,
|
|
@@ -9,10 +9,11 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
|
9
9
|
import type { Canonical } from "atom.io/json"
|
|
10
10
|
import { stringifyJson } from "atom.io/json"
|
|
11
11
|
|
|
12
|
-
import type { ReadonlyHeldSelectorFamily, RootStore } from ".."
|
|
13
12
|
import { newest } from "../lineage"
|
|
14
13
|
import { createReadonlyHeldSelector } from "../selector"
|
|
14
|
+
import type { ReadonlyHeldSelectorFamily } from "../state-types"
|
|
15
15
|
import { Subject } from "../subject"
|
|
16
|
+
import type { RootStore } from "../transaction"
|
|
16
17
|
|
|
17
18
|
export function createReadonlyHeldSelectorFamily<
|
|
18
19
|
T extends object,
|
|
@@ -12,11 +12,14 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
|
12
12
|
import type { Canonical } from "atom.io/json"
|
|
13
13
|
import { stringifyJson } from "atom.io/json"
|
|
14
14
|
|
|
15
|
-
import
|
|
16
|
-
import { findInStore, getFromStore, getJsonToken } from ".."
|
|
15
|
+
import { getFromStore } from "../get-state"
|
|
17
16
|
import { newest } from "../lineage"
|
|
17
|
+
import { getJsonToken } from "../mutable"
|
|
18
18
|
import { createReadonlyPureSelector } from "../selector"
|
|
19
|
+
import type { ReadonlyPureSelectorFamily } from "../state-types"
|
|
19
20
|
import { Subject } from "../subject"
|
|
21
|
+
import type { RootStore } from "../transaction"
|
|
22
|
+
import { findInStore } from "./find-in-store"
|
|
20
23
|
|
|
21
24
|
export function createReadonlyPureSelectorFamily<T, K extends Canonical, E>(
|
|
22
25
|
store: RootStore,
|
|
@@ -10,11 +10,12 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
|
10
10
|
import type { Canonical } from "atom.io/json"
|
|
11
11
|
import { stringifyJson } from "atom.io/json"
|
|
12
12
|
|
|
13
|
-
import type { RegularAtomFamily, RootStore } from ".."
|
|
14
13
|
import { createRegularAtom } from "../atom"
|
|
15
14
|
import { isFn } from "../is-fn"
|
|
16
15
|
import { newest } from "../lineage"
|
|
16
|
+
import type { RegularAtomFamily } from "../state-types"
|
|
17
17
|
import { Subject } from "../subject"
|
|
18
|
+
import type { RootStore } from "../transaction"
|
|
18
19
|
|
|
19
20
|
export function createRegularAtomFamily<T, K extends Canonical, E>(
|
|
20
21
|
store: RootStore,
|
|
@@ -9,11 +9,12 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
|
9
9
|
import type { Canonical } from "atom.io/json"
|
|
10
10
|
import { stringifyJson } from "atom.io/json"
|
|
11
11
|
|
|
12
|
-
import type { RootStore, WritableHeldSelectorFamily } from ".."
|
|
13
12
|
import { newest } from "../lineage"
|
|
14
13
|
import { createWritableHeldSelector } from "../selector"
|
|
14
|
+
import type { WritableHeldSelectorFamily } from "../state-types"
|
|
15
15
|
import type { Store } from "../store"
|
|
16
16
|
import { Subject } from "../subject"
|
|
17
|
+
import type { RootStore } from "../transaction"
|
|
17
18
|
|
|
18
19
|
export function createWritableHeldSelectorFamily<
|
|
19
20
|
T extends object,
|
|
@@ -12,12 +12,15 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
|
|
|
12
12
|
import type { Canonical } from "atom.io/json"
|
|
13
13
|
import { stringifyJson } from "atom.io/json"
|
|
14
14
|
|
|
15
|
-
import
|
|
16
|
-
import { findInStore, getFromStore, getJsonToken } from ".."
|
|
15
|
+
import { getFromStore } from "../get-state"
|
|
17
16
|
import { newest } from "../lineage"
|
|
17
|
+
import { getJsonToken } from "../mutable"
|
|
18
18
|
import { createWritablePureSelector } from "../selector"
|
|
19
|
+
import type { WritablePureSelectorFamily } from "../state-types"
|
|
19
20
|
import type { Store } from "../store"
|
|
20
21
|
import { Subject } from "../subject"
|
|
22
|
+
import type { RootStore } from "../transaction"
|
|
23
|
+
import { findInStore } from "./find-in-store"
|
|
21
24
|
|
|
22
25
|
export function createWritablePureSelectorFamily<T, K extends Canonical, E>(
|
|
23
26
|
store: Store,
|
|
@@ -11,16 +11,16 @@ export function disposeFromStore(
|
|
|
11
11
|
token: ReadableToken<any, any, any>,
|
|
12
12
|
): void
|
|
13
13
|
|
|
14
|
-
export function disposeFromStore<K extends Canonical
|
|
14
|
+
export function disposeFromStore<K extends Canonical>(
|
|
15
15
|
store: Store,
|
|
16
16
|
token: ReadableFamilyToken<any, K, any>,
|
|
17
|
-
key:
|
|
17
|
+
key: NoInfer<K>,
|
|
18
18
|
): void
|
|
19
19
|
|
|
20
|
-
export function disposeFromStore<K extends Canonical
|
|
20
|
+
export function disposeFromStore<K extends Canonical>(
|
|
21
21
|
store: Store,
|
|
22
22
|
...params:
|
|
23
|
-
| [token: ReadableFamilyToken<any, K, any>, key:
|
|
23
|
+
| [token: ReadableFamilyToken<any, K, any>, key: NoInfer<K>]
|
|
24
24
|
| [token: ReadableToken<any, any, any>]
|
|
25
25
|
): void
|
|
26
26
|
|
|
@@ -20,7 +20,7 @@ import type { Canonical } from "atom.io/json"
|
|
|
20
20
|
|
|
21
21
|
import type { Transceiver } from "../mutable"
|
|
22
22
|
import { type Store, withdraw } from "../store"
|
|
23
|
-
import { mintInStore } from "./mint-in-store"
|
|
23
|
+
import { DO_NOT_CREATE, mintInStore } from "./mint-in-store"
|
|
24
24
|
import { seekInStore } from "./seek-in-store"
|
|
25
25
|
|
|
26
26
|
// seek [token 🟧] [inits ⬛]
|
|
@@ -36,49 +36,49 @@ export function findInStore<
|
|
|
36
36
|
store: Store,
|
|
37
37
|
familyToken: MutableAtomFamilyToken<T, K>,
|
|
38
38
|
key: Key,
|
|
39
|
-
): MutableAtomToken<T,
|
|
39
|
+
): MutableAtomToken<T, Key>
|
|
40
40
|
|
|
41
41
|
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
42
42
|
store: Store,
|
|
43
43
|
familyToken: RegularAtomFamilyToken<T, K, E>,
|
|
44
44
|
key: Key,
|
|
45
|
-
): RegularAtomToken<T,
|
|
45
|
+
): RegularAtomToken<T, Key, E>
|
|
46
46
|
|
|
47
47
|
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
48
48
|
store: Store,
|
|
49
49
|
familyToken: AtomFamilyToken<T, K, E>,
|
|
50
50
|
key: Key,
|
|
51
|
-
): AtomToken<T,
|
|
51
|
+
): AtomToken<T, Key, E>
|
|
52
52
|
|
|
53
53
|
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
54
54
|
store: Store,
|
|
55
55
|
familyToken: WritablePureSelectorFamilyToken<T, K, E>,
|
|
56
56
|
key: Key,
|
|
57
|
-
): WritablePureSelectorToken<T,
|
|
57
|
+
): WritablePureSelectorToken<T, Key, E>
|
|
58
58
|
|
|
59
59
|
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
60
60
|
store: Store,
|
|
61
61
|
familyToken: ReadonlyPureSelectorFamilyToken<T, K, E>,
|
|
62
62
|
key: Key,
|
|
63
|
-
): ReadonlyPureSelectorToken<T,
|
|
63
|
+
): ReadonlyPureSelectorToken<T, Key, E>
|
|
64
64
|
|
|
65
65
|
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
66
66
|
store: Store,
|
|
67
67
|
familyToken: SelectorFamilyToken<T, K, E>,
|
|
68
68
|
key: Key,
|
|
69
|
-
): SelectorToken<T,
|
|
69
|
+
): SelectorToken<T, Key, E>
|
|
70
70
|
|
|
71
71
|
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
72
72
|
store: Store,
|
|
73
73
|
familyToken: WritableFamilyToken<T, K, E>,
|
|
74
74
|
key: Key,
|
|
75
|
-
): WritableToken<T,
|
|
75
|
+
): WritableToken<T, Key, E>
|
|
76
76
|
|
|
77
77
|
export function findInStore<T, K extends Canonical, Key extends K, E>(
|
|
78
78
|
store: Store,
|
|
79
79
|
familyToken: ReadableFamilyToken<T, K, E>,
|
|
80
80
|
key: Key,
|
|
81
|
-
): ReadableToken<T,
|
|
81
|
+
): ReadableToken<T, Key, E>
|
|
82
82
|
|
|
83
83
|
export function findInStore(
|
|
84
84
|
store: Store,
|
|
@@ -90,6 +90,6 @@ export function findInStore(
|
|
|
90
90
|
if (existingStateToken) {
|
|
91
91
|
return existingStateToken
|
|
92
92
|
}
|
|
93
|
-
const newStateToken = mintInStore(store, family, key)
|
|
93
|
+
const newStateToken = mintInStore(DO_NOT_CREATE, store, family, key)
|
|
94
94
|
return newStateToken
|
|
95
95
|
}
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
} from "atom.io"
|
|
9
9
|
import type { Canonical } from "atom.io/json"
|
|
10
10
|
|
|
11
|
+
import type { Transceiver } from "../mutable"
|
|
11
12
|
import type {
|
|
12
13
|
MutableAtomFamily,
|
|
13
14
|
ReadableFamily,
|
|
@@ -15,8 +16,7 @@ import type {
|
|
|
15
16
|
RegularAtomFamily,
|
|
16
17
|
WritableFamily,
|
|
17
18
|
WritablePureSelectorFamily,
|
|
18
|
-
} from "
|
|
19
|
-
import type { Transceiver } from "../mutable"
|
|
19
|
+
} from "../state-types"
|
|
20
20
|
import { type Store, withdraw } from "../store"
|
|
21
21
|
|
|
22
22
|
export function getFamilyOfToken<
|
|
@@ -2,48 +2,71 @@ import type { ReadableToken, WritableToken } from "atom.io"
|
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
import { stringifyJson } from "atom.io/json"
|
|
4
4
|
|
|
5
|
-
import type { ReadableFamily } from "
|
|
5
|
+
import type { ReadableFamily } from "../state-types"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
export const FAMILY_MEMBER_TOKEN_TYPES = {
|
|
9
|
+
atom_family: `atom`,
|
|
10
|
+
molecule_family: `molecule`,
|
|
11
|
+
mutable_atom_family: `mutable_atom`,
|
|
12
|
+
readonly_held_selector_family: `readonly_held_selector`,
|
|
13
|
+
readonly_pure_selector_family: `readonly_pure_selector`,
|
|
14
|
+
writable_held_selector_family: `writable_held_selector`,
|
|
15
|
+
writable_pure_selector_family: `writable_pure_selector`,
|
|
16
|
+
} as const
|
|
8
17
|
|
|
9
18
|
export const MUST_CREATE: unique symbol = Symbol(`MUST_CREATE`)
|
|
19
|
+
export const DO_NOT_CREATE: unique symbol = Symbol(`DO_NOT_CREATE`)
|
|
10
20
|
|
|
11
|
-
export function mintInStore<T, K extends Canonical,
|
|
21
|
+
export function mintInStore<T, K extends Canonical, KK extends K, E>(
|
|
22
|
+
mustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,
|
|
12
23
|
store: Store,
|
|
13
24
|
family: ReadableFamily<T, K, E>,
|
|
14
|
-
key:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
25
|
+
key: KK,
|
|
26
|
+
): WritableToken<T, KK, E>
|
|
27
|
+
export function mintInStore<T, K extends Canonical, KK extends K, E>(
|
|
28
|
+
mustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,
|
|
18
29
|
store: Store,
|
|
19
30
|
family: ReadableFamily<T, K, E>,
|
|
20
|
-
key:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
key: KK,
|
|
32
|
+
): ReadableToken<T, KK, E>
|
|
33
|
+
export function mintInStore<T, K extends Canonical, KK extends K, E>(
|
|
34
|
+
mustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,
|
|
24
35
|
store: Store,
|
|
25
36
|
family: ReadableFamily<T, K, E>,
|
|
26
|
-
key:
|
|
27
|
-
|
|
28
|
-
): ReadableToken<T, Key, E> {
|
|
37
|
+
key: KK,
|
|
38
|
+
): ReadableToken<T, KK, E> {
|
|
29
39
|
const stringKey = stringifyJson(key)
|
|
30
40
|
const molecule = store.molecules.get(stringKey)
|
|
31
41
|
|
|
32
42
|
const cannotCreate = !molecule && store.config.lifespan === `immortal`
|
|
33
43
|
|
|
34
44
|
if (cannotCreate) {
|
|
45
|
+
const { type: familyType, key: familyKey } = family
|
|
35
46
|
store.logger.warn(
|
|
36
47
|
`💣`,
|
|
37
48
|
`key`,
|
|
38
49
|
stringKey,
|
|
39
50
|
`was used to mint a counterfeit token for`,
|
|
40
|
-
|
|
41
|
-
`"${
|
|
51
|
+
familyType,
|
|
52
|
+
`"${familyKey}"`,
|
|
42
53
|
)
|
|
43
|
-
|
|
54
|
+
const fullKey = `${familyKey}(${stringKey})`
|
|
55
|
+
const type = FAMILY_MEMBER_TOKEN_TYPES[familyType]
|
|
56
|
+
const stateToken: ReadableToken<T, KK, E> & { counterfeit: true } = {
|
|
57
|
+
counterfeit: true,
|
|
58
|
+
key: fullKey,
|
|
59
|
+
type,
|
|
60
|
+
family: {
|
|
61
|
+
key: familyKey,
|
|
62
|
+
subKey: stringKey,
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return stateToken
|
|
44
67
|
}
|
|
45
68
|
|
|
46
|
-
let token: ReadableToken<T,
|
|
69
|
+
let token: ReadableToken<T, KK, E>
|
|
47
70
|
if (mustCreate === MUST_CREATE) {
|
|
48
71
|
store.logger.info(
|
|
49
72
|
`👪`,
|
|
@@ -57,7 +80,19 @@ export function mintInStore<T, K extends Canonical, Key extends K, E>(
|
|
|
57
80
|
store.moleculeData.set(stringKey, family.key)
|
|
58
81
|
}
|
|
59
82
|
} else {
|
|
60
|
-
|
|
83
|
+
const { type: familyType, key: familyKey } = family
|
|
84
|
+
const fullKey = `${familyKey}(${stringKey})`
|
|
85
|
+
const type = FAMILY_MEMBER_TOKEN_TYPES[familyType]
|
|
86
|
+
const stateToken: ReadableToken<T, KK, E> = {
|
|
87
|
+
key: fullKey,
|
|
88
|
+
type,
|
|
89
|
+
family: {
|
|
90
|
+
key: familyKey,
|
|
91
|
+
subKey: stringKey,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return stateToken
|
|
61
96
|
}
|
|
62
97
|
|
|
63
98
|
return token
|
|
@@ -19,9 +19,9 @@ import type {
|
|
|
19
19
|
import type { Canonical } from "atom.io/json"
|
|
20
20
|
import { stringifyJson } from "atom.io/json"
|
|
21
21
|
|
|
22
|
-
import type { ReadableState } from ".."
|
|
23
22
|
import { newest } from "../lineage"
|
|
24
23
|
import type { Transceiver } from "../mutable"
|
|
24
|
+
import type { ReadableState } from "../state-types"
|
|
25
25
|
import { deposit, type Store } from "../store"
|
|
26
26
|
|
|
27
27
|
export function seekInStore<
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ReadableToken, ViewOf } from "atom.io"
|
|
2
2
|
import { type Canonical, stringifyJson } from "atom.io/json"
|
|
3
3
|
|
|
4
|
-
import type { ReadableFamily } from "
|
|
4
|
+
import type { ReadableFamily } from "../state-types"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
|
|
7
7
|
export function getFallback<T, K extends Canonical, E>(
|
|
8
8
|
store: Store,
|
|
9
9
|
token: ReadableToken<T, K, E>,
|
|
10
10
|
family: ReadableFamily<T, K, E>,
|
|
11
|
-
subKey: K
|
|
11
|
+
subKey: NoInfer<K>,
|
|
12
12
|
): ViewOf<E | T> {
|
|
13
13
|
const disposal = store.disposalTraces.buffer.find(
|
|
14
14
|
(item) => item?.key === stringifyJson(subKey),
|
|
@@ -16,20 +16,20 @@ export function getFromStore<T, E>(
|
|
|
16
16
|
export function getFromStore<T, K extends Canonical, E>(
|
|
17
17
|
store: Store,
|
|
18
18
|
token: ReadableFamilyToken<T, K, E>,
|
|
19
|
-
key: K
|
|
19
|
+
key: NoInfer<K>,
|
|
20
20
|
): ViewOf<E | T>
|
|
21
21
|
|
|
22
|
-
export function getFromStore<T, K extends Canonical,
|
|
22
|
+
export function getFromStore<T, K extends Canonical, E>(
|
|
23
23
|
store: Store,
|
|
24
24
|
...params:
|
|
25
|
-
| [token: ReadableFamilyToken<T, K, E>, key:
|
|
25
|
+
| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]
|
|
26
26
|
| [token: ReadableToken<T, any, E>]
|
|
27
27
|
): ViewOf<E | T>
|
|
28
28
|
|
|
29
|
-
export function getFromStore<T, K extends Canonical,
|
|
29
|
+
export function getFromStore<T, K extends Canonical, E>(
|
|
30
30
|
store: Store,
|
|
31
31
|
...params:
|
|
32
|
-
| [token: ReadableFamilyToken<T, K, E>, key:
|
|
32
|
+
| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]
|
|
33
33
|
| [token: ReadableToken<T, any, E>]
|
|
34
34
|
): ViewOf<E | T> {
|
|
35
35
|
const { token, family, subKey } = reduceReference(store, ...params)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ViewOf } from "atom.io"
|
|
2
2
|
|
|
3
|
-
import type { ReadableState } from ".."
|
|
4
3
|
import { readFromCache, writeToCache } from "../caching"
|
|
5
4
|
import { safeCompute } from "../safe-compute"
|
|
5
|
+
import type { ReadableState } from "../state-types"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
|
|
8
8
|
export function readOrComputeValue<T, E>(
|
|
@@ -5,23 +5,25 @@ import type {
|
|
|
5
5
|
} from "atom.io"
|
|
6
6
|
import { type Canonical, parseJson } from "atom.io/json"
|
|
7
7
|
|
|
8
|
-
import type { ReadableFamily, Subject } from ".."
|
|
9
|
-
import { isChildStore, isRootStore, newest } from ".."
|
|
10
8
|
import { seekInStore } from "../families"
|
|
11
9
|
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
12
10
|
import { mintInStore, MUST_CREATE } from "../families/mint-in-store"
|
|
11
|
+
import { newest } from "../lineage"
|
|
12
|
+
import type { ReadableFamily } from "../state-types"
|
|
13
13
|
import type { Store } from "../store"
|
|
14
14
|
import { withdraw } from "../store"
|
|
15
|
+
import type { Subject } from "../subject"
|
|
16
|
+
import { isChildStore, isRootStore } from "../transaction"
|
|
15
17
|
|
|
16
18
|
export function reduceReference<T, K extends Canonical, E>(
|
|
17
19
|
store: Store,
|
|
18
20
|
...params:
|
|
19
|
-
| [token: ReadableFamilyToken<T, K, E>, key: K]
|
|
21
|
+
| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]
|
|
20
22
|
| [token: ReadableToken<T, K, E>]
|
|
21
23
|
): {
|
|
22
24
|
token: ReadableToken<T, K, E>
|
|
23
25
|
family: ReadableFamily<T, K, E> | undefined
|
|
24
|
-
subKey: K | undefined
|
|
26
|
+
subKey: NoInfer<K> | undefined
|
|
25
27
|
isNew: boolean
|
|
26
28
|
} {
|
|
27
29
|
let existingToken: ReadableToken<T, K, E> | undefined
|
|
@@ -45,7 +47,7 @@ export function reduceReference<T, K extends Canonical, E>(
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
if (!existingToken) {
|
|
48
|
-
brandNewToken = mintInStore(store, familyToken, subKey
|
|
50
|
+
brandNewToken = mintInStore(MUST_CREATE, store, familyToken, subKey)
|
|
49
51
|
token = brandNewToken
|
|
50
52
|
} else {
|
|
51
53
|
token = existingToken
|
|
@@ -56,7 +58,7 @@ export function reduceReference<T, K extends Canonical, E>(
|
|
|
56
58
|
subKey = params[1]
|
|
57
59
|
existingToken = seekInStore(store, family, subKey)
|
|
58
60
|
if (!existingToken) {
|
|
59
|
-
brandNewToken = mintInStore(store, family, subKey
|
|
61
|
+
brandNewToken = mintInStore(MUST_CREATE, store, family, subKey)
|
|
60
62
|
token = brandNewToken
|
|
61
63
|
} else {
|
|
62
64
|
token = existingToken
|