atom.io 0.33.13 → 0.33.15
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/data/index.js.map +1 -1
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +9 -7
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +98 -53
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +7 -7
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +26 -38
- package/dist/introspection/index.js.map +1 -1
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +21 -1
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +24 -13
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.css +110 -56
- package/dist/react-devtools/index.css.map +1 -1
- package/dist/react-devtools/index.js +38 -14
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/use-o-BrXc7Qro.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/package.json +10 -10
- package/src/internal/atom/create-regular-atom.ts +0 -2
- package/src/internal/atom/index.ts +0 -1
- package/src/internal/mutable/create-mutable-atom.ts +0 -2
- package/src/internal/selector/trace-selector-atoms.ts +9 -7
- package/src/internal/set-state/index.ts +2 -0
- package/src/internal/set-state/reset-atom-or-selector.ts +32 -0
- package/src/internal/set-state/reset-in-store.ts +78 -0
- package/src/internal/set-state/set-atom.ts +0 -4
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -8
- package/src/internal/transaction/build-transaction.ts +11 -2
- package/src/internal/transaction/create-transaction.ts +9 -5
- package/src/introspection/attach-atom-index.ts +6 -15
- package/src/introspection/attach-introspection-states.ts +5 -5
- package/src/introspection/attach-selector-index.ts +78 -85
- package/src/introspection/attach-timeline-index.ts +5 -12
- package/src/introspection/attach-transaction-index.ts +18 -16
- package/src/introspection/auditor.ts +2 -3
- package/src/main/index.ts +1 -0
- package/src/main/reset-state.ts +35 -0
- package/src/main/silo.ts +6 -0
- package/src/main/transaction.ts +2 -0
- package/src/react-devtools/StateIndex.tsx +44 -20
- package/src/react-devtools/TimelineIndex.tsx +16 -12
- package/src/react-devtools/TransactionIndex.tsx +22 -18
- package/src/react-devtools/devtools.css +110 -56
- package/src/react-devtools/store.ts +1 -1
- package/src/internal/atom/is-default.ts +0 -18
|
@@ -9,7 +9,6 @@ import { selectJson } from "atom.io/json"
|
|
|
9
9
|
|
|
10
10
|
import type { MutableAtom } from ".."
|
|
11
11
|
import { cacheValue, setIntoStore } from ".."
|
|
12
|
-
import { markAtomAsDefault } from "../atom"
|
|
13
12
|
import { newest } from "../lineage"
|
|
14
13
|
import { deposit, type Store } from "../store"
|
|
15
14
|
import { Subject } from "../subject"
|
|
@@ -59,7 +58,6 @@ export function createMutableAtom<
|
|
|
59
58
|
}
|
|
60
59
|
const initialValue = def()
|
|
61
60
|
target.atoms.set(newAtom.key, newAtom)
|
|
62
|
-
markAtomAsDefault(store, key)
|
|
63
61
|
cacheValue(target, key, initialValue, subject)
|
|
64
62
|
const token = deposit(newAtom)
|
|
65
63
|
if (options.effects) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Selector, Store } from ".."
|
|
1
|
+
import type { Atom, Selector, Store } from ".."
|
|
2
2
|
import type { AtomKey, StateKey } from "../keys"
|
|
3
3
|
import { isAtomKey } from "../keys"
|
|
4
4
|
import { getSelectorDependencyKeys } from "./get-selector-dependency-keys"
|
|
@@ -37,13 +37,15 @@ export const traceSelectorAtoms = (
|
|
|
37
37
|
export const traceAllSelectorAtoms = (
|
|
38
38
|
selector: Selector<any>,
|
|
39
39
|
store: Store,
|
|
40
|
-
):
|
|
40
|
+
): Atom<unknown>[] => {
|
|
41
41
|
const selectorKey = selector.key
|
|
42
42
|
const directDependencyKeys = getSelectorDependencyKeys(store, selectorKey)
|
|
43
43
|
const covered = new Set<string>()
|
|
44
|
-
return directDependencyKeys
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
return directDependencyKeys
|
|
45
|
+
.flatMap((depKey) =>
|
|
46
|
+
isAtomKey(store, depKey)
|
|
47
|
+
? depKey
|
|
48
|
+
: traceSelectorAtoms(store, depKey, covered),
|
|
49
|
+
)
|
|
50
|
+
.map((atomKey) => store.atoms.get(atomKey) as Atom<unknown>)
|
|
49
51
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Atom, traceAllSelectorAtoms, type WritableState } from ".."
|
|
2
|
+
import type { Store } from "../store"
|
|
3
|
+
import { setAtom } from "./set-atom"
|
|
4
|
+
|
|
5
|
+
function resetAtom(store: Store, state: Atom<any>) {
|
|
6
|
+
let def = state.default
|
|
7
|
+
if (def instanceof Function) {
|
|
8
|
+
def = def()
|
|
9
|
+
}
|
|
10
|
+
setAtom(store, state, def)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resetAtomOrSelector(
|
|
14
|
+
store: Store,
|
|
15
|
+
state: WritableState<any>,
|
|
16
|
+
): void {
|
|
17
|
+
switch (state.type) {
|
|
18
|
+
case `atom`:
|
|
19
|
+
case `mutable_atom`:
|
|
20
|
+
resetAtom(store, state)
|
|
21
|
+
break
|
|
22
|
+
case `writable_pure_selector`:
|
|
23
|
+
case `writable_held_selector`:
|
|
24
|
+
{
|
|
25
|
+
const atoms = traceAllSelectorAtoms(state, store)
|
|
26
|
+
for (const atom of atoms) {
|
|
27
|
+
resetAtom(store, atom)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
break
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { WritableFamilyToken, WritableToken } from "atom.io"
|
|
2
|
+
import { type Canonical, parseJson } from "atom.io/json"
|
|
3
|
+
|
|
4
|
+
import { findInStore } from "../families"
|
|
5
|
+
import { getFamilyOfToken } from "../families/get-family-of-token"
|
|
6
|
+
import { closeOperation, openOperation } from "../operation"
|
|
7
|
+
import type { Store } from "../store"
|
|
8
|
+
import { withdraw } from "../store"
|
|
9
|
+
import { resetAtomOrSelector } from "./reset-atom-or-selector"
|
|
10
|
+
|
|
11
|
+
export function resetInStore(store: Store, token: WritableToken<any>): void
|
|
12
|
+
|
|
13
|
+
export function resetInStore<K extends Canonical>(
|
|
14
|
+
store: Store,
|
|
15
|
+
token: WritableFamilyToken<any, K>,
|
|
16
|
+
key: K,
|
|
17
|
+
): void
|
|
18
|
+
|
|
19
|
+
export function resetInStore<T>(
|
|
20
|
+
store: Store,
|
|
21
|
+
...params:
|
|
22
|
+
| [token: WritableFamilyToken<T, Canonical>, key: Canonical]
|
|
23
|
+
| [token: WritableToken<T>]
|
|
24
|
+
): void {
|
|
25
|
+
let token: WritableToken<T>
|
|
26
|
+
let family: WritableFamilyToken<T, Canonical> | null
|
|
27
|
+
let key: Canonical | null
|
|
28
|
+
if (params.length === 1) {
|
|
29
|
+
token = params[0]
|
|
30
|
+
family = getFamilyOfToken(store, token) ?? null
|
|
31
|
+
if (family) {
|
|
32
|
+
key = token.family ? parseJson(token.family.subKey) : null
|
|
33
|
+
token = findInStore(store, family, key)
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
family = params[0]
|
|
37
|
+
key = params[1]
|
|
38
|
+
token = findInStore(store, family, key)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (`counterfeit` in token && `family` in token) {
|
|
42
|
+
const subKey = token.family.subKey
|
|
43
|
+
const disposal = store.disposalTraces.buffer.find(
|
|
44
|
+
(item) => item?.key === subKey,
|
|
45
|
+
)
|
|
46
|
+
store.logger.error(
|
|
47
|
+
`❌`,
|
|
48
|
+
token.type,
|
|
49
|
+
token.key,
|
|
50
|
+
`could not be reset because it was not found in the store "${store.config.name}".`,
|
|
51
|
+
disposal
|
|
52
|
+
? `This state was previously disposed:\n${disposal.trace}`
|
|
53
|
+
: `No previous disposal trace was found.`,
|
|
54
|
+
)
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const rejectionTime = openOperation(store, token)
|
|
59
|
+
if (rejectionTime) {
|
|
60
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
61
|
+
`waiting to reset "${token.key}" at T-${rejectionTime}`,
|
|
62
|
+
() => {
|
|
63
|
+
unsubscribe()
|
|
64
|
+
store.logger.info(
|
|
65
|
+
`🟢`,
|
|
66
|
+
token.type,
|
|
67
|
+
token.key,
|
|
68
|
+
`resuming deferred resetState from T-${rejectionTime}`,
|
|
69
|
+
)
|
|
70
|
+
resetInStore(store, token)
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
const state = withdraw(store, token)
|
|
76
|
+
resetAtomOrSelector(store, state)
|
|
77
|
+
closeOperation(store)
|
|
78
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { KeyedStateUpdate } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Atom, Store } from ".."
|
|
4
|
-
import { isAtomDefault, markAtomAsNotDefault } from "../atom"
|
|
5
4
|
import { cacheValue } from "../caching"
|
|
6
5
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
7
6
|
import { isTransceiver, type Transceiver } from "../mutable"
|
|
@@ -27,9 +26,6 @@ export const setAtom = <T>(
|
|
|
27
26
|
newValue = become(next)(newValue)
|
|
28
27
|
target.logger.info(`📝`, `atom`, atom.key, `set to`, newValue)
|
|
29
28
|
newValue = cacheValue(target, atom.key, newValue, atom.subject)
|
|
30
|
-
if (isAtomDefault(target, atom.key)) {
|
|
31
|
-
markAtomAsNotDefault(target, atom.key)
|
|
32
|
-
}
|
|
33
29
|
markDone(target, atom.key)
|
|
34
30
|
evictDownStream(target, atom)
|
|
35
31
|
const update = { oldValue, newValue }
|
|
@@ -11,13 +11,7 @@ export const subscribeToRootAtoms = <T>(
|
|
|
11
11
|
): (() => void)[] => {
|
|
12
12
|
const target = newest(store)
|
|
13
13
|
const dependencySubscriptions = traceAllSelectorAtoms(selector, store).map(
|
|
14
|
-
(
|
|
15
|
-
const atom = target.atoms.get(atomKey)
|
|
16
|
-
if (atom === undefined) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
`Atom "${atomKey}", a dependency of selector "${selector.key}", not found in store "${store.config.name}".`,
|
|
19
|
-
)
|
|
20
|
-
}
|
|
14
|
+
(atom) => {
|
|
21
15
|
return atom.subject.subscribe(
|
|
22
16
|
`${selector.type}:${selector.key}`,
|
|
23
17
|
(atomChange) => {
|
|
@@ -26,7 +20,7 @@ export const subscribeToRootAtoms = <T>(
|
|
|
26
20
|
selector.type,
|
|
27
21
|
selector.key,
|
|
28
22
|
`root`,
|
|
29
|
-
|
|
23
|
+
atom.key,
|
|
30
24
|
`went`,
|
|
31
25
|
atomChange.oldValue,
|
|
32
26
|
`->`,
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
disposeState,
|
|
3
|
+
findState,
|
|
4
|
+
getState,
|
|
5
|
+
resetState,
|
|
6
|
+
setState,
|
|
7
|
+
} from "atom.io"
|
|
2
8
|
|
|
3
9
|
import { arbitrary } from "../arbitrary"
|
|
4
10
|
import { disposeFromStore, findInStore } from "../families"
|
|
@@ -8,7 +14,7 @@ import { Junction } from "../junction"
|
|
|
8
14
|
import { LazyMap } from "../lazy-map"
|
|
9
15
|
import { newest } from "../lineage"
|
|
10
16
|
import { getJsonToken } from "../mutable"
|
|
11
|
-
import { setIntoStore } from "../set-state"
|
|
17
|
+
import { resetInStore, setIntoStore } from "../set-state"
|
|
12
18
|
import type { Store } from "../store"
|
|
13
19
|
import type { Func } from "../utility-types"
|
|
14
20
|
import type { TransactionProgress } from "."
|
|
@@ -77,6 +83,9 @@ export const buildTransaction = (
|
|
|
77
83
|
set: ((...ps: Parameters<typeof setState>) => {
|
|
78
84
|
setIntoStore(child, ...ps)
|
|
79
85
|
}) as typeof setState,
|
|
86
|
+
reset: ((...ps: Parameters<typeof resetState>) => {
|
|
87
|
+
resetInStore(child, ...ps)
|
|
88
|
+
}) as typeof resetState,
|
|
80
89
|
run: (token, identifier = arbitrary()) =>
|
|
81
90
|
actUponStore(child, token, identifier),
|
|
82
91
|
find: ((...ps: Parameters<typeof findState>) =>
|
|
@@ -25,11 +25,13 @@ export function createTransaction<F extends Func>(
|
|
|
25
25
|
store: Store,
|
|
26
26
|
options: TransactionOptions<F>,
|
|
27
27
|
): TransactionToken<F> {
|
|
28
|
+
const { key } = options
|
|
29
|
+
const transactionAlreadyExists = store.transactions.has(key)
|
|
28
30
|
const newTransaction: Transaction<F> = {
|
|
29
|
-
key
|
|
31
|
+
key,
|
|
30
32
|
type: `transaction`,
|
|
31
33
|
run: (params: Parameters<F>, id: string) => {
|
|
32
|
-
const childStore = buildTransaction(store,
|
|
34
|
+
const childStore = buildTransaction(store, key, params, id)
|
|
33
35
|
try {
|
|
34
36
|
const target = newest(store)
|
|
35
37
|
const { toolkit } = childStore.transactionMeta
|
|
@@ -38,7 +40,7 @@ export function createTransaction<F extends Func>(
|
|
|
38
40
|
return output
|
|
39
41
|
} catch (thrown) {
|
|
40
42
|
abortTransaction(target)
|
|
41
|
-
store.logger.warn(`💥`, `transaction`,
|
|
43
|
+
store.logger.warn(`💥`, `transaction`, key, `caught:`, thrown)
|
|
42
44
|
throw thrown
|
|
43
45
|
}
|
|
44
46
|
},
|
|
@@ -46,8 +48,10 @@ export function createTransaction<F extends Func>(
|
|
|
46
48
|
subject: new Subject(),
|
|
47
49
|
}
|
|
48
50
|
const target = newest(store)
|
|
49
|
-
target.transactions.set(
|
|
51
|
+
target.transactions.set(key, newTransaction)
|
|
50
52
|
const token = deposit(newTransaction)
|
|
51
|
-
|
|
53
|
+
if (!transactionAlreadyExists) {
|
|
54
|
+
store.on.transactionCreation.next(token)
|
|
55
|
+
}
|
|
52
56
|
return token
|
|
53
57
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { AtomToken
|
|
1
|
+
import type { AtomToken } from "atom.io"
|
|
2
2
|
import type { Store } from "atom.io/internal"
|
|
3
3
|
import {
|
|
4
4
|
createRegularAtom,
|
|
5
|
-
createStandaloneSelector,
|
|
6
5
|
deposit,
|
|
7
6
|
isReservedIntrospectionKey,
|
|
8
7
|
} from "atom.io/internal"
|
|
@@ -11,13 +10,11 @@ import type { WritableTokenIndex } from "."
|
|
|
11
10
|
|
|
12
11
|
export type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>
|
|
13
12
|
|
|
14
|
-
export const attachAtomIndex = (
|
|
15
|
-
|
|
16
|
-
): ReadonlyPureSelectorToken<AtomTokenIndex> => {
|
|
17
|
-
const atomTokenIndexState__INTERNAL = createRegularAtom<AtomTokenIndex>(
|
|
13
|
+
export const attachAtomIndex = (store: Store): AtomToken<AtomTokenIndex> => {
|
|
14
|
+
return createRegularAtom<AtomTokenIndex>(
|
|
18
15
|
store,
|
|
19
16
|
{
|
|
20
|
-
key: `🔍 Atom Token Index
|
|
17
|
+
key: `🔍 Atom Token Index`,
|
|
21
18
|
default: () => {
|
|
22
19
|
const base: AtomTokenIndex = new Map()
|
|
23
20
|
for (const [key, val] of store.atoms) {
|
|
@@ -66,7 +63,7 @@ export const attachAtomIndex = (
|
|
|
66
63
|
} else {
|
|
67
64
|
self.set(atomToken.key, atomToken)
|
|
68
65
|
}
|
|
69
|
-
return self
|
|
66
|
+
return new Map(self)
|
|
70
67
|
})
|
|
71
68
|
})
|
|
72
69
|
store.on.atomDisposal.subscribe(`introspection`, (atomToken) => {
|
|
@@ -80,10 +77,8 @@ export const attachAtomIndex = (
|
|
|
80
77
|
self.delete(familyKey)
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
|
-
} else {
|
|
84
|
-
self.delete(atomToken.key)
|
|
85
80
|
}
|
|
86
|
-
return self
|
|
81
|
+
return new Map(self)
|
|
87
82
|
})
|
|
88
83
|
})
|
|
89
84
|
},
|
|
@@ -91,8 +86,4 @@ export const attachAtomIndex = (
|
|
|
91
86
|
},
|
|
92
87
|
undefined,
|
|
93
88
|
)
|
|
94
|
-
return createStandaloneSelector(store, {
|
|
95
|
-
key: `🔍 Atom Token Index`,
|
|
96
|
-
get: ({ get }) => get(atomTokenIndexState__INTERNAL),
|
|
97
|
-
})
|
|
98
89
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AtomToken,
|
|
2
3
|
Loadable,
|
|
3
4
|
ReadonlyPureSelectorFamilyToken,
|
|
4
|
-
ReadonlyPureSelectorToken,
|
|
5
5
|
TimelineToken,
|
|
6
6
|
TransactionToken,
|
|
7
7
|
TransactionUpdate,
|
|
@@ -18,14 +18,14 @@ import { attachTransactionLogs } from "./attach-transaction-logs"
|
|
|
18
18
|
import { attachTypeSelectors } from "./attach-type-selectors"
|
|
19
19
|
|
|
20
20
|
export type IntrospectionStates = {
|
|
21
|
-
atomIndex:
|
|
22
|
-
selectorIndex:
|
|
23
|
-
transactionIndex:
|
|
21
|
+
atomIndex: AtomToken<AtomTokenIndex>
|
|
22
|
+
selectorIndex: AtomToken<SelectorTokenIndex>
|
|
23
|
+
transactionIndex: AtomToken<TransactionToken<Func>[]>
|
|
24
24
|
transactionLogSelectors: ReadonlyPureSelectorFamilyToken<
|
|
25
25
|
TransactionUpdate<Func>[],
|
|
26
26
|
string
|
|
27
27
|
>
|
|
28
|
-
timelineIndex:
|
|
28
|
+
timelineIndex: AtomToken<TimelineToken<any>[]>
|
|
29
29
|
timelineSelectors: ReadonlyPureSelectorFamilyToken<Timeline<any>, string>
|
|
30
30
|
typeSelectors: ReadonlyPureSelectorFamilyToken<Loadable<string>, string>
|
|
31
31
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AtomToken, SelectorToken } from "atom.io"
|
|
2
2
|
import type { Store } from "atom.io/internal"
|
|
3
3
|
import {
|
|
4
4
|
createRegularAtom,
|
|
5
|
-
createStandaloneSelector,
|
|
6
5
|
deposit,
|
|
7
6
|
isReservedIntrospectionKey,
|
|
8
7
|
} from "atom.io/internal"
|
|
@@ -13,97 +12,91 @@ export type SelectorTokenIndex = WritableTokenIndex<SelectorToken<unknown>>
|
|
|
13
12
|
|
|
14
13
|
export const attachSelectorIndex = (
|
|
15
14
|
store: Store,
|
|
16
|
-
):
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
key: val.family.key,
|
|
36
|
-
familyMembers: new Map(),
|
|
37
|
-
}
|
|
38
|
-
base.set(val.family.key, familyNode)
|
|
15
|
+
): AtomToken<SelectorTokenIndex> => {
|
|
16
|
+
return createRegularAtom<SelectorTokenIndex>(
|
|
17
|
+
store,
|
|
18
|
+
{
|
|
19
|
+
key: `🔍 Selector Token Index`,
|
|
20
|
+
default: () => {
|
|
21
|
+
const base: SelectorTokenIndex = new Map()
|
|
22
|
+
for (const map of [store.readonlySelectors, store.writableSelectors]) {
|
|
23
|
+
for (const [key, val] of map) {
|
|
24
|
+
if (isReservedIntrospectionKey(key)) {
|
|
25
|
+
continue
|
|
26
|
+
}
|
|
27
|
+
const token = deposit(val)
|
|
28
|
+
if (val.family) {
|
|
29
|
+
let familyNode = base.get(val.family.key)
|
|
30
|
+
if (!familyNode || !(`familyMembers` in familyNode)) {
|
|
31
|
+
familyNode = {
|
|
32
|
+
key: val.family.key,
|
|
33
|
+
familyMembers: new Map(),
|
|
39
34
|
}
|
|
40
|
-
|
|
41
|
-
} else {
|
|
42
|
-
base.set(key, token)
|
|
35
|
+
base.set(val.family.key, familyNode)
|
|
43
36
|
}
|
|
37
|
+
familyNode.familyMembers.set(val.family.subKey, token)
|
|
38
|
+
} else {
|
|
39
|
+
base.set(key, token)
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
}
|
|
43
|
+
return base
|
|
44
|
+
},
|
|
45
|
+
effects: [
|
|
46
|
+
({ setSelf }) => {
|
|
47
|
+
store.on.selectorCreation.subscribe(
|
|
48
|
+
`introspection`,
|
|
49
|
+
(selectorToken) => {
|
|
50
|
+
if (isReservedIntrospectionKey(selectorToken.key)) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
self.set(familyKey, familyNode)
|
|
54
|
+
setSelf((self) => {
|
|
55
|
+
if (selectorToken.family) {
|
|
56
|
+
const { key: familyKey, subKey } = selectorToken.family
|
|
57
|
+
let familyNode = self.get(familyKey)
|
|
58
|
+
if (
|
|
59
|
+
familyNode === undefined ||
|
|
60
|
+
!(`familyMembers` in familyNode)
|
|
61
|
+
) {
|
|
62
|
+
familyNode = {
|
|
63
|
+
key: familyKey,
|
|
64
|
+
familyMembers: new Map(),
|
|
70
65
|
}
|
|
71
|
-
|
|
72
|
-
} else {
|
|
73
|
-
self.set(selectorToken.key, selectorToken)
|
|
66
|
+
self.set(familyKey, familyNode)
|
|
74
67
|
}
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
68
|
+
familyNode.familyMembers.set(subKey, selectorToken)
|
|
69
|
+
} else {
|
|
70
|
+
self.set(selectorToken.key, selectorToken)
|
|
71
|
+
}
|
|
72
|
+
return new Map(self)
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
)
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
77
|
+
store.on.selectorDisposal.subscribe(
|
|
78
|
+
`introspection`,
|
|
79
|
+
(selectorToken) => {
|
|
80
|
+
setSelf((self) => {
|
|
81
|
+
if (selectorToken.family) {
|
|
82
|
+
const { key: familyKey, subKey } = selectorToken.family
|
|
83
|
+
const familyNode = self.get(familyKey)
|
|
84
|
+
if (familyNode && `familyMembers` in familyNode) {
|
|
85
|
+
familyNode.familyMembers.delete(subKey)
|
|
86
|
+
if (familyNode.familyMembers.size === 0) {
|
|
87
|
+
self.delete(familyKey)
|
|
92
88
|
}
|
|
93
|
-
} else {
|
|
94
|
-
self.delete(selectorToken.key)
|
|
95
89
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
90
|
+
} else {
|
|
91
|
+
self.delete(selectorToken.key)
|
|
92
|
+
}
|
|
93
|
+
return new Map(self)
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
undefined,
|
|
101
|
+
)
|
|
109
102
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AtomToken, TimelineToken } from "atom.io"
|
|
2
2
|
import type { Store } from "atom.io/internal"
|
|
3
|
-
import { createRegularAtom
|
|
3
|
+
import { createRegularAtom } from "atom.io/internal"
|
|
4
4
|
|
|
5
5
|
export const attachTimelineIndex = (
|
|
6
6
|
store: Store,
|
|
7
|
-
):
|
|
8
|
-
|
|
9
|
-
TimelineToken<any>[]
|
|
10
|
-
>(
|
|
7
|
+
): AtomToken<TimelineToken<any>[]> => {
|
|
8
|
+
return createRegularAtom<TimelineToken<any>[]>(
|
|
11
9
|
store,
|
|
12
10
|
{
|
|
13
|
-
key: `🔍 Timeline Token Index
|
|
11
|
+
key: `🔍 Timeline Token Index`,
|
|
14
12
|
default: () =>
|
|
15
13
|
[...store.timelines].map(([key]): TimelineToken<any> => {
|
|
16
14
|
return { key, type: `timeline` }
|
|
@@ -28,9 +26,4 @@ export const attachTimelineIndex = (
|
|
|
28
26
|
},
|
|
29
27
|
undefined,
|
|
30
28
|
)
|
|
31
|
-
const timelineTokenIndex = createStandaloneSelector(store, {
|
|
32
|
-
key: `🔍 Timeline Token Index`,
|
|
33
|
-
get: ({ get }) => get(timelineTokenIndexState__INTERNAL),
|
|
34
|
-
})
|
|
35
|
-
return timelineTokenIndex
|
|
36
29
|
}
|
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AtomToken, TransactionToken } from "atom.io"
|
|
2
2
|
import type { Func, Store } from "atom.io/internal"
|
|
3
|
-
import { createRegularAtom,
|
|
3
|
+
import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
|
|
4
4
|
|
|
5
5
|
export const attachTransactionIndex = (
|
|
6
6
|
store: Store,
|
|
7
|
-
):
|
|
8
|
-
|
|
9
|
-
TransactionToken<Func>[]
|
|
10
|
-
>(
|
|
7
|
+
): AtomToken<TransactionToken<Func>[]> => {
|
|
8
|
+
return createRegularAtom<TransactionToken<Func>[]>(
|
|
11
9
|
store,
|
|
12
10
|
{
|
|
13
|
-
key: `🔍 Transaction Token Index
|
|
14
|
-
default: () =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
key: `🔍 Transaction Token Index`,
|
|
12
|
+
default: () => {
|
|
13
|
+
const tokens: TransactionToken<Func>[] = []
|
|
14
|
+
for (const [key] of store.transactions) {
|
|
15
|
+
if (isReservedIntrospectionKey(key)) {
|
|
16
|
+
continue
|
|
17
|
+
}
|
|
18
|
+
tokens.push({ key, type: `transaction` })
|
|
19
|
+
}
|
|
20
|
+
return tokens
|
|
21
|
+
},
|
|
18
22
|
effects: [
|
|
19
23
|
({ setSelf }) => {
|
|
20
24
|
store.on.transactionCreation.subscribe(
|
|
21
25
|
`introspection`,
|
|
22
26
|
(transactionToken) => {
|
|
27
|
+
if (isReservedIntrospectionKey(transactionToken.key)) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
23
30
|
setSelf((state) => [...state, transactionToken])
|
|
24
31
|
},
|
|
25
32
|
)
|
|
@@ -28,9 +35,4 @@ export const attachTransactionIndex = (
|
|
|
28
35
|
},
|
|
29
36
|
undefined,
|
|
30
37
|
)
|
|
31
|
-
const transactionTokenIndex = createStandaloneSelector(store, {
|
|
32
|
-
key: `🔍 Transaction Token Index`,
|
|
33
|
-
get: ({ get }) => get(transactionTokenIndexState__INTERNAL),
|
|
34
|
-
})
|
|
35
|
-
return transactionTokenIndex
|
|
36
38
|
}
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
type AtomToken,
|
|
3
3
|
getState,
|
|
4
4
|
type ReadableToken,
|
|
5
|
-
type ReadonlyPureSelectorToken,
|
|
6
5
|
type SelectorToken,
|
|
7
6
|
} from "atom.io"
|
|
8
7
|
import * as Internal from "atom.io/internal"
|
|
@@ -26,8 +25,8 @@ export class Auditor {
|
|
|
26
25
|
public readonly store: Internal.Store
|
|
27
26
|
public auditorCreatedAt: number = performance.now()
|
|
28
27
|
public statesCreatedAt: Map<string, number> = new Map()
|
|
29
|
-
public readonly atomIndex:
|
|
30
|
-
public readonly selectorIndex:
|
|
28
|
+
public readonly atomIndex: AtomToken<AtomTokenIndex>
|
|
29
|
+
public readonly selectorIndex: AtomToken<SelectorTokenIndex>
|
|
31
30
|
public disposed = false
|
|
32
31
|
|
|
33
32
|
private readonly unsubscribeFromAtomCreation: () => void
|
package/src/main/index.ts
CHANGED