atom.io 0.18.0 → 0.18.2
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/dist/chunk-3J2EGSBE.js +31 -0
- package/dist/chunk-3J2EGSBE.js.map +1 -0
- package/dist/chunk-A4ZCNKWQ.js +18 -0
- package/dist/chunk-A4ZCNKWQ.js.map +1 -0
- package/dist/{chunk-OEVFAUPE.js → chunk-IZHOMSXA.js} +53 -11
- package/dist/chunk-IZHOMSXA.js.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +110 -134
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +24 -24
- package/internal/dist/index.js +110 -134
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/delete-atom.ts +7 -6
- package/internal/src/caching.ts +6 -6
- package/internal/src/families/create-regular-atom-family.ts +4 -4
- package/internal/src/get-state/get-from-store.ts +2 -5
- package/internal/src/ingest-updates/ingest-atom-update.ts +6 -2
- package/internal/src/mutable/create-mutable-atom-family.ts +4 -4
- package/internal/src/selector/register-selector.ts +3 -14
- package/internal/src/set-state/copy-mutable-if-needed.ts +5 -0
- package/internal/src/set-state/emit-update.ts +25 -11
- package/internal/src/set-state/set-atom.ts +4 -3
- package/internal/src/set-state/set-into-store.ts +2 -5
- package/internal/src/store/withdraw-new-family-member.ts +38 -28
- package/internal/src/store/withdraw.ts +20 -23
- package/internal/src/subscribe/subscribe-to-state.ts +2 -3
- package/internal/src/subscribe/subscribe-to-timeline.ts +0 -5
- package/internal/src/subscribe/subscribe-to-transaction.ts +0 -5
- package/internal/src/timeline/add-atom-to-timeline.ts +6 -15
- package/internal/src/timeline/create-timeline.ts +0 -27
- package/internal/src/transaction/apply-transaction.ts +0 -1
- package/internal/src/transaction/set-epoch-number.ts +0 -1
- package/json/src/index.ts +3 -3
- package/package.json +242 -241
- package/react/dist/index.cjs +2 -3
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.js +2 -3
- package/react/dist/index.js.map +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.cjs +1 -1
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.js +1 -15
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +6 -6
- package/react-devtools/src/StateIndex.tsx +2 -2
- package/react-devtools/src/Updates.tsx +1 -1
- package/react-devtools/src/index.ts +3 -3
- package/realtime/dist/index.cjs +50 -2
- package/realtime/dist/index.cjs.map +1 -1
- package/realtime/dist/index.d.ts +110 -3
- package/realtime/dist/index.js +47 -4
- package/realtime/dist/index.js.map +1 -1
- package/realtime/src/index.ts +1 -0
- package/realtime/src/realtime-continuity.ts +14 -4
- package/realtime/src/shared-room-store.ts +48 -0
- package/realtime-client/dist/index.cjs +113 -200
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +2 -5
- package/realtime-client/dist/index.js +22 -190
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +0 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +5 -5
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +10 -0
- package/realtime-client/src/sync-continuity.ts +56 -9
- package/realtime-react/dist/index.cjs +51 -26
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +2 -6
- package/realtime-react/dist/index.js +2 -17
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +0 -2
- package/realtime-server/dist/index.cjs +399 -327
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +55 -60
- package/realtime-server/dist/index.js +394 -319
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +2 -4
- package/realtime-server/src/ipc-sockets/child-socket.ts +135 -0
- package/realtime-server/src/ipc-sockets/custom-socket.ts +90 -0
- package/realtime-server/src/ipc-sockets/index.ts +3 -0
- package/realtime-server/src/ipc-sockets/parent-socket.ts +186 -0
- package/realtime-server/src/realtime-continuity-synchronizer.ts +225 -96
- package/realtime-server/src/realtime-server-stores/index.ts +2 -1
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +50 -31
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +64 -0
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +42 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +49 -26
- package/realtime-testing/dist/index.cjs +51 -11
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.ts +1 -0
- package/realtime-testing/dist/index.js +11 -11
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +11 -11
- package/src/logger.ts +5 -1
- package/dist/chunk-OEVFAUPE.js.map +0 -1
- package/realtime-client/src/sync-server-action.ts +0 -168
- package/realtime-client/src/sync-state.ts +0 -19
- package/realtime-react/src/use-sync-server-action.ts +0 -17
- package/realtime-react/src/use-sync.ts +0 -17
- package/realtime-server/src/ipc-socket.ts +0 -230
- package/realtime-server/src/realtime-action-synchronizer.ts +0 -164
- package/realtime-server/src/realtime-server-stores/server-room-store.ts +0 -97
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AtomToken } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Store } from ".."
|
|
4
|
-
import { deleteSelector, newest } from ".."
|
|
4
|
+
import { deleteSelector, getUpdateToken, newest } from ".."
|
|
5
5
|
|
|
6
|
-
export function deleteAtom(
|
|
7
|
-
atomToken: RegularAtomToken<unknown>,
|
|
8
|
-
store: Store,
|
|
9
|
-
): void {
|
|
6
|
+
export function deleteAtom(atomToken: AtomToken<unknown>, store: Store): void {
|
|
10
7
|
const target = newest(store)
|
|
11
8
|
const { key } = atomToken
|
|
12
9
|
const atom = target.atoms.get(key)
|
|
@@ -35,5 +32,9 @@ export function deleteAtom(
|
|
|
35
32
|
target.selectorAtoms.delete(key)
|
|
36
33
|
target.atomsThatAreDefault.delete(key)
|
|
37
34
|
target.timelineAtoms.delete(key)
|
|
35
|
+
if (atomToken.type === `mutable_atom`) {
|
|
36
|
+
const updateToken = getUpdateToken(atomToken)
|
|
37
|
+
deleteAtom(updateToken, store)
|
|
38
|
+
}
|
|
38
39
|
store.logger.info(`🔥`, `atom`, `${key}`, `deleted`)
|
|
39
40
|
}
|
package/internal/src/caching.ts
CHANGED
|
@@ -53,12 +53,12 @@ export const readCachedValue = <T>(
|
|
|
53
53
|
token: ReadableState<any>,
|
|
54
54
|
target: Store,
|
|
55
55
|
): T => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
let value = target.valueMap.get(token.key) as T
|
|
57
|
+
if (token.type === `mutable_atom` && isChildStore(target)) {
|
|
58
|
+
const { parent } = target
|
|
59
|
+
const copiedValue = copyMutableIfNeeded(token, parent, target)
|
|
60
|
+
value = copiedValue
|
|
61
|
+
}
|
|
62
62
|
return value
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -10,7 +10,6 @@ import { stringifyJson } from "atom.io/json"
|
|
|
10
10
|
|
|
11
11
|
import { createRegularAtom } from "../atom"
|
|
12
12
|
import { newest } from "../lineage"
|
|
13
|
-
import { deposit, withdraw } from "../store"
|
|
14
13
|
import type { Store } from "../store"
|
|
15
14
|
import { Subject } from "../subject"
|
|
16
15
|
|
|
@@ -24,10 +23,11 @@ export function createRegularAtomFamily<T, K extends Json.Serializable>(
|
|
|
24
23
|
const subKey = stringifyJson(key)
|
|
25
24
|
const family: FamilyMetadata = { key: options.key, subKey }
|
|
26
25
|
const fullKey = `${options.key}(${subKey})`
|
|
27
|
-
const
|
|
26
|
+
const target = newest(store)
|
|
27
|
+
const atomAlreadyCreated = target.atoms.has(fullKey)
|
|
28
28
|
let token: RegularAtomToken<any>
|
|
29
|
-
if (
|
|
30
|
-
token =
|
|
29
|
+
if (atomAlreadyCreated) {
|
|
30
|
+
token = { type: `atom`, key: fullKey, family }
|
|
31
31
|
} else {
|
|
32
32
|
const individualOptions: RegularAtomOptions<any> = {
|
|
33
33
|
key: fullKey,
|
|
@@ -2,13 +2,10 @@ import type { ReadableToken } from "atom.io"
|
|
|
2
2
|
|
|
3
3
|
import { NotFoundError } from "../not-found-error"
|
|
4
4
|
import type { Store } from "../store"
|
|
5
|
-
import { withdraw,
|
|
5
|
+
import { withdraw, withdrawOrCreate } from "../store"
|
|
6
6
|
import { readOrComputeValue } from "./read-or-compute-value"
|
|
7
7
|
|
|
8
8
|
export function getFromStore<T>(token: ReadableToken<T>, store: Store): T {
|
|
9
|
-
const state =
|
|
10
|
-
if (state === undefined) {
|
|
11
|
-
throw new NotFoundError(token, store)
|
|
12
|
-
}
|
|
9
|
+
const state = withdrawOrCreate(token, store)
|
|
13
10
|
return readOrComputeValue(state, store)
|
|
14
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KeyedStateUpdate } from "atom.io"
|
|
1
|
+
import type { KeyedStateUpdate, RegularAtomToken } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import { setIntoStore } from "../set-state"
|
|
4
4
|
import type { Store } from "../store"
|
|
@@ -10,5 +10,9 @@ export function ingestAtomUpdate(
|
|
|
10
10
|
): void {
|
|
11
11
|
const { key, newValue, oldValue } = atomUpdate
|
|
12
12
|
const value = applying === `newValue` ? newValue : oldValue
|
|
13
|
-
|
|
13
|
+
const token: RegularAtomToken<unknown> = { key, type: `atom` }
|
|
14
|
+
if (atomUpdate.family) {
|
|
15
|
+
Object.assign(token, { family: atomUpdate.family })
|
|
16
|
+
}
|
|
17
|
+
setIntoStore(token, value, store)
|
|
14
18
|
}
|
|
@@ -11,7 +11,6 @@ import { stringifyJson } from "atom.io/json"
|
|
|
11
11
|
|
|
12
12
|
import { newest } from "../lineage"
|
|
13
13
|
import { createMutableAtom } from "../mutable"
|
|
14
|
-
import { deposit, withdraw } from "../store"
|
|
15
14
|
import type { Store } from "../store"
|
|
16
15
|
import { Subject } from "../subject"
|
|
17
16
|
import { FamilyTracker } from "./tracker-family"
|
|
@@ -31,10 +30,11 @@ export function createMutableAtomFamily<
|
|
|
31
30
|
const subKey = stringifyJson(key)
|
|
32
31
|
const family: FamilyMetadata = { key: options.key, subKey }
|
|
33
32
|
const fullKey = `${options.key}(${subKey})`
|
|
34
|
-
const
|
|
33
|
+
const target = newest(store)
|
|
34
|
+
const atomAlreadyCreated = target.atoms.has(fullKey)
|
|
35
35
|
let token: MutableAtomToken<T, J>
|
|
36
|
-
if (
|
|
37
|
-
token =
|
|
36
|
+
if (atomAlreadyCreated) {
|
|
37
|
+
token = { type: `mutable_atom`, key: fullKey, family }
|
|
38
38
|
} else {
|
|
39
39
|
const individualOptions: MutableAtomOptions<T, J> = {
|
|
40
40
|
key: fullKey,
|
|
@@ -5,7 +5,7 @@ import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
|
5
5
|
import { newest } from "../lineage"
|
|
6
6
|
import { setAtomOrSelector } from "../set-state"
|
|
7
7
|
import type { Store } from "../store"
|
|
8
|
-
import {
|
|
8
|
+
import { withdrawOrCreate } from "../store"
|
|
9
9
|
import { updateSelectorAtoms } from "./update-selector-atoms"
|
|
10
10
|
|
|
11
11
|
export const registerSelector = (
|
|
@@ -15,13 +15,7 @@ export const registerSelector = (
|
|
|
15
15
|
get: (dependency) => {
|
|
16
16
|
const target = newest(store)
|
|
17
17
|
|
|
18
|
-
const dependencyState =
|
|
19
|
-
withdraw(dependency, store) ?? withdrawNewFamilyMember(dependency, store)
|
|
20
|
-
if (dependencyState === undefined) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
`State "${dependency.key}" not found in store "${store.config.name}".`,
|
|
23
|
-
)
|
|
24
|
-
}
|
|
18
|
+
const dependencyState = withdrawOrCreate(dependency, store)
|
|
25
19
|
const dependencyValue = readOrComputeValue(dependencyState, store)
|
|
26
20
|
|
|
27
21
|
store.logger.info(
|
|
@@ -46,12 +40,7 @@ export const registerSelector = (
|
|
|
46
40
|
return dependencyValue
|
|
47
41
|
},
|
|
48
42
|
set: (WritableToken, newValue) => {
|
|
49
|
-
const state =
|
|
50
|
-
if (state === undefined) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`State "${WritableToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
43
|
+
const state = withdrawOrCreate(WritableToken, store)
|
|
55
44
|
setAtomOrSelector(state, newValue, store)
|
|
56
45
|
},
|
|
57
46
|
find: ((token, key) => findInStore(token, key, store)) as typeof findState,
|
|
@@ -9,7 +9,12 @@ export function copyMutableIfNeeded<T extends Transceiver<any>>(
|
|
|
9
9
|
): T {
|
|
10
10
|
const originValue = origin.valueMap.get(atom.key)
|
|
11
11
|
const targetValue = target.valueMap.get(atom.key)
|
|
12
|
+
|
|
12
13
|
if (originValue === targetValue) {
|
|
14
|
+
if (originValue === undefined) {
|
|
15
|
+
return typeof atom.default === `function` ? atom.default() : atom.default
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
origin.logger.info(`📃`, `atom`, `${atom.key}`, `copying`)
|
|
14
19
|
const jsonValue = atom.toJson(originValue)
|
|
15
20
|
const copiedValue = atom.fromJson(jsonValue)
|
|
@@ -8,16 +8,30 @@ export const emitUpdate = <T>(
|
|
|
8
8
|
update: StateUpdate<T>,
|
|
9
9
|
store: Store,
|
|
10
10
|
): void => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
switch (state.type) {
|
|
12
|
+
case `mutable_atom`:
|
|
13
|
+
store.logger.info(
|
|
14
|
+
`📢`,
|
|
15
|
+
state.type,
|
|
16
|
+
state.key,
|
|
17
|
+
`is now (`,
|
|
18
|
+
update.newValue,
|
|
19
|
+
`) subscribers:`,
|
|
20
|
+
state.subject.subscribers,
|
|
21
|
+
)
|
|
22
|
+
break
|
|
23
|
+
default:
|
|
24
|
+
store.logger.info(
|
|
25
|
+
`📢`,
|
|
26
|
+
state.type,
|
|
27
|
+
state.key,
|
|
28
|
+
`went (`,
|
|
29
|
+
update.oldValue,
|
|
30
|
+
`->`,
|
|
31
|
+
update.newValue,
|
|
32
|
+
`) subscribers:`,
|
|
33
|
+
state.subject.subscribers,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
22
36
|
state.subject.next(update)
|
|
23
37
|
}
|
|
@@ -42,12 +42,13 @@ export const setAtom = <T>(
|
|
|
42
42
|
const mutableKey = atom.key.slice(1)
|
|
43
43
|
const mutableAtom = target.atoms.get(mutableKey) as Atom<any>
|
|
44
44
|
let transceiver: Transceiver<any> = target.valueMap.get(mutableKey)
|
|
45
|
-
if (
|
|
45
|
+
if (mutableAtom.type === `mutable_atom` && isChildStore(target)) {
|
|
46
46
|
const { parent } = target
|
|
47
|
-
const copiedValue = copyMutableIfNeeded(
|
|
47
|
+
const copiedValue = copyMutableIfNeeded(mutableAtom, parent, target)
|
|
48
48
|
transceiver = copiedValue
|
|
49
49
|
}
|
|
50
|
-
transceiver.do(update.newValue)
|
|
50
|
+
const accepted = transceiver.do(update.newValue) === null
|
|
51
|
+
if (accepted) evictDownStream(mutableAtom, target)
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -3,7 +3,7 @@ import type { WritableToken } from "atom.io"
|
|
|
3
3
|
import { NotFoundError } from "../not-found-error"
|
|
4
4
|
import { closeOperation, openOperation } from "../operation"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
|
-
import {
|
|
6
|
+
import { withdrawOrCreate } from "../store"
|
|
7
7
|
import { setAtomOrSelector } from "./set-atom-or-selector"
|
|
8
8
|
|
|
9
9
|
export function setIntoStore<T, New extends T>(
|
|
@@ -15,10 +15,7 @@ export function setIntoStore<T, New extends T>(
|
|
|
15
15
|
if (rejection) {
|
|
16
16
|
return
|
|
17
17
|
}
|
|
18
|
-
const state =
|
|
19
|
-
if (state === undefined) {
|
|
20
|
-
throw new NotFoundError(token, store)
|
|
21
|
-
}
|
|
18
|
+
const state = withdrawOrCreate(token, store)
|
|
22
19
|
setAtomOrSelector(state, value, store)
|
|
23
20
|
closeOperation(store)
|
|
24
21
|
}
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
WritableSelectorToken,
|
|
6
6
|
WritableToken,
|
|
7
7
|
} from "atom.io"
|
|
8
|
+
|
|
8
9
|
import type {
|
|
9
10
|
Atom,
|
|
10
11
|
ReadableState,
|
|
@@ -13,47 +14,56 @@ import type {
|
|
|
13
14
|
WritableSelector,
|
|
14
15
|
WritableState,
|
|
15
16
|
} from ".."
|
|
16
|
-
import { newest, withdraw } from ".."
|
|
17
|
+
import { NotFoundError, newest, withdraw } from ".."
|
|
17
18
|
|
|
18
|
-
export function
|
|
19
|
+
export function withdrawOrCreate<T>(
|
|
19
20
|
token: RegularAtomToken<T>,
|
|
20
21
|
store: Store,
|
|
21
|
-
): Atom<T>
|
|
22
|
-
export function
|
|
22
|
+
): Atom<T>
|
|
23
|
+
export function withdrawOrCreate<T>(
|
|
23
24
|
token: WritableSelectorToken<T>,
|
|
24
25
|
store: Store,
|
|
25
|
-
): WritableSelector<T>
|
|
26
|
-
export function
|
|
26
|
+
): WritableSelector<T>
|
|
27
|
+
export function withdrawOrCreate<T>(
|
|
27
28
|
token: ReadonlySelectorToken<T>,
|
|
28
29
|
store: Store,
|
|
29
|
-
): ReadonlySelector<T>
|
|
30
|
-
export function
|
|
30
|
+
): ReadonlySelector<T>
|
|
31
|
+
export function withdrawOrCreate<T>(
|
|
31
32
|
token: WritableToken<T>,
|
|
32
33
|
store: Store,
|
|
33
|
-
): WritableState<T>
|
|
34
|
-
export function
|
|
34
|
+
): WritableState<T>
|
|
35
|
+
export function withdrawOrCreate<T>(
|
|
35
36
|
token: ReadableToken<T>,
|
|
36
37
|
store: Store,
|
|
37
|
-
): ReadableState<T>
|
|
38
|
-
export function
|
|
38
|
+
): ReadableState<T>
|
|
39
|
+
export function withdrawOrCreate<T>(
|
|
39
40
|
token: ReadableToken<T>,
|
|
40
41
|
store: Store,
|
|
41
|
-
): ReadableState<T>
|
|
42
|
-
|
|
43
|
-
store
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
42
|
+
): ReadableState<T> {
|
|
43
|
+
try {
|
|
44
|
+
const state = withdraw(token, store)
|
|
45
|
+
return state
|
|
46
|
+
} catch (notFoundError) {
|
|
47
|
+
if (token.family) {
|
|
48
|
+
store.logger.info(
|
|
49
|
+
`👪`,
|
|
50
|
+
token.type,
|
|
51
|
+
token.key,
|
|
52
|
+
`creating new family member in store "${store.config.name}"`,
|
|
53
|
+
)
|
|
54
|
+
const target = newest(store)
|
|
55
|
+
const family = target.families.get(token.family.key)
|
|
56
|
+
if (family) {
|
|
57
|
+
const jsonSubKey = JSON.parse(token.family.subKey)
|
|
58
|
+
family(jsonSubKey)
|
|
59
|
+
const state = withdraw(token, store)
|
|
60
|
+
return state
|
|
61
|
+
}
|
|
62
|
+
throw new NotFoundError(
|
|
63
|
+
{ key: token.family.key, type: `${token.type}_family` },
|
|
64
|
+
store,
|
|
65
|
+
)
|
|
56
66
|
}
|
|
67
|
+
throw notFoundError
|
|
57
68
|
}
|
|
58
|
-
return undefined
|
|
59
69
|
}
|
|
@@ -37,6 +37,8 @@ import type {
|
|
|
37
37
|
WritableSelector,
|
|
38
38
|
WritableState,
|
|
39
39
|
} from ".."
|
|
40
|
+
import { NotFoundError } from ".."
|
|
41
|
+
|
|
40
42
|
import type { Timeline } from "../timeline"
|
|
41
43
|
import type { Transaction } from "../transaction"
|
|
42
44
|
import type { Store } from "./store"
|
|
@@ -63,40 +65,34 @@ export type Withdrawable =
|
|
|
63
65
|
export function withdraw<T>(
|
|
64
66
|
token: RegularAtomToken<T>,
|
|
65
67
|
store: Store,
|
|
66
|
-
): RegularAtom<T>
|
|
68
|
+
): RegularAtom<T>
|
|
67
69
|
export function withdraw<T extends Transceiver<any>>(
|
|
68
70
|
token: MutableAtomToken<T, any>,
|
|
69
71
|
store: Store,
|
|
70
|
-
): MutableAtom<T, any>
|
|
71
|
-
export function withdraw<T>(
|
|
72
|
-
token: AtomToken<T>,
|
|
73
|
-
store: Store,
|
|
74
|
-
): Atom<T> | undefined
|
|
72
|
+
): MutableAtom<T, any>
|
|
73
|
+
export function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>
|
|
75
74
|
export function withdraw<T>(
|
|
76
75
|
token: WritableSelectorToken<T>,
|
|
77
76
|
store: Store,
|
|
78
|
-
): WritableSelector<T>
|
|
77
|
+
): WritableSelector<T>
|
|
79
78
|
export function withdraw<T>(
|
|
80
79
|
token: ReadonlySelectorToken<T>,
|
|
81
80
|
store: Store,
|
|
82
|
-
): ReadonlySelector<T>
|
|
83
|
-
export function withdraw<T>(
|
|
84
|
-
token: SelectorToken<T>,
|
|
85
|
-
store: Store,
|
|
86
|
-
): Selector<T> | undefined
|
|
81
|
+
): ReadonlySelector<T>
|
|
82
|
+
export function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>
|
|
87
83
|
export function withdraw<T>(
|
|
88
84
|
token: WritableToken<T>,
|
|
89
85
|
store: Store,
|
|
90
|
-
): WritableState<T>
|
|
86
|
+
): WritableState<T>
|
|
91
87
|
export function withdraw<T>(
|
|
92
88
|
token: ReadableToken<T>,
|
|
93
89
|
store: Store,
|
|
94
|
-
): ReadableState<T>
|
|
90
|
+
): ReadableState<T>
|
|
95
91
|
|
|
96
92
|
export function withdraw<T, K extends Json.Serializable>(
|
|
97
93
|
token: RegularAtomFamilyToken<T, K>,
|
|
98
94
|
store: Store,
|
|
99
|
-
): RegularAtomFamily<T, K>
|
|
95
|
+
): RegularAtomFamily<T, K>
|
|
100
96
|
export function withdraw<
|
|
101
97
|
T extends Transceiver<any>,
|
|
102
98
|
J extends Json.Serializable,
|
|
@@ -104,32 +100,32 @@ export function withdraw<
|
|
|
104
100
|
>(
|
|
105
101
|
token: MutableAtomFamilyToken<T, J, K>,
|
|
106
102
|
store: Store,
|
|
107
|
-
): MutableAtomFamily<T, J, K>
|
|
103
|
+
): MutableAtomFamily<T, J, K>
|
|
108
104
|
export function withdraw<T, K extends Json.Serializable>(
|
|
109
105
|
token: AtomFamilyToken<T>,
|
|
110
106
|
store: Store,
|
|
111
|
-
): AtomFamily<T, any>
|
|
107
|
+
): AtomFamily<T, any>
|
|
112
108
|
export function withdraw<T, K extends Json.Serializable>(
|
|
113
109
|
token: ReadonlySelectorFamilyToken<T, K>,
|
|
114
110
|
store: Store,
|
|
115
|
-
): ReadonlySelectorFamily<T, any>
|
|
111
|
+
): ReadonlySelectorFamily<T, any>
|
|
116
112
|
export function withdraw<T, K extends Json.Serializable>(
|
|
117
113
|
token: WritableSelectorFamilyToken<T, K>,
|
|
118
114
|
store: Store,
|
|
119
|
-
): WritableSelectorFamily<T, any>
|
|
115
|
+
): WritableSelectorFamily<T, any>
|
|
120
116
|
export function withdraw<T, K extends Json.Serializable>(
|
|
121
117
|
token: SelectorFamilyToken<T, K>,
|
|
122
118
|
store: Store,
|
|
123
|
-
): SelectorFamily<T, any>
|
|
119
|
+
): SelectorFamily<T, any>
|
|
124
120
|
|
|
125
121
|
export function withdraw<T>(
|
|
126
122
|
token: TransactionToken<T>,
|
|
127
123
|
store: Store,
|
|
128
|
-
): Transaction<T extends ƒn ? T : never>
|
|
124
|
+
): Transaction<T extends ƒn ? T : never>
|
|
129
125
|
export function withdraw<T>(
|
|
130
126
|
token: TimelineToken<T>,
|
|
131
127
|
store: Store,
|
|
132
|
-
): Timeline<T extends TimelineManageable ? T : never>
|
|
128
|
+
): Timeline<T extends TimelineManageable ? T : never>
|
|
133
129
|
export function withdraw<T>(
|
|
134
130
|
token:
|
|
135
131
|
| RegularAtomFamilyToken<T, any>
|
|
@@ -142,7 +138,7 @@ export function withdraw<T>(
|
|
|
142
138
|
? MutableAtomFamilyToken<T, any, any> | MutableAtomToken<T, any>
|
|
143
139
|
: never),
|
|
144
140
|
store: Store,
|
|
145
|
-
): Withdrawable
|
|
141
|
+
): Withdrawable {
|
|
146
142
|
let withdrawn: Withdrawable | undefined
|
|
147
143
|
let target: Store | null = store
|
|
148
144
|
while (target !== null) {
|
|
@@ -175,4 +171,5 @@ export function withdraw<T>(
|
|
|
175
171
|
}
|
|
176
172
|
target = target.child
|
|
177
173
|
}
|
|
174
|
+
throw new NotFoundError(token, store)
|
|
178
175
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReadableToken, UpdateHandler } from "atom.io"
|
|
2
2
|
import type { Store } from "../store"
|
|
3
|
-
import {
|
|
3
|
+
import { withdrawOrCreate } from "../store"
|
|
4
4
|
import { subscribeToRootAtoms } from "./subscribe-to-root-atoms"
|
|
5
5
|
|
|
6
6
|
export function subscribeToState<T>(
|
|
@@ -9,8 +9,7 @@ export function subscribeToState<T>(
|
|
|
9
9
|
key: string,
|
|
10
10
|
store: Store,
|
|
11
11
|
): () => void {
|
|
12
|
-
const state =
|
|
13
|
-
withdraw<T>(token, store) ?? withdrawNewFamilyMember(token, store)
|
|
12
|
+
const state = withdrawOrCreate(token, store)
|
|
14
13
|
if (state === undefined) {
|
|
15
14
|
throw new Error(
|
|
16
15
|
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
@@ -9,11 +9,6 @@ export const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(
|
|
|
9
9
|
store: Store,
|
|
10
10
|
): (() => void) => {
|
|
11
11
|
const tl = withdraw(token, store)
|
|
12
|
-
if (tl === undefined) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`,
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
12
|
store.logger.info(`👀`, `timeline`, token.key, `Adding subscription "${key}"`)
|
|
18
13
|
const unsubscribe = tl.subject.subscribe(key, handleUpdate)
|
|
19
14
|
return () => {
|
|
@@ -9,11 +9,6 @@ export const subscribeToTransaction = <ƒ extends ƒn>(
|
|
|
9
9
|
store: Store,
|
|
10
10
|
): (() => void) => {
|
|
11
11
|
const tx = withdraw(token, store)
|
|
12
|
-
if (tx === undefined) {
|
|
13
|
-
throw new Error(
|
|
14
|
-
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`,
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
12
|
store.logger.info(
|
|
18
13
|
`👀`,
|
|
19
14
|
`transaction`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AtomToken, TransactionUpdate, ƒn } from "atom.io"
|
|
1
|
+
import type { AtomToken, TransactionToken, TransactionUpdate, ƒn } from "atom.io"
|
|
2
2
|
import type { TimelineUpdate } from "atom.io"
|
|
3
3
|
|
|
4
4
|
import { newest } from "../lineage"
|
|
@@ -17,16 +17,11 @@ export const addAtomToTimeline = (
|
|
|
17
17
|
store: Store,
|
|
18
18
|
): void => {
|
|
19
19
|
let maybeAtom = withdraw(atomToken, store)
|
|
20
|
-
if (maybeAtom
|
|
20
|
+
if (maybeAtom.type === `mutable_atom`) {
|
|
21
21
|
const updateToken = getUpdateToken(maybeAtom)
|
|
22
22
|
maybeAtom = withdraw(updateToken, store)
|
|
23
23
|
}
|
|
24
24
|
const atom = maybeAtom
|
|
25
|
-
if (atom === undefined) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`,
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
25
|
store.timelineAtoms.set({ atomKey: atom.key, timelineKey: tl.key })
|
|
31
26
|
|
|
32
27
|
atom.subject.subscribe(`timeline`, (update) => {
|
|
@@ -70,15 +65,11 @@ export const addAtomToTimeline = (
|
|
|
70
65
|
}
|
|
71
66
|
}
|
|
72
67
|
if (currentTransactionKey) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
77
|
-
if (currentTransaction === undefined) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`,
|
|
80
|
-
)
|
|
68
|
+
const txToken: TransactionToken<any> = {
|
|
69
|
+
key: currentTransactionKey,
|
|
70
|
+
type: `transaction`,
|
|
81
71
|
}
|
|
72
|
+
const currentTransaction = withdraw(txToken, store)
|
|
82
73
|
if (tl.transactionKey !== currentTransactionKey) {
|
|
83
74
|
if (tl.transactionKey) {
|
|
84
75
|
store.logger.error(
|
|
@@ -89,15 +89,6 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
89
89
|
) {
|
|
90
90
|
const familyToken: AtomFamilyToken<any> = tokenOrFamily
|
|
91
91
|
const family = withdraw(familyToken, store)
|
|
92
|
-
if (family === undefined) {
|
|
93
|
-
store.logger.error(
|
|
94
|
-
`❌`,
|
|
95
|
-
`timeline`,
|
|
96
|
-
options.key,
|
|
97
|
-
`Failed to add family "${familyToken.key}" because it does not exist in the store`,
|
|
98
|
-
)
|
|
99
|
-
continue
|
|
100
|
-
}
|
|
101
92
|
const familyKey = family.key
|
|
102
93
|
target.timelineAtoms.set({ atomKey: familyKey, timelineKey })
|
|
103
94
|
family.subject.subscribe(`timeline:${options.key}`, (token) => {
|
|
@@ -110,26 +101,8 @@ export function createTimeline<ManagedAtom extends TimelineManageable>(
|
|
|
110
101
|
}
|
|
111
102
|
} else {
|
|
112
103
|
let atom = withdraw(tokenOrFamily, store)
|
|
113
|
-
if (atom === undefined) {
|
|
114
|
-
store.logger.error(
|
|
115
|
-
`❌`,
|
|
116
|
-
`timeline`,
|
|
117
|
-
options.key,
|
|
118
|
-
`Failed to add atom "${atomKey}" because it does not exist in the store`,
|
|
119
|
-
)
|
|
120
|
-
continue
|
|
121
|
-
}
|
|
122
104
|
if (isMutable(atom)) {
|
|
123
105
|
const updateAtom = withdraw(getUpdateToken(atom), store)
|
|
124
|
-
if (updateAtom === undefined) {
|
|
125
|
-
store.logger.error(
|
|
126
|
-
`❌`,
|
|
127
|
-
`timeline`,
|
|
128
|
-
options.key,
|
|
129
|
-
`Failed to add update atom "${atomKey}" because it does not exist in the store`,
|
|
130
|
-
)
|
|
131
|
-
continue
|
|
132
|
-
}
|
|
133
106
|
atom = updateAtom
|
|
134
107
|
atomKey = atom.key
|
|
135
108
|
}
|
|
@@ -60,7 +60,6 @@ export const applyTransaction = <ƒ extends ƒn>(
|
|
|
60
60
|
}
|
|
61
61
|
ingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent)
|
|
62
62
|
if (isRootStore(parent)) {
|
|
63
|
-
console.log(child.transactionMeta.update)
|
|
64
63
|
setEpochNumberOfAction(
|
|
65
64
|
child.transactionMeta.update.key,
|
|
66
65
|
child.transactionMeta.update.epoch,
|
package/json/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from "anvl/json"
|
|
2
|
-
export * from "anvl/primitive"
|
|
1
|
+
export * from "~/packages/anvl/src/json"
|
|
2
|
+
export * from "~/packages/anvl/src/primitive"
|
|
3
3
|
|
|
4
4
|
export * from "./select-json"
|
|
5
5
|
export * from "./select-json-family"
|
|
6
6
|
|
|
7
|
-
import type { Json } from "anvl/json"
|
|
7
|
+
import type { Json } from "~/packages/anvl/src/json"
|
|
8
8
|
|
|
9
9
|
export type JsonIO = (...params: Json.Serializable[]) => Json.Serializable | void
|