atom.io 0.40.1 → 0.40.3
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.d.ts +1 -1
- package/dist/data/index.d.ts.map +1 -1
- package/dist/data/index.js.map +1 -1
- package/dist/internal/index.d.ts +155 -144
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +91 -39
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +4 -4
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +80 -56
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +11 -11
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/struct.ts +2 -2
- package/src/internal/atom/create-regular-atom.ts +8 -7
- package/src/internal/atom/dispose-atom.ts +6 -3
- package/src/internal/atom/has-role.ts +1 -1
- package/src/internal/caching.ts +15 -15
- package/src/internal/events/ingest-creation-disposal.ts +1 -1
- package/src/internal/families/create-readonly-held-selector-family.ts +6 -7
- package/src/internal/families/create-readonly-pure-selector-family.ts +23 -17
- package/src/internal/families/create-regular-atom-family.ts +17 -15
- package/src/internal/families/create-selector-family.ts +9 -9
- package/src/internal/families/create-writable-held-selector-family.ts +6 -7
- package/src/internal/families/create-writable-pure-selector-family.ts +24 -18
- package/src/internal/families/dispose-from-store.ts +10 -7
- package/src/internal/families/find-in-store.ts +23 -23
- package/src/internal/families/get-family-of-token.ts +17 -17
- package/src/internal/families/mint-in-store.ts +11 -11
- package/src/internal/families/seek-in-store.ts +26 -26
- package/src/internal/get-state/get-fallback.ts +8 -8
- package/src/internal/get-state/get-from-store.ts +17 -12
- package/src/internal/get-state/read-or-compute-value.ts +78 -14
- package/src/internal/get-state/reduce-reference.ts +10 -10
- package/src/internal/index.ts +58 -53
- package/src/internal/join/join-internal.ts +15 -6
- package/src/internal/mutable/create-mutable-atom-family.ts +7 -8
- package/src/internal/mutable/get-json-family.ts +3 -2
- package/src/internal/mutable/get-update-family.ts +7 -5
- package/src/internal/mutable/tracker-family.ts +5 -1
- package/src/internal/mutable/tracker.ts +5 -1
- package/src/internal/operation.ts +4 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +8 -6
- package/src/internal/selector/create-standalone-selector.ts +10 -10
- package/src/internal/selector/create-writable-pure-selector.ts +9 -7
- package/src/internal/selector/dispose-selector.ts +2 -2
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/internal/selector/trace-selector-atoms.ts +3 -3
- package/src/internal/selector/update-selector-atoms.ts +1 -1
- package/src/internal/set-state/dispatch-state-update.ts +9 -5
- package/src/internal/set-state/evict-downstream.ts +4 -1
- package/src/internal/set-state/operate-on-store.ts +16 -10
- package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
- package/src/internal/set-state/reset-in-store.ts +9 -6
- package/src/internal/set-state/set-atom-or-selector.ts +1 -1
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/set-state/set-into-store.ts +10 -7
- package/src/internal/set-state/set-selector.ts +1 -1
- package/src/internal/store/deposit.ts +38 -30
- package/src/internal/store/mint-or-counterfeit.ts +23 -23
- package/src/internal/store/store.ts +9 -9
- package/src/internal/store/withdraw.ts +68 -62
- package/src/internal/subscribe/recall-state.ts +4 -1
- package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
- package/src/internal/subscribe/subscribe-to-state.ts +4 -4
- package/src/internal/timeline/create-timeline.ts +5 -5
- package/src/internal/utility-types.ts +2 -0
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-selector-index.ts +4 -2
- package/src/introspection/attach-timeline-family.ts +13 -11
- package/src/introspection/attach-timeline-index.ts +1 -1
- package/src/introspection/attach-transaction-index.ts +1 -1
- package/src/introspection/attach-transaction-logs.ts +4 -2
- package/src/introspection/attach-type-selectors.ts +2 -1
- package/src/introspection/index.ts +3 -5
- package/src/main/atom.ts +15 -9
- package/src/main/events.ts +25 -23
- package/src/main/get-state.ts +10 -8
- package/src/main/reset-state.ts +4 -4
- package/src/main/selector.ts +41 -24
- package/src/main/set-state.ts +8 -4
- package/src/main/timeline.ts +5 -3
- package/src/main/tokens.ts +72 -44
- package/src/main/validators.ts +4 -4
- package/src/react/parse-state-overloads.ts +10 -10
- package/src/react/use-i.ts +6 -6
- package/src/react/use-loadable.ts +15 -15
- package/src/react/use-o.ts +9 -9
- package/src/react-devtools/StateEditor.tsx +5 -3
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/Updates.tsx +1 -1
- package/src/react-devtools/store.ts +16 -7
|
@@ -8,21 +8,21 @@ import type { Store } from "atom.io/internal"
|
|
|
8
8
|
import { findInStore } from "atom.io/internal"
|
|
9
9
|
import type { Canonical } from "atom.io/json"
|
|
10
10
|
|
|
11
|
-
export function parseStateOverloads<T, K extends Canonical>(
|
|
11
|
+
export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
|
|
12
12
|
store: Store,
|
|
13
|
-
...rest: [WritableFamilyToken<T, K>,
|
|
14
|
-
): WritableToken<T>
|
|
13
|
+
...rest: [WritableFamilyToken<T, K, E>, Key] | [WritableToken<T, any, E>]
|
|
14
|
+
): WritableToken<T, K, E>
|
|
15
15
|
|
|
16
|
-
export function parseStateOverloads<T, K extends Canonical>(
|
|
16
|
+
export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
|
|
17
17
|
store: Store,
|
|
18
|
-
...rest: [ReadableFamilyToken<T, K>,
|
|
19
|
-
): ReadableToken<T>
|
|
18
|
+
...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
|
|
19
|
+
): ReadableToken<T, K, E>
|
|
20
20
|
|
|
21
|
-
export function parseStateOverloads<T, K extends Canonical>(
|
|
21
|
+
export function parseStateOverloads<T, K extends Canonical, Key extends K, E>(
|
|
22
22
|
store: Store,
|
|
23
|
-
...rest: [ReadableFamilyToken<T, K>,
|
|
24
|
-
): ReadableToken<T> {
|
|
25
|
-
let token: ReadableToken<any>
|
|
23
|
+
...rest: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
|
|
24
|
+
): ReadableToken<T, K, E> {
|
|
25
|
+
let token: ReadableToken<any, any, any>
|
|
26
26
|
if (rest.length === 2) {
|
|
27
27
|
const family = rest[0]
|
|
28
28
|
const key = rest[1]
|
package/src/react/use-i.ts
CHANGED
|
@@ -7,16 +7,16 @@ import { parseStateOverloads } from "./parse-state-overloads"
|
|
|
7
7
|
import { StoreContext } from "./store-context"
|
|
8
8
|
|
|
9
9
|
export function useI<T>(
|
|
10
|
-
token: WritableToken<T>,
|
|
10
|
+
token: WritableToken<T, any, any>,
|
|
11
11
|
): <New extends T>(next: New | ((old: T) => New)) => void
|
|
12
12
|
|
|
13
|
-
export function useI<T, K extends Canonical>(
|
|
14
|
-
token: WritableFamilyToken<T, K>,
|
|
15
|
-
key:
|
|
13
|
+
export function useI<T, K extends Canonical, Key extends K>(
|
|
14
|
+
token: WritableFamilyToken<T, K, any>,
|
|
15
|
+
key: Key,
|
|
16
16
|
): <New extends T>(next: New | ((old: T) => New)) => void
|
|
17
17
|
|
|
18
|
-
export function useI<T, K extends Canonical>(
|
|
19
|
-
...params: [WritableFamilyToken<T, K>,
|
|
18
|
+
export function useI<T, K extends Canonical, Key extends K>(
|
|
19
|
+
...params: [WritableFamilyToken<T, K, any>, Key] | [WritableToken<T, any, any>]
|
|
20
20
|
): <New extends T>(next: New | ((old: T) => New)) => void {
|
|
21
21
|
const store = React.useContext(StoreContext)
|
|
22
22
|
const token = parseStateOverloads(store, ...params)
|
|
@@ -4,32 +4,32 @@ import type { Canonical } from "atom.io/json"
|
|
|
4
4
|
import { useO } from "atom.io/react"
|
|
5
5
|
import React from "react"
|
|
6
6
|
|
|
7
|
-
export function useLoadable<T>(
|
|
8
|
-
token: ReadableToken<Loadable<T
|
|
9
|
-
): `LOADING` | { loading: boolean; value: T }
|
|
7
|
+
export function useLoadable<T, E>(
|
|
8
|
+
token: ReadableToken<Loadable<T>, any, E>,
|
|
9
|
+
): `LOADING` | { loading: boolean; value: E | T }
|
|
10
10
|
|
|
11
|
-
export function useLoadable<T, K extends Canonical>(
|
|
12
|
-
token: ReadableFamilyToken<Loadable<T>, K>,
|
|
11
|
+
export function useLoadable<T, K extends Canonical, E>(
|
|
12
|
+
token: ReadableFamilyToken<Loadable<T>, K, E>,
|
|
13
13
|
key: K,
|
|
14
|
-
): `LOADING` | { loading: boolean; value: T }
|
|
14
|
+
): `LOADING` | { loading: boolean; value: E | T }
|
|
15
15
|
|
|
16
|
-
export function useLoadable<T, F extends T>(
|
|
17
|
-
token: ReadableToken<Loadable<T
|
|
16
|
+
export function useLoadable<T, F extends T, E>(
|
|
17
|
+
token: ReadableToken<Loadable<T>, any, E>,
|
|
18
18
|
fallback: F,
|
|
19
19
|
): { loading: boolean; value: T }
|
|
20
20
|
|
|
21
|
-
export function useLoadable<T, K extends Canonical, F extends T>(
|
|
22
|
-
token: ReadableFamilyToken<Loadable<T>, K>,
|
|
21
|
+
export function useLoadable<T, K extends Canonical, F extends T, E>(
|
|
22
|
+
token: ReadableFamilyToken<Loadable<T>, K, E>,
|
|
23
23
|
key: K,
|
|
24
24
|
fallback: F,
|
|
25
|
-
): { loading: boolean; value: T }
|
|
25
|
+
): { loading: boolean; value: E | T }
|
|
26
26
|
|
|
27
27
|
export function useLoadable(
|
|
28
28
|
...params:
|
|
29
|
-
| readonly [ReadableFamilyToken<any, Canonical>, Canonical, unknown]
|
|
30
|
-
| readonly [ReadableFamilyToken<any, Canonical>, Canonical]
|
|
31
|
-
| readonly [ReadableToken<any>, unknown]
|
|
32
|
-
| readonly [ReadableToken<any>]
|
|
29
|
+
| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical, unknown]
|
|
30
|
+
| readonly [ReadableFamilyToken<any, Canonical, any>, Canonical]
|
|
31
|
+
| readonly [ReadableToken<any, any, any>, unknown]
|
|
32
|
+
| readonly [ReadableToken<any, any, any>]
|
|
33
33
|
): `LOADING` | { loading: boolean; value: unknown } {
|
|
34
34
|
let state: unknown
|
|
35
35
|
let fallback: unknown
|
package/src/react/use-o.ts
CHANGED
|
@@ -6,20 +6,20 @@ import * as React from "react"
|
|
|
6
6
|
import { parseStateOverloads } from "./parse-state-overloads"
|
|
7
7
|
import { StoreContext } from "./store-context"
|
|
8
8
|
|
|
9
|
-
export function useO<T>(token: ReadableToken<T>): T
|
|
9
|
+
export function useO<T, E>(token: ReadableToken<T, any, E>): E | T
|
|
10
10
|
|
|
11
|
-
export function useO<T, K extends Canonical>(
|
|
12
|
-
token: ReadableFamilyToken<T, K>,
|
|
13
|
-
key:
|
|
14
|
-
): T
|
|
11
|
+
export function useO<T, K extends Canonical, Key extends K, E>(
|
|
12
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
13
|
+
key: Key,
|
|
14
|
+
): E | T
|
|
15
15
|
|
|
16
|
-
export function useO<T, K extends Canonical>(
|
|
17
|
-
...params: [ReadableFamilyToken<T, K>,
|
|
18
|
-
): T {
|
|
16
|
+
export function useO<T, K extends Canonical, Key extends K, E>(
|
|
17
|
+
...params: [ReadableFamilyToken<T, K, E>, Key] | [ReadableToken<T, any, E>]
|
|
18
|
+
): E | T {
|
|
19
19
|
const store = React.useContext(StoreContext)
|
|
20
20
|
const token = parseStateOverloads(store, ...params)
|
|
21
21
|
const id = React.useId()
|
|
22
|
-
return React.useSyncExternalStore<T>(
|
|
22
|
+
return React.useSyncExternalStore<E | T>(
|
|
23
23
|
(dispatch) => subscribeToState(store, token, `use-o:${id}`, dispatch),
|
|
24
24
|
() => getFromStore(store, token),
|
|
25
25
|
() => getFromStore(store, token),
|
|
@@ -5,7 +5,7 @@ import type { FC } from "react"
|
|
|
5
5
|
import { JsonEditor } from "./json-editor"
|
|
6
6
|
|
|
7
7
|
export const StateEditor: FC<{
|
|
8
|
-
token: WritableToken<unknown>
|
|
8
|
+
token: WritableToken<unknown, any, unknown>
|
|
9
9
|
}> = ({ token }) => {
|
|
10
10
|
const set = useI(token)
|
|
11
11
|
const data = useO(token)
|
|
@@ -23,7 +23,7 @@ export const StateEditor: FC<{
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const ReadonlySelectorViewer: FC<{
|
|
26
|
-
token: ReadonlySelectorToken<unknown>
|
|
26
|
+
token: ReadonlySelectorToken<unknown, any, unknown>
|
|
27
27
|
}> = ({ token }) => {
|
|
28
28
|
const data = useO(token)
|
|
29
29
|
const metaPath = token.family
|
|
@@ -41,7 +41,9 @@ export const ReadonlySelectorViewer: FC<{
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export const StoreEditor: FC<{
|
|
44
|
-
token:
|
|
44
|
+
token:
|
|
45
|
+
| ReadonlySelectorToken<unknown, any, unknown>
|
|
46
|
+
| WritableToken<unknown, any, unknown>
|
|
45
47
|
}> = ({ token }) => {
|
|
46
48
|
switch (token.type) {
|
|
47
49
|
case `readonly_pure_selector`:
|
|
@@ -25,7 +25,7 @@ import { DevtoolsContext } from "./store"
|
|
|
25
25
|
/* eslint-disable no-console */
|
|
26
26
|
|
|
27
27
|
export const StateIndexLeafNode: FC<{
|
|
28
|
-
node: ReadableToken<unknown>
|
|
28
|
+
node: ReadableToken<unknown, any, unknown>
|
|
29
29
|
isOpenState: RegularAtomToken<boolean>
|
|
30
30
|
typeState: ReadonlyPureSelectorToken<Loadable<string>>
|
|
31
31
|
dispose?: (() => void) | undefined
|
|
@@ -95,7 +95,7 @@ export const StateIndexLeafNode: FC<{
|
|
|
95
95
|
)
|
|
96
96
|
}
|
|
97
97
|
export const StateIndexTreeNode: FC<{
|
|
98
|
-
node: FamilyNode<ReadableToken<unknown>>
|
|
98
|
+
node: FamilyNode<ReadableToken<unknown, any, unknown>>
|
|
99
99
|
isOpenState: RegularAtomToken<boolean>
|
|
100
100
|
}> = ({ node, isOpenState }) => {
|
|
101
101
|
const setIsOpen = useI(isOpenState)
|
|
@@ -147,7 +147,9 @@ export const StateIndexTreeNode: FC<{
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
export const StateIndexNode: FC<{
|
|
150
|
-
node:
|
|
150
|
+
node:
|
|
151
|
+
| FamilyNode<ReadableToken<unknown, any, unknown>>
|
|
152
|
+
| ReadableToken<unknown, any, unknown>
|
|
151
153
|
isOpenState: RegularAtomToken<boolean>
|
|
152
154
|
typeState: ReadonlyPureSelectorToken<Loadable<string>>
|
|
153
155
|
dispose?: () => void
|
|
@@ -169,7 +171,7 @@ export const StateIndexNode: FC<{
|
|
|
169
171
|
}
|
|
170
172
|
|
|
171
173
|
export const StateIndex: FC<{
|
|
172
|
-
tokenIndex: AtomToken<WritableTokenIndex<ReadableToken<unknown>>>
|
|
174
|
+
tokenIndex: AtomToken<WritableTokenIndex<ReadableToken<unknown, any, unknown>>>
|
|
173
175
|
}> = ({ tokenIndex }) => {
|
|
174
176
|
const tokenIds = useO(tokenIndex)
|
|
175
177
|
|
|
@@ -39,7 +39,7 @@ export function attachDevtoolsStates(
|
|
|
39
39
|
): DevtoolsStates & IntrospectionStates & { store: Store } {
|
|
40
40
|
const introspectionStates = attachIntrospectionStates(store)
|
|
41
41
|
|
|
42
|
-
const devtoolsAreHiddenAtom = createRegularAtom<boolean>(
|
|
42
|
+
const devtoolsAreHiddenAtom = createRegularAtom<boolean, never, never>(
|
|
43
43
|
store,
|
|
44
44
|
{
|
|
45
45
|
key: `🔍 Devtools Are Hidden`,
|
|
@@ -62,7 +62,7 @@ export function attachDevtoolsStates(
|
|
|
62
62
|
undefined,
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
const devtoolsAreOpenAtom = createRegularAtom<boolean>(
|
|
65
|
+
const devtoolsAreOpenAtom = createRegularAtom<boolean, never, never>(
|
|
66
66
|
store,
|
|
67
67
|
{
|
|
68
68
|
key: `🔍 Devtools Are Open`,
|
|
@@ -75,7 +75,11 @@ export function attachDevtoolsStates(
|
|
|
75
75
|
undefined,
|
|
76
76
|
)
|
|
77
77
|
|
|
78
|
-
const devtoolsViewSelectionAtom = createRegularAtom<
|
|
78
|
+
const devtoolsViewSelectionAtom = createRegularAtom<
|
|
79
|
+
DevtoolsView,
|
|
80
|
+
never,
|
|
81
|
+
never
|
|
82
|
+
>(
|
|
79
83
|
store,
|
|
80
84
|
{
|
|
81
85
|
key: `🔍 Devtools View Selection`,
|
|
@@ -88,7 +92,11 @@ export function attachDevtoolsStates(
|
|
|
88
92
|
undefined,
|
|
89
93
|
)
|
|
90
94
|
|
|
91
|
-
const devtoolsViewOptionsAtom = createRegularAtom<
|
|
95
|
+
const devtoolsViewOptionsAtom = createRegularAtom<
|
|
96
|
+
DevtoolsView[],
|
|
97
|
+
never,
|
|
98
|
+
never
|
|
99
|
+
>(
|
|
92
100
|
store,
|
|
93
101
|
{
|
|
94
102
|
key: `🔍 Devtools View Options`,
|
|
@@ -103,7 +111,8 @@ export function attachDevtoolsStates(
|
|
|
103
111
|
|
|
104
112
|
const viewIsOpenAtoms = createRegularAtomFamily<
|
|
105
113
|
boolean,
|
|
106
|
-
readonly (number | string)[]
|
|
114
|
+
readonly (number | string)[],
|
|
115
|
+
never
|
|
107
116
|
>(store, {
|
|
108
117
|
key: `🔍 Devtools View Is Open`,
|
|
109
118
|
default: false,
|
|
@@ -122,8 +131,8 @@ export function attachDevtoolsStates(
|
|
|
122
131
|
do: ({ get, set }, path, current) => {
|
|
123
132
|
const currentView = get(devtoolsViewSelectionAtom)
|
|
124
133
|
let states:
|
|
125
|
-
| WritableTokenIndex<AtomToken<unknown>>
|
|
126
|
-
| WritableTokenIndex<SelectorToken<unknown>>
|
|
134
|
+
| WritableTokenIndex<AtomToken<unknown, any, any>>
|
|
135
|
+
| WritableTokenIndex<SelectorToken<unknown, any, any>>
|
|
127
136
|
switch (currentView) {
|
|
128
137
|
case `atoms`:
|
|
129
138
|
states = get(introspectionStates.atomIndex)
|