atom.io 0.31.1 → 0.32.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.d.ts +867 -101
- package/data/dist/index.js +10 -558
- package/data/src/index.ts +0 -2
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +1 -2
- package/dist/chunk-354XQWHH.js +153 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-5F2V7S3B.js +83 -0
- package/dist/chunk-ECOMOMUN.js +631 -0
- package/dist/{chunk-Y5MBNTVU.js → chunk-GY2XQYZY.js} +1791 -703
- package/dist/chunk-NF7FJKJD.js +107 -0
- package/dist/chunk-R3ZUK5EH.js +1024 -0
- package/dist/chunk-Z2UJW4NQ.js +523 -0
- package/dist/index.d.ts +622 -26
- package/dist/index.js +1 -228
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +0 -146
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/internal/dist/index.d.ts +783 -64
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/dispose-atom.ts +4 -13
- package/internal/src/atom/is-default.ts +3 -3
- package/internal/src/caching.ts +5 -5
- package/internal/src/capitalize.ts +3 -0
- package/internal/src/families/create-readonly-selector-family.ts +5 -6
- package/internal/src/families/create-writable-selector-family.ts +1 -4
- package/internal/src/families/dispose-from-store.ts +3 -13
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +2 -0
- package/internal/src/install-into-store.ts +1 -1
- package/internal/src/join/edit-relations-in-store.ts +32 -0
- package/internal/src/join/find-relations-in-store.ts +124 -0
- package/internal/src/join/get-internal-relations-from-store.ts +14 -0
- package/internal/src/join/get-join.ts +31 -0
- package/internal/src/join/index.ts +5 -0
- package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
- package/internal/src/keys.ts +7 -7
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +1 -1
- package/internal/src/mutable/tracker-family.ts +19 -17
- package/internal/src/mutable/tracker.ts +8 -8
- package/internal/src/pretty-print.ts +1 -1
- package/internal/src/selector/create-readonly-selector.ts +3 -7
- package/internal/src/selector/create-writable-selector.ts +4 -4
- package/internal/src/selector/dispose-selector.ts +20 -11
- package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
- package/internal/src/selector/register-selector.ts +6 -9
- package/internal/src/selector/trace-selector-atoms.ts +2 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +10 -10
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +22 -22
- package/internal/src/subscribe/recall-state.ts +1 -1
- package/internal/src/subscribe/subscribe-in-store.ts +3 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -5
- package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
- package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
- package/internal/src/timeline/create-timeline.ts +17 -37
- package/internal/src/transaction/act-upon-store.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +5 -5
- package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -8
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/get-epoch-number.ts +3 -3
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.d.ts +922 -6
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +899 -5
- package/json/dist/index.js +1 -80
- package/json/src/select-json-family.ts +3 -14
- package/package.json +24 -42
- package/react/dist/index.d.ts +921 -3
- package/react/dist/index.js +2 -82
- package/react/src/use-o.ts +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.css +16 -14
- package/react-devtools/dist/index.d.ts +26 -1
- package/react-devtools/dist/index.js +6 -6
- package/react-devtools/src/devtools.scss +16 -14
- package/realtime/dist/index.d.ts +202 -8
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +2 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +960 -22
- package/realtime-client/dist/index.js +3 -509
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
- package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-atom.ts +2 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-mutable-atom.ts +2 -2
- package/realtime-client/src/pull-selector-family-member.ts +4 -4
- package/realtime-client/src/pull-selector.ts +4 -4
- package/realtime-client/src/push-state.ts +5 -10
- package/realtime-client/src/server-action.ts +4 -4
- package/realtime-client/src/sync-continuity.ts +6 -6
- package/realtime-react/dist/index.d.ts +166 -12
- package/realtime-react/dist/index.js +5 -154
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector.ts +1 -1
- package/realtime-react/src/use-push.ts +1 -1
- package/realtime-react/src/use-server-action.ts +2 -2
- package/realtime-react/src/use-sync-continuity.ts +1 -1
- package/realtime-server/dist/index.d.ts +971 -28
- package/realtime-server/dist/index.js +3 -1001
- package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
- package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
- package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
- package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.d.ts +1091 -3
- package/realtime-testing/dist/index.js +20 -22
- package/realtime-testing/src/setup-realtime-test.tsx +2 -1
- package/src/index.ts +4 -0
- package/src/join.ts +218 -0
- package/src/silo.ts +4 -4
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +37 -2
- package/transceivers/set-rtx/dist/index.js +1 -215
- package/web/dist/index.d.ts +30 -1
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/ephemeral/dist/index.d.ts +0 -67
- package/ephemeral/dist/index.js +0 -9
- package/ephemeral/package.json +0 -13
- package/ephemeral/src/index.ts +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -203
- package/immortal/dist/index.d.ts +0 -12
- package/immortal/dist/index.js +0 -9
- package/immortal/package.json +0 -13
- package/immortal/src/index.ts +0 -1
- package/immortal/src/seek-state.ts +0 -60
- /package/{ephemeral/src → src}/find-state.ts +0 -0
|
@@ -19,14 +19,10 @@ export const createReadonlySelector = <T>(
|
|
|
19
19
|
const target = newest(store)
|
|
20
20
|
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
21
21
|
const covered = new Set<string>()
|
|
22
|
-
const { get, find,
|
|
23
|
-
options.key,
|
|
24
|
-
covered,
|
|
25
|
-
target,
|
|
26
|
-
)
|
|
22
|
+
const { get, find, json } = registerSelector(options.key, covered, target)
|
|
27
23
|
const getSelf = () => {
|
|
28
|
-
const value = options.get({ get, find,
|
|
29
|
-
cacheValue(options.key, value, subject
|
|
24
|
+
const value = options.get({ get, find, json })
|
|
25
|
+
cacheValue(newest(store), options.key, value, subject)
|
|
30
26
|
covered.clear()
|
|
31
27
|
return value
|
|
32
28
|
}
|
|
@@ -23,12 +23,12 @@ export const createWritableSelector = <T>(
|
|
|
23
23
|
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
24
24
|
const covered = new Set<string>()
|
|
25
25
|
const setterToolkit = registerSelector(options.key, covered, target)
|
|
26
|
-
const { find, get,
|
|
27
|
-
const getterToolkit = { find, get,
|
|
26
|
+
const { find, get, json } = setterToolkit
|
|
27
|
+
const getterToolkit = { find, get, json }
|
|
28
28
|
|
|
29
29
|
const getSelf = (getFn = options.get, innerTarget = newest(store)): T => {
|
|
30
30
|
const value = getFn(getterToolkit)
|
|
31
|
-
cacheValue(options.key, value, subject
|
|
31
|
+
cacheValue(innerTarget, options.key, value, subject)
|
|
32
32
|
covered.clear()
|
|
33
33
|
return value
|
|
34
34
|
}
|
|
@@ -47,7 +47,7 @@ export const createWritableSelector = <T>(
|
|
|
47
47
|
newValue,
|
|
48
48
|
`)`,
|
|
49
49
|
)
|
|
50
|
-
cacheValue(options.key, newValue, subject
|
|
50
|
+
cacheValue(innerTarget, options.key, newValue, subject)
|
|
51
51
|
markDone(innerTarget, options.key)
|
|
52
52
|
if (isRootStore(innerTarget)) {
|
|
53
53
|
subject.next({ newValue, oldValue })
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SelectorFamilyToken, SelectorToken } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Store } from ".."
|
|
4
4
|
import { isChildStore, newest, withdraw } from ".."
|
|
5
5
|
|
|
6
6
|
export function disposeSelector(
|
|
7
|
-
selectorToken: ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>,
|
|
8
7
|
store: Store,
|
|
8
|
+
selectorToken: SelectorToken<unknown>,
|
|
9
9
|
): void {
|
|
10
10
|
const target = newest(store)
|
|
11
11
|
const { key } = selectorToken
|
|
12
|
-
const selector = withdraw(
|
|
12
|
+
const selector = withdraw(target, selectorToken)
|
|
13
13
|
if (!selector.family) {
|
|
14
14
|
store.logger.error(
|
|
15
15
|
`❌`,
|
|
@@ -22,23 +22,31 @@ export function disposeSelector(
|
|
|
22
22
|
if (molecule) {
|
|
23
23
|
target.moleculeData.delete(selector.family.subKey, selector.family.key)
|
|
24
24
|
}
|
|
25
|
+
let familyToken: SelectorFamilyToken<any, any>
|
|
25
26
|
switch (selectorToken.type) {
|
|
26
27
|
case `selector`:
|
|
27
28
|
{
|
|
28
29
|
target.selectors.delete(key)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
familyToken = {
|
|
31
|
+
key: selector.family.key,
|
|
32
|
+
type: `selector_family`,
|
|
33
|
+
}
|
|
34
|
+
const family = withdraw(store, familyToken)
|
|
35
|
+
family.subject.next({
|
|
36
|
+
type: `state_disposal`,
|
|
37
|
+
subType: `selector`,
|
|
38
|
+
token: selectorToken,
|
|
39
|
+
})
|
|
33
40
|
}
|
|
34
41
|
break
|
|
35
42
|
case `readonly_selector`:
|
|
36
43
|
{
|
|
37
44
|
target.readonlySelectors.delete(key)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
familyToken = {
|
|
46
|
+
key: selector.family.key,
|
|
47
|
+
type: `readonly_selector_family`,
|
|
48
|
+
}
|
|
49
|
+
const family = withdraw(store, familyToken)
|
|
42
50
|
family.subject.next({
|
|
43
51
|
type: `state_disposal`,
|
|
44
52
|
subType: `selector`,
|
|
@@ -47,6 +55,7 @@ export function disposeSelector(
|
|
|
47
55
|
}
|
|
48
56
|
break
|
|
49
57
|
}
|
|
58
|
+
|
|
50
59
|
target.valueMap.delete(key)
|
|
51
60
|
target.selectorAtoms.delete(key)
|
|
52
61
|
target.selectorGraph.delete(key)
|
|
@@ -15,6 +15,6 @@ export const getSelectorDependencyKeys = (
|
|
|
15
15
|
.selectorGraph.getRelationEntries({ downstreamSelectorKey: key })
|
|
16
16
|
.filter(([_, { source }]) => source !== key)
|
|
17
17
|
.map(([_, { source }]) => source)
|
|
18
|
-
.filter((source) => isStateKey(
|
|
18
|
+
.filter((source) => isStateKey(store, source))
|
|
19
19
|
return sources
|
|
20
20
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
findState,
|
|
2
3
|
ReadableFamilyToken,
|
|
3
4
|
ReadableToken,
|
|
4
5
|
setState,
|
|
@@ -6,15 +7,12 @@ import type {
|
|
|
6
7
|
WritableFamilyToken,
|
|
7
8
|
WritableToken,
|
|
8
9
|
} from "atom.io"
|
|
9
|
-
import type { findState } from "atom.io/ephemeral"
|
|
10
|
-
import type { seekState } from "atom.io/immortal"
|
|
11
10
|
import type { Json } from "atom.io/json"
|
|
12
11
|
|
|
13
|
-
import { findInStore
|
|
12
|
+
import { findInStore } from "../families"
|
|
14
13
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
15
14
|
import { newest } from "../lineage"
|
|
16
15
|
import { getJsonToken } from "../mutable"
|
|
17
|
-
import { NotFoundError } from "../not-found-error"
|
|
18
16
|
import { setAtomOrSelector } from "../set-state"
|
|
19
17
|
import type { Store } from "../store"
|
|
20
18
|
import { withdraw } from "../store"
|
|
@@ -40,8 +38,8 @@ export const registerSelector = (
|
|
|
40
38
|
;[dependency] = params
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
const dependencyState = withdraw(
|
|
44
|
-
const dependencyValue = readOrComputeValue(
|
|
41
|
+
const dependencyState = withdraw(store, dependency)
|
|
42
|
+
const dependencyValue = readOrComputeValue(store, dependencyState)
|
|
45
43
|
|
|
46
44
|
store.logger.info(
|
|
47
45
|
`🔌`,
|
|
@@ -85,10 +83,9 @@ export const registerSelector = (
|
|
|
85
83
|
token = findInStore(store, family, key)
|
|
86
84
|
}
|
|
87
85
|
const target = newest(store)
|
|
88
|
-
const state = withdraw(
|
|
89
|
-
setAtomOrSelector(state, value
|
|
86
|
+
const state = withdraw(target, token)
|
|
87
|
+
setAtomOrSelector(target, state, value)
|
|
90
88
|
}) as typeof setState,
|
|
91
89
|
find: ((token, key) => findInStore(store, token, key)) as typeof findState,
|
|
92
|
-
seek: ((token, key) => seekInStore(store, token, key)) as typeof seekState,
|
|
93
90
|
json: (token) => getJsonToken(store, token),
|
|
94
91
|
})
|
|
@@ -22,7 +22,7 @@ export const traceSelectorAtoms = (
|
|
|
22
22
|
}
|
|
23
23
|
covered.add(indirectDependencyKey)
|
|
24
24
|
|
|
25
|
-
if (!isAtomKey(
|
|
25
|
+
if (!isAtomKey(store, indirectDependencyKey)) {
|
|
26
26
|
indirectDependencyKeys.push(
|
|
27
27
|
...getSelectorDependencyKeys(indirectDependencyKey, store),
|
|
28
28
|
)
|
|
@@ -42,7 +42,7 @@ export const traceAllSelectorAtoms = (
|
|
|
42
42
|
const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store)
|
|
43
43
|
const covered = new Set<string>()
|
|
44
44
|
return directDependencyKeys.flatMap((depKey) =>
|
|
45
|
-
isAtomKey(
|
|
45
|
+
isAtomKey(store, depKey)
|
|
46
46
|
? depKey
|
|
47
47
|
: traceSelectorAtoms(depKey, covered, store),
|
|
48
48
|
)
|
|
@@ -3,9 +3,9 @@ import { Tracker } from "../mutable"
|
|
|
3
3
|
import type { Store } from "../store"
|
|
4
4
|
|
|
5
5
|
export function copyMutableIfNeeded<T extends Transceiver<any>>(
|
|
6
|
+
target: Store,
|
|
6
7
|
atom: MutableAtom<T, any>,
|
|
7
8
|
origin: Store,
|
|
8
|
-
target: Store,
|
|
9
9
|
): T {
|
|
10
10
|
const originValue = origin.valueMap.get(atom.key)
|
|
11
11
|
const targetValue = target.valueMap.get(atom.key)
|
|
@@ -3,9 +3,9 @@ import type { StateUpdate } from "atom.io"
|
|
|
3
3
|
import type { Atom, Selector, Store } from ".."
|
|
4
4
|
|
|
5
5
|
export const emitUpdate = <T>(
|
|
6
|
+
store: Store,
|
|
6
7
|
state: Atom<T> | Selector<T>,
|
|
7
8
|
update: StateUpdate<T>,
|
|
8
|
-
store: Store,
|
|
9
9
|
): void => {
|
|
10
10
|
switch (state.type) {
|
|
11
11
|
case `mutable_atom`:
|
|
@@ -4,7 +4,7 @@ import { newest } from "../lineage"
|
|
|
4
4
|
import { isDone, markDone } from "../operation"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
|
|
7
|
-
export const evictDownStream = <T>(atom: Atom<T
|
|
7
|
+
export const evictDownStream = <T>(store: Store, atom: Atom<T>): void => {
|
|
8
8
|
const target = newest(store)
|
|
9
9
|
const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key)
|
|
10
10
|
target.logger.info(
|
|
@@ -3,9 +3,9 @@ import type { Store } from "../store"
|
|
|
3
3
|
import { setAtom } from "./set-atom"
|
|
4
4
|
|
|
5
5
|
export const setAtomOrSelector = <T>(
|
|
6
|
+
store: Store,
|
|
6
7
|
state: WritableState<T>,
|
|
7
8
|
value: T | ((oldValue: T) => T),
|
|
8
|
-
store: Store,
|
|
9
9
|
): void => {
|
|
10
10
|
switch (state.type) {
|
|
11
11
|
case `atom`:
|
|
@@ -17,38 +17,38 @@ export const setAtom = <T>(
|
|
|
17
17
|
next: T | ((oldValue: T) => T),
|
|
18
18
|
target: Store,
|
|
19
19
|
): void => {
|
|
20
|
-
const oldValue = readOrComputeValue(
|
|
20
|
+
const oldValue = readOrComputeValue(target, atom)
|
|
21
21
|
let newValue = oldValue
|
|
22
22
|
if (atom.type === `mutable_atom` && isChildStore(target)) {
|
|
23
23
|
const { parent } = target
|
|
24
|
-
const copiedValue = copyMutableIfNeeded(atom, parent
|
|
24
|
+
const copiedValue = copyMutableIfNeeded(target, atom, parent)
|
|
25
25
|
newValue = copiedValue
|
|
26
26
|
}
|
|
27
27
|
newValue = become(next)(newValue)
|
|
28
28
|
target.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)
|
|
29
|
-
newValue = cacheValue(atom.key, newValue, atom.subject
|
|
30
|
-
if (isAtomDefault(atom.key
|
|
31
|
-
markAtomAsNotDefault(atom.key
|
|
29
|
+
newValue = cacheValue(target, atom.key, newValue, atom.subject)
|
|
30
|
+
if (isAtomDefault(target, atom.key)) {
|
|
31
|
+
markAtomAsNotDefault(target, atom.key)
|
|
32
32
|
}
|
|
33
33
|
markDone(target, atom.key)
|
|
34
|
-
evictDownStream(
|
|
34
|
+
evictDownStream(target, atom)
|
|
35
35
|
const update = { oldValue, newValue }
|
|
36
36
|
if (isRootStore(target)) {
|
|
37
|
-
emitUpdate(atom, update
|
|
37
|
+
emitUpdate(target, atom, update)
|
|
38
38
|
} else if (target.parent) {
|
|
39
39
|
if (target.on.transactionApplying.state === null) {
|
|
40
|
-
stowUpdate(atom, update
|
|
40
|
+
stowUpdate(target, atom, update)
|
|
41
41
|
} else if (atom.key.startsWith(`*`)) {
|
|
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
45
|
if (mutableAtom.type === `mutable_atom` && isChildStore(target)) {
|
|
46
46
|
const { parent } = target
|
|
47
|
-
const copiedValue = copyMutableIfNeeded(mutableAtom, parent
|
|
47
|
+
const copiedValue = copyMutableIfNeeded(target, mutableAtom, parent)
|
|
48
48
|
transceiver = copiedValue
|
|
49
49
|
}
|
|
50
50
|
const accepted = transceiver.do(update.newValue) === null
|
|
51
|
-
if (accepted) evictDownStream(
|
|
51
|
+
if (accepted) evictDownStream(target, mutableAtom)
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -84,7 +84,7 @@ export function setIntoStore<T, New extends T>(
|
|
|
84
84
|
)
|
|
85
85
|
return
|
|
86
86
|
}
|
|
87
|
-
const state = withdraw(
|
|
88
|
-
setAtomOrSelector(state, value
|
|
87
|
+
const state = withdraw(store, token)
|
|
88
|
+
setAtomOrSelector(store, state, value)
|
|
89
89
|
closeOperation(store)
|
|
90
90
|
}
|
|
@@ -19,9 +19,9 @@ function shouldUpdateBeStowed(key: string, update: StateUpdate<any>): boolean {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const stowUpdate = <T>(
|
|
22
|
+
store: Store,
|
|
22
23
|
state: Atom<T>,
|
|
23
24
|
update: StateUpdate<T>,
|
|
24
|
-
store: Store,
|
|
25
25
|
): void => {
|
|
26
26
|
const { key } = state
|
|
27
27
|
const target = newest(store)
|
|
@@ -9,7 +9,6 @@ import type {
|
|
|
9
9
|
WritableSelectorToken,
|
|
10
10
|
} from "atom.io"
|
|
11
11
|
import { AtomIOLogger } from "atom.io"
|
|
12
|
-
import type { Join } from "atom.io/data"
|
|
13
12
|
import type { Canonical, stringified } from "atom.io/json"
|
|
14
13
|
|
|
15
14
|
import type {
|
|
@@ -21,6 +20,7 @@ import type {
|
|
|
21
20
|
WritableSelector,
|
|
22
21
|
WritableSelectorFamily,
|
|
23
22
|
} from ".."
|
|
23
|
+
import type { Join } from "../join"
|
|
24
24
|
import { Junction } from "../junction"
|
|
25
25
|
import type { Lineage } from "../lineage"
|
|
26
26
|
import type { Molecule } from "../molecule"
|
|
@@ -49,95 +49,95 @@ import type { Transaction } from "../transaction"
|
|
|
49
49
|
import type { Store } from "./store"
|
|
50
50
|
|
|
51
51
|
export function withdraw<T>(
|
|
52
|
-
token: RegularAtomToken<T>,
|
|
53
52
|
store: Store,
|
|
53
|
+
token: RegularAtomToken<T>,
|
|
54
54
|
): RegularAtom<T>
|
|
55
55
|
export function withdraw<T extends Transceiver<any>>(
|
|
56
|
-
token: MutableAtomToken<T, any>,
|
|
57
56
|
store: Store,
|
|
57
|
+
token: MutableAtomToken<T, any>,
|
|
58
58
|
): MutableAtom<T, any>
|
|
59
|
-
export function withdraw<T>(token: AtomToken<T
|
|
59
|
+
export function withdraw<T>(store: Store, token: AtomToken<T>): Atom<T>
|
|
60
60
|
export function withdraw<T>(
|
|
61
|
-
token: WritableSelectorToken<T>,
|
|
62
61
|
store: Store,
|
|
62
|
+
token: WritableSelectorToken<T>,
|
|
63
63
|
): WritableSelector<T>
|
|
64
64
|
export function withdraw<T>(
|
|
65
|
-
token: ReadonlySelectorToken<T>,
|
|
66
65
|
store: Store,
|
|
66
|
+
token: ReadonlySelectorToken<T>,
|
|
67
67
|
): ReadonlySelector<T>
|
|
68
|
-
export function withdraw<T>(token: SelectorToken<T
|
|
68
|
+
export function withdraw<T>(store: Store, token: SelectorToken<T>): Selector<T>
|
|
69
69
|
export function withdraw<T>(
|
|
70
|
-
token: WritableToken<T>,
|
|
71
70
|
store: Store,
|
|
71
|
+
token: WritableToken<T>,
|
|
72
72
|
): WritableState<T>
|
|
73
73
|
export function withdraw<T>(
|
|
74
|
-
token: ReadableToken<T>,
|
|
75
74
|
store: Store,
|
|
75
|
+
token: ReadableToken<T>,
|
|
76
76
|
): ReadableState<T>
|
|
77
77
|
|
|
78
78
|
export function withdraw<T, K extends Canonical>(
|
|
79
|
-
token: RegularAtomFamilyToken<T, K>,
|
|
80
79
|
store: Store,
|
|
80
|
+
token: RegularAtomFamilyToken<T, K>,
|
|
81
81
|
): RegularAtomFamily<T, K>
|
|
82
82
|
export function withdraw<
|
|
83
83
|
T extends Transceiver<any>,
|
|
84
84
|
J extends Json.Serializable,
|
|
85
85
|
K extends Canonical,
|
|
86
86
|
>(
|
|
87
|
-
token: MutableAtomFamilyToken<T, J, K>,
|
|
88
87
|
store: Store,
|
|
88
|
+
token: MutableAtomFamilyToken<T, J, K>,
|
|
89
89
|
): MutableAtomFamily<T, J, K>
|
|
90
90
|
export function withdraw<T, K extends Canonical>(
|
|
91
|
-
token: AtomFamilyToken<T>,
|
|
92
91
|
store: Store,
|
|
92
|
+
token: AtomFamilyToken<T>,
|
|
93
93
|
): AtomFamily<T, any>
|
|
94
94
|
export function withdraw<T, K extends Canonical>(
|
|
95
|
-
token: ReadonlySelectorFamilyToken<T, K>,
|
|
96
95
|
store: Store,
|
|
96
|
+
token: ReadonlySelectorFamilyToken<T, K>,
|
|
97
97
|
): ReadonlySelectorFamily<T, any>
|
|
98
98
|
export function withdraw<T, K extends Canonical>(
|
|
99
|
-
token: WritableSelectorFamilyToken<T, K>,
|
|
100
99
|
store: Store,
|
|
100
|
+
token: WritableSelectorFamilyToken<T, K>,
|
|
101
101
|
): WritableSelectorFamily<T, any>
|
|
102
102
|
export function withdraw<T, K extends Canonical>(
|
|
103
|
-
token: SelectorFamilyToken<T, K>,
|
|
104
103
|
store: Store,
|
|
104
|
+
token: SelectorFamilyToken<T, K>,
|
|
105
105
|
): SelectorFamily<T, any>
|
|
106
106
|
export function withdraw<T, K extends Canonical>(
|
|
107
|
-
token: ReadableFamilyToken<T, K>,
|
|
108
107
|
store: Store,
|
|
108
|
+
token: ReadableFamilyToken<T, K>,
|
|
109
109
|
): ReadableFamily<T, any>
|
|
110
110
|
export function withdraw<T, K extends Canonical>(
|
|
111
|
-
token: WritableFamilyToken<T, K>,
|
|
112
111
|
store: Store,
|
|
112
|
+
token: WritableFamilyToken<T, K>,
|
|
113
113
|
): WritableFamily<T, any>
|
|
114
114
|
|
|
115
115
|
export function withdraw<T extends Func>(
|
|
116
|
-
token: TransactionToken<T>,
|
|
117
116
|
store: Store,
|
|
117
|
+
token: TransactionToken<T>,
|
|
118
118
|
): Transaction<T extends Func ? T : never>
|
|
119
119
|
export function withdraw<T>(
|
|
120
|
-
token: TimelineToken<T>,
|
|
121
120
|
store: Store,
|
|
121
|
+
token: TimelineToken<T>,
|
|
122
122
|
): Timeline<T extends TimelineManageable ? T : never>
|
|
123
123
|
|
|
124
124
|
export function withdraw<T>(
|
|
125
|
-
token: WritableToken<T>,
|
|
126
125
|
store: Store,
|
|
126
|
+
token: WritableToken<T>,
|
|
127
127
|
): WritableState<T>
|
|
128
128
|
export function withdraw<T>(
|
|
129
|
-
token: ReadableToken<T>,
|
|
130
129
|
store: Store,
|
|
130
|
+
token: ReadableToken<T>,
|
|
131
131
|
): ReadableState<T>
|
|
132
132
|
|
|
133
133
|
export function withdraw(
|
|
134
|
-
token: AtomIOToken,
|
|
135
134
|
store: Store,
|
|
135
|
+
token: AtomIOToken,
|
|
136
136
|
): AtomIOInternalResource
|
|
137
137
|
|
|
138
138
|
export function withdraw(
|
|
139
|
-
token: AtomIOToken,
|
|
140
139
|
store: Store,
|
|
140
|
+
token: AtomIOToken,
|
|
141
141
|
): AtomIOInternalResource {
|
|
142
142
|
let withdrawn: AtomIOInternalResource | undefined
|
|
143
143
|
let target: Store | null = store
|
|
@@ -2,7 +2,7 @@ import type { ReadableState } from ".."
|
|
|
2
2
|
import { newest } from "../lineage"
|
|
3
3
|
import type { Store } from "../store"
|
|
4
4
|
|
|
5
|
-
export const recallState = <T>(state: ReadableState<T
|
|
5
|
+
export const recallState = <T>(store: Store, state: ReadableState<T>): T => {
|
|
6
6
|
const target = newest(store)
|
|
7
7
|
if (target.operation.open) {
|
|
8
8
|
return target.operation.prev.get(state.key)
|
|
@@ -53,10 +53,10 @@ export function subscribeInStore(
|
|
|
53
53
|
case `mutable_atom`:
|
|
54
54
|
case `readonly_selector`:
|
|
55
55
|
case `selector`:
|
|
56
|
-
return subscribeToState(
|
|
56
|
+
return subscribeToState(store, token, key, handleUpdate)
|
|
57
57
|
case `transaction`:
|
|
58
|
-
return subscribeToTransaction(
|
|
58
|
+
return subscribeToTransaction(store, token, key, handleUpdate)
|
|
59
59
|
case `timeline`:
|
|
60
|
-
return subscribeToTimeline(
|
|
60
|
+
return subscribeToTimeline(store, token, key, handleUpdate)
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -6,8 +6,8 @@ import type { Store } from "../store"
|
|
|
6
6
|
import { recallState } from "./recall-state"
|
|
7
7
|
|
|
8
8
|
export const subscribeToRootAtoms = <T>(
|
|
9
|
-
selector: Selector<T>,
|
|
10
9
|
store: Store,
|
|
10
|
+
selector: Selector<T>,
|
|
11
11
|
): (() => void)[] => {
|
|
12
12
|
const target = newest(store)
|
|
13
13
|
const dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(
|
|
@@ -32,8 +32,8 @@ export const subscribeToRootAtoms = <T>(
|
|
|
32
32
|
`->`,
|
|
33
33
|
atomChange.newValue,
|
|
34
34
|
)
|
|
35
|
-
const oldValue = recallState(
|
|
36
|
-
const newValue = readOrComputeValue(
|
|
35
|
+
const oldValue = recallState(target, selector)
|
|
36
|
+
const newValue = readOrComputeValue(target, selector)
|
|
37
37
|
store.logger.info(
|
|
38
38
|
`✨`,
|
|
39
39
|
selector.type,
|
|
@@ -5,10 +5,10 @@ import { withdraw } from "../store"
|
|
|
5
5
|
import { subscribeToRootAtoms } from "./subscribe-to-root-atoms"
|
|
6
6
|
|
|
7
7
|
export function subscribeToState<T>(
|
|
8
|
+
store: Store,
|
|
8
9
|
token: ReadableToken<T>,
|
|
9
|
-
handleUpdate: UpdateHandler<T>,
|
|
10
10
|
key: string,
|
|
11
|
-
|
|
11
|
+
handleUpdate: UpdateHandler<T>,
|
|
12
12
|
): () => void {
|
|
13
13
|
function safelyHandleUpdate(update: StateUpdate<any>): void {
|
|
14
14
|
if (store.operation.open) {
|
|
@@ -23,18 +23,18 @@ export function subscribeToState<T>(
|
|
|
23
23
|
handleUpdate(update)
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
const state = withdraw(
|
|
26
|
+
const state = withdraw(store, token)
|
|
27
27
|
store.logger.info(`👀`, state.type, state.key, `Adding subscription "${key}"`)
|
|
28
28
|
const isSelector =
|
|
29
29
|
state.type === `selector` || state.type === `readonly_selector`
|
|
30
30
|
let dependencyUnsubFunctions: (() => void)[] | null = null
|
|
31
31
|
let updateHandler: UpdateHandler<T> = safelyHandleUpdate
|
|
32
32
|
if (isSelector) {
|
|
33
|
-
dependencyUnsubFunctions = subscribeToRootAtoms(
|
|
33
|
+
dependencyUnsubFunctions = subscribeToRootAtoms(store, state)
|
|
34
34
|
updateHandler = (update) => {
|
|
35
35
|
if (dependencyUnsubFunctions) {
|
|
36
36
|
dependencyUnsubFunctions.length = 0
|
|
37
|
-
dependencyUnsubFunctions.push(...subscribeToRootAtoms(
|
|
37
|
+
dependencyUnsubFunctions.push(...subscribeToRootAtoms(store, state))
|
|
38
38
|
}
|
|
39
39
|
safelyHandleUpdate(update)
|
|
40
40
|
}
|
|
@@ -4,12 +4,12 @@ import type { Store } from ".."
|
|
|
4
4
|
import { withdraw } from ".."
|
|
5
5
|
|
|
6
6
|
export const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(
|
|
7
|
+
store: Store,
|
|
7
8
|
token: TimelineToken<ManagedAtom>,
|
|
8
|
-
handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,
|
|
9
9
|
key: string,
|
|
10
|
-
|
|
10
|
+
handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void,
|
|
11
11
|
): (() => void) => {
|
|
12
|
-
const tl = withdraw(
|
|
12
|
+
const tl = withdraw(store, token)
|
|
13
13
|
store.logger.info(`👀`, `timeline`, token.key, `Adding subscription "${key}"`)
|
|
14
14
|
const unsubscribe = tl.subject.subscribe(key, handleUpdate)
|
|
15
15
|
return () => {
|
|
@@ -4,12 +4,12 @@ import type { Func, Store } from ".."
|
|
|
4
4
|
import { withdraw } from ".."
|
|
5
5
|
|
|
6
6
|
export const subscribeToTransaction = <F extends Func>(
|
|
7
|
+
store: Store,
|
|
7
8
|
token: TransactionToken<F>,
|
|
8
|
-
handleUpdate: TransactionUpdateHandler<F>,
|
|
9
9
|
key: string,
|
|
10
|
-
|
|
10
|
+
handleUpdate: TransactionUpdateHandler<F>,
|
|
11
11
|
): (() => void) => {
|
|
12
|
-
const tx = withdraw(
|
|
12
|
+
const tx = withdraw(store, token)
|
|
13
13
|
store.logger.info(
|
|
14
14
|
`👀`,
|
|
15
15
|
`transaction`,
|