atom.io 0.40.0 → 0.40.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/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 +205 -196
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +145 -107
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +6 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +93 -66
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +16 -13
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +14 -14
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.js +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +3 -3
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/data/struct.ts +2 -2
- package/src/internal/atom/create-regular-atom.ts +11 -9
- package/src/internal/atom/dispose-atom.ts +11 -8
- 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 +3 -4
- package/src/internal/families/create-readonly-pure-selector-family.ts +25 -23
- package/src/internal/families/create-regular-atom-family.ts +21 -15
- package/src/internal/families/create-selector-family.ts +15 -15
- package/src/internal/families/create-writable-held-selector-family.ts +2 -2
- package/src/internal/families/create-writable-pure-selector-family.ts +25 -21
- package/src/internal/families/dispose-from-store.ts +17 -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 +10 -10
- 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 +20 -8
- 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 +65 -60
- package/src/internal/install-into-store.ts +2 -1
- package/src/internal/join/create-join.ts +2 -2
- package/src/internal/join/find-relations-in-store.ts +2 -2
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/get-join.ts +5 -2
- package/src/internal/join/join-internal.ts +30 -26
- package/src/internal/lineage.ts +12 -1
- package/src/internal/molecule.ts +64 -36
- package/src/internal/mutable/create-mutable-atom-family.ts +5 -5
- package/src/internal/mutable/create-mutable-atom.ts +2 -2
- 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 +8 -4
- package/src/internal/mutable/tracker.ts +5 -1
- package/src/internal/operation.ts +4 -2
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +10 -8
- package/src/internal/selector/create-standalone-selector.ts +10 -10
- package/src/internal/selector/create-writable-held-selector.ts +2 -2
- package/src/internal/selector/create-writable-pure-selector.ts +11 -9
- 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/become.ts +1 -3
- package/src/internal/set-state/dispatch-state-update.ts +10 -6
- 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 +17 -16
- 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 +34 -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 +23 -21
- 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 +11 -10
- package/src/internal/timeline/time-travel.ts +4 -3
- package/src/internal/transaction/abort-transaction.ts +3 -15
- package/src/internal/transaction/act-upon-store.ts +1 -5
- package/src/internal/transaction/apply-transaction.ts +3 -15
- package/src/internal/transaction/assign-transaction-to-continuity.ts +2 -7
- package/src/internal/transaction/build-transaction.ts +2 -3
- package/src/internal/transaction/create-transaction.ts +5 -6
- package/src/internal/transaction/get-epoch-number.ts +1 -7
- package/src/internal/transaction/set-epoch-number.ts +4 -12
- package/src/introspection/attach-atom-index.ts +2 -2
- package/src/introspection/attach-introspection-states.ts +4 -2
- package/src/introspection/attach-selector-index.ts +4 -2
- package/src/introspection/attach-timeline-family.ts +15 -13
- 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 +6 -4
- package/src/introspection/attach-type-selectors.ts +4 -3
- package/src/introspection/index.ts +3 -5
- package/src/main/atom.ts +14 -8
- package/src/main/dispose-state.ts +1 -5
- package/src/main/events.ts +26 -26
- package/src/main/get-state.ts +10 -11
- package/src/main/realm.ts +36 -12
- package/src/main/reset-state.ts +5 -9
- package/src/main/selector.ts +40 -24
- package/src/main/set-state.ts +8 -11
- package/src/main/silo.ts +4 -3
- 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/store-context.tsx +3 -3
- 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/Button.tsx +3 -2
- package/src/react-devtools/StateEditor.tsx +5 -3
- package/src/react-devtools/StateIndex.tsx +6 -4
- package/src/react-devtools/TimelineIndex.tsx +0 -2
- package/src/react-devtools/Updates.tsx +1 -1
- package/src/react-devtools/store.ts +18 -9
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +4 -8
- package/src/realtime-client/sync-continuity.ts +2 -2
- package/src/realtime-server/index.ts +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReadonlyPureSelectorFamilyToken } from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { RootStore, Timeline } from "atom.io/internal"
|
|
3
3
|
import {
|
|
4
4
|
createRegularAtomFamily,
|
|
5
5
|
createSelectorFamily,
|
|
@@ -7,11 +7,12 @@ import {
|
|
|
7
7
|
} from "atom.io/internal"
|
|
8
8
|
|
|
9
9
|
export const attachTimelineFamily = (
|
|
10
|
-
store:
|
|
10
|
+
store: RootStore,
|
|
11
11
|
): ReadonlyPureSelectorFamilyToken<Timeline<any>, string> => {
|
|
12
12
|
const findTimelineLogState__INTERNAL = createRegularAtomFamily<
|
|
13
13
|
Timeline<any>,
|
|
14
|
-
string
|
|
14
|
+
string,
|
|
15
|
+
never
|
|
15
16
|
>(store, {
|
|
16
17
|
key: `🔍 Timeline Update Log (Internal)`,
|
|
17
18
|
default: (key) =>
|
|
@@ -36,15 +37,16 @@ export const attachTimelineFamily = (
|
|
|
36
37
|
},
|
|
37
38
|
],
|
|
38
39
|
})
|
|
39
|
-
const findTimelineLogState = createSelectorFamily<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
const findTimelineLogState = createSelectorFamily<
|
|
41
|
+
Timeline<any>,
|
|
42
|
+
string,
|
|
43
|
+
never
|
|
44
|
+
>(store, {
|
|
45
|
+
key: `🔍 Timeline Update Log`,
|
|
46
|
+
get:
|
|
47
|
+
(key) =>
|
|
48
|
+
({ get }) =>
|
|
49
|
+
get(findTimelineLogState__INTERNAL, key),
|
|
50
|
+
})
|
|
49
51
|
return findTimelineLogState
|
|
50
52
|
}
|
|
@@ -5,7 +5,7 @@ import { createRegularAtom } from "atom.io/internal"
|
|
|
5
5
|
export const attachTimelineIndex = (
|
|
6
6
|
store: Store,
|
|
7
7
|
): AtomToken<TimelineToken<any>[]> => {
|
|
8
|
-
return createRegularAtom<TimelineToken<any>[]>(
|
|
8
|
+
return createRegularAtom<TimelineToken<any>[], never, never>(
|
|
9
9
|
store,
|
|
10
10
|
{
|
|
11
11
|
key: `🔍 Timeline Token Index`,
|
|
@@ -5,7 +5,7 @@ import { createRegularAtom, isReservedIntrospectionKey } from "atom.io/internal"
|
|
|
5
5
|
export const attachTransactionIndex = (
|
|
6
6
|
store: Store,
|
|
7
7
|
): AtomToken<TransactionToken<Fn>[]> => {
|
|
8
|
-
return createRegularAtom<TransactionToken<Fn>[]>(
|
|
8
|
+
return createRegularAtom<TransactionToken<Fn>[], never, never>(
|
|
9
9
|
store,
|
|
10
10
|
{
|
|
11
11
|
key: `🔍 Transaction Token Index`,
|
|
@@ -3,18 +3,19 @@ import type {
|
|
|
3
3
|
TransactionOutcomeEvent,
|
|
4
4
|
TransactionToken,
|
|
5
5
|
} from "atom.io"
|
|
6
|
-
import type {
|
|
6
|
+
import type { RootStore } from "atom.io/internal"
|
|
7
7
|
import { createRegularAtomFamily, createSelectorFamily } from "atom.io/internal"
|
|
8
8
|
|
|
9
9
|
export const attachTransactionLogs = (
|
|
10
|
-
store:
|
|
10
|
+
store: RootStore,
|
|
11
11
|
): ReadonlyPureSelectorFamilyToken<
|
|
12
12
|
TransactionOutcomeEvent<TransactionToken<any>>[],
|
|
13
13
|
string
|
|
14
14
|
> => {
|
|
15
15
|
const transactionUpdateLogAtoms = createRegularAtomFamily<
|
|
16
16
|
TransactionOutcomeEvent<TransactionToken<any>>[],
|
|
17
|
-
string
|
|
17
|
+
string,
|
|
18
|
+
never
|
|
18
19
|
>(store, {
|
|
19
20
|
key: `🔍 Transaction Update Log (Internal)`,
|
|
20
21
|
default: () => [],
|
|
@@ -31,7 +32,8 @@ export const attachTransactionLogs = (
|
|
|
31
32
|
})
|
|
32
33
|
const findTransactionUpdateLogState = createSelectorFamily<
|
|
33
34
|
TransactionOutcomeEvent<TransactionToken<any>>[],
|
|
34
|
-
string
|
|
35
|
+
string,
|
|
36
|
+
never
|
|
35
37
|
>(store, {
|
|
36
38
|
key: `🔍 Transaction Update Log`,
|
|
37
39
|
get:
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { Loadable, ReadonlyPureSelectorFamilyToken } from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { RootStore } from "atom.io/internal"
|
|
3
3
|
import { createReadonlyPureSelectorFamily } from "atom.io/internal"
|
|
4
4
|
|
|
5
5
|
import { discoverType } from "./refinery"
|
|
6
6
|
|
|
7
7
|
export const attachTypeSelectors = (
|
|
8
|
-
store:
|
|
8
|
+
store: RootStore,
|
|
9
9
|
): ReadonlyPureSelectorFamilyToken<Loadable<string>, string> => {
|
|
10
10
|
const typeSelectors = createReadonlyPureSelectorFamily<
|
|
11
11
|
Loadable<string>,
|
|
12
|
-
string
|
|
12
|
+
string,
|
|
13
|
+
never
|
|
13
14
|
>(store, {
|
|
14
15
|
key: `🔍 State Type`,
|
|
15
16
|
get:
|
|
@@ -6,12 +6,10 @@ export * from "./differ"
|
|
|
6
6
|
export * from "./refinery"
|
|
7
7
|
export * from "./sprawl"
|
|
8
8
|
|
|
9
|
-
export type FamilyNode<Token extends ReadableToken<unknown>> = {
|
|
9
|
+
export type FamilyNode<Token extends ReadableToken<unknown, any, any>> = {
|
|
10
10
|
key: string
|
|
11
11
|
familyMembers: Map<string, Token>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export type WritableTokenIndex<Token extends ReadableToken<unknown>> =
|
|
15
|
-
string,
|
|
16
|
-
FamilyNode<Token> | Token
|
|
17
|
-
>
|
|
14
|
+
export type WritableTokenIndex<Token extends ReadableToken<unknown, any, any>> =
|
|
15
|
+
Map<string, FamilyNode<Token> | Token>
|
package/src/main/atom.ts
CHANGED
|
@@ -17,13 +17,15 @@ import type {
|
|
|
17
17
|
RegularAtomToken,
|
|
18
18
|
} from "./tokens"
|
|
19
19
|
|
|
20
|
-
export type RegularAtomOptions<T> = {
|
|
20
|
+
export type RegularAtomOptions<T, E = never> = {
|
|
21
21
|
/** The unique identifier of the atom */
|
|
22
22
|
key: string
|
|
23
23
|
/** The starting value of the atom */
|
|
24
24
|
default: T | (() => T)
|
|
25
25
|
/** Hooks used to run side effects when the atom is set */
|
|
26
|
-
effects?: AtomEffect<T>[]
|
|
26
|
+
effects?: readonly AtomEffect<T>[]
|
|
27
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
28
|
+
catch?: readonly (new () => E)[]
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Create a regular atom, a global reactive variable in the implicit store
|
|
@@ -31,7 +33,9 @@ export type RegularAtomOptions<T> = {
|
|
|
31
33
|
* @returns
|
|
32
34
|
* A reference to the atom created: a {@link RegularAtomToken}
|
|
33
35
|
*/
|
|
34
|
-
export function atom<T
|
|
36
|
+
export function atom<T, E = never>(
|
|
37
|
+
options: RegularAtomOptions<T, E>,
|
|
38
|
+
): RegularAtomToken<T, any, E> {
|
|
35
39
|
return createRegularAtom(IMPLICIT.STORE, options, undefined)
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -41,7 +45,7 @@ export type MutableAtomOptions<T extends Transceiver<any, any, any>> = {
|
|
|
41
45
|
/** A constructor for the atom's value */
|
|
42
46
|
class: ConstructorOf<T>
|
|
43
47
|
/** Hooks used to run side effects when the atom is set */
|
|
44
|
-
effects?: AtomEffect<T>[]
|
|
48
|
+
effects?: readonly AtomEffect<T>[]
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* Create a mutable atom, a global reactive variable in the implicit store
|
|
@@ -79,13 +83,15 @@ export type Effectors<T> = {
|
|
|
79
83
|
onSet: (callback: (options: StateUpdate<T>) => void) => void
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
export type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
86
|
+
export type RegularAtomFamilyOptions<T, K extends Canonical, E = never> = {
|
|
83
87
|
/** The unique identifier of the atom family */
|
|
84
88
|
key: string
|
|
85
89
|
/** The starting value of the atom family */
|
|
86
90
|
default: T | ((key: K) => T)
|
|
87
91
|
/** Hooks used to run side effects when an atom in the family is set */
|
|
88
92
|
effects?: (key: K) => AtomEffect<T>[]
|
|
93
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
94
|
+
catch?: readonly (new () => E)[]
|
|
89
95
|
}
|
|
90
96
|
/**
|
|
91
97
|
* Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
|
|
@@ -93,9 +99,9 @@ export type RegularAtomFamilyOptions<T, K extends Canonical> = {
|
|
|
93
99
|
* @returns
|
|
94
100
|
* A reference to the atom family created: a {@link RegularAtomFamilyToken}
|
|
95
101
|
*/
|
|
96
|
-
export function atomFamily<T, K extends Canonical>(
|
|
97
|
-
options: RegularAtomFamilyOptions<T, K>,
|
|
98
|
-
): RegularAtomFamilyToken<T, K> {
|
|
102
|
+
export function atomFamily<T, K extends Canonical, E = never>(
|
|
103
|
+
options: RegularAtomFamilyOptions<T, K, E>,
|
|
104
|
+
): RegularAtomFamilyToken<T, K, E> {
|
|
99
105
|
return createRegularAtomFamily(IMPLICIT.STORE, options)
|
|
100
106
|
}
|
|
101
107
|
|
|
@@ -30,9 +30,5 @@ export function disposeState(
|
|
|
30
30
|
| [token: ReadableFamilyToken<any, any>, key: Canonical]
|
|
31
31
|
| [token: ReadableToken<any>]
|
|
32
32
|
): void {
|
|
33
|
-
|
|
34
|
-
disposeFromStore(IMPLICIT.STORE, ...params)
|
|
35
|
-
} else {
|
|
36
|
-
disposeFromStore(IMPLICIT.STORE, ...params)
|
|
37
|
-
}
|
|
33
|
+
disposeFromStore(IMPLICIT.STORE, ...params)
|
|
38
34
|
}
|
package/src/main/events.ts
CHANGED
|
@@ -16,14 +16,14 @@ export type StateUpdate<T> = {
|
|
|
16
16
|
readonly newValue: ViewOf<T>
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export type AtomUpdateEvent<A extends AtomToken<any>> = {
|
|
19
|
+
export type AtomUpdateEvent<A extends AtomToken<any, any, any>> = {
|
|
20
20
|
type: `atom_update`
|
|
21
21
|
token: A
|
|
22
22
|
update: StateUpdate<TokenType<A>>
|
|
23
23
|
timestamp: number
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export type SelectorUpdateSubEvent<A extends AtomToken<any>> =
|
|
26
|
+
export type SelectorUpdateSubEvent<A extends AtomToken<any, any, any>> =
|
|
27
27
|
| AtomUpdateEvent<A>
|
|
28
28
|
| StateCreationEvent<any>
|
|
29
29
|
export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
|
|
@@ -33,36 +33,38 @@ export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
|
|
|
33
33
|
timestamp: number
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export type StateLifecycleEvent<R extends ReadableToken<any>> =
|
|
36
|
+
export type StateLifecycleEvent<R extends ReadableToken<any, any, any>> =
|
|
37
37
|
| StateCreationEvent<R>
|
|
38
38
|
| StateDisposalEvent<R>
|
|
39
|
-
export type StateCreationEvent<R extends ReadableToken<any>> =
|
|
39
|
+
export type StateCreationEvent<R extends ReadableToken<any, any, any>> =
|
|
40
40
|
| ReadableStateCreationEvent<R>
|
|
41
41
|
| (R extends WritableToken<any> ? WritableStateCreationEvent<R> : never)
|
|
42
|
-
export type ReadableStateCreationEvent<R extends ReadableToken<any>> =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
export type ReadableStateCreationEvent<R extends ReadableToken<any, any, any>> =
|
|
43
|
+
{
|
|
44
|
+
type: `state_creation`
|
|
45
|
+
subType: `readable`
|
|
46
|
+
token: R
|
|
47
|
+
timestamp: number
|
|
48
|
+
}
|
|
49
|
+
export type WritableStateCreationEvent<W extends WritableToken<any, any, any>> =
|
|
50
|
+
{
|
|
51
|
+
type: `state_creation`
|
|
52
|
+
subType: `writable`
|
|
53
|
+
token: W
|
|
54
|
+
timestamp: number
|
|
55
|
+
value?: TokenType<W>
|
|
56
|
+
}
|
|
57
|
+
export type StateDisposalEvent<R extends ReadableToken<any, any, any>> =
|
|
56
58
|
| AtomDisposalEvent<R>
|
|
57
59
|
| SelectorDisposalEvent<R>
|
|
58
|
-
export type AtomDisposalEvent<R extends ReadableToken<any>> = {
|
|
60
|
+
export type AtomDisposalEvent<R extends ReadableToken<any, any, any>> = {
|
|
59
61
|
type: `state_disposal`
|
|
60
62
|
subType: `atom`
|
|
61
63
|
token: R
|
|
62
64
|
value: TokenType<R>
|
|
63
65
|
timestamp: number
|
|
64
66
|
}
|
|
65
|
-
export type SelectorDisposalEvent<R extends ReadableToken<any>> = {
|
|
67
|
+
export type SelectorDisposalEvent<R extends ReadableToken<any, any, any>> = {
|
|
66
68
|
type: `state_disposal`
|
|
67
69
|
subType: `selector`
|
|
68
70
|
token: R
|
|
@@ -94,12 +96,12 @@ export type MoleculeTransferEvent = {
|
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
export type TransactionSubEvent =
|
|
97
|
-
| AtomUpdateEvent<AtomToken<any>>
|
|
99
|
+
| AtomUpdateEvent<AtomToken<any, any, any>>
|
|
98
100
|
| MoleculeCreationEvent
|
|
99
101
|
| MoleculeDisposalEvent
|
|
100
102
|
| MoleculeTransferEvent
|
|
101
|
-
| StateCreationEvent<ReadableToken<unknown>>
|
|
102
|
-
| StateDisposalEvent<ReadableToken<unknown>>
|
|
103
|
+
| StateCreationEvent<ReadableToken<unknown, any, any>>
|
|
104
|
+
| StateDisposalEvent<ReadableToken<unknown, any, any>>
|
|
103
105
|
| TransactionOutcomeEvent<TransactionToken<any>>
|
|
104
106
|
|
|
105
107
|
export type TransactionOutcomeEvent<T extends TransactionToken<any>> = {
|
|
@@ -114,11 +116,9 @@ export type TransactionOutcomeEvent<T extends TransactionToken<any>> = {
|
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
export type TimelineEvent<ManagedAtom extends TimelineManageable> = {
|
|
117
|
-
|
|
119
|
+
checkpoint?: true
|
|
118
120
|
} & (
|
|
119
121
|
| AtomUpdateEvent<AtomOnly<ManagedAtom>>
|
|
120
|
-
| MoleculeCreationEvent
|
|
121
|
-
| MoleculeDisposalEvent
|
|
122
122
|
| StateCreationEvent<AtomOnly<ManagedAtom>>
|
|
123
123
|
| StateDisposalEvent<AtomOnly<ManagedAtom>>
|
|
124
124
|
| TimelineSelectorUpdateEvent<ManagedAtom>
|
package/src/main/get-state.ts
CHANGED
|
@@ -11,7 +11,9 @@ import type { ReadableFamilyToken, ReadableToken } from "."
|
|
|
11
11
|
* @overload Default
|
|
12
12
|
* @default
|
|
13
13
|
*/
|
|
14
|
-
export function getState<T
|
|
14
|
+
export function getState<T, E = never>(
|
|
15
|
+
token: ReadableToken<T, any, E>,
|
|
16
|
+
): ViewOf<E | T>
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Read or compute the current value of a state
|
|
@@ -20,18 +22,15 @@ export function getState<T>(token: ReadableToken<T>): ViewOf<T>
|
|
|
20
22
|
* @return The current value of the state
|
|
21
23
|
* @overload Streamlined
|
|
22
24
|
*/
|
|
23
|
-
export function getState<T, K extends Canonical, Key extends K>(
|
|
24
|
-
token: ReadableFamilyToken<T, K>,
|
|
25
|
+
export function getState<T, K extends Canonical, Key extends K, E = never>(
|
|
26
|
+
token: ReadableFamilyToken<T, K, E>,
|
|
25
27
|
key: Key,
|
|
26
|
-
): ViewOf<T>
|
|
28
|
+
): ViewOf<E | T>
|
|
27
29
|
|
|
28
|
-
export function getState(
|
|
30
|
+
export function getState<T, K extends Canonical, Key extends K, E = never>(
|
|
29
31
|
...params:
|
|
30
|
-
| [token: ReadableFamilyToken<
|
|
31
|
-
| [token: ReadableToken<any>]
|
|
32
|
-
):
|
|
33
|
-
if (params.length === 2) {
|
|
34
|
-
return getFromStore(IMPLICIT.STORE, ...params)
|
|
35
|
-
}
|
|
32
|
+
| [token: ReadableFamilyToken<T, K, E>, key: Key]
|
|
33
|
+
| [token: ReadableToken<T, any, E>]
|
|
34
|
+
): ViewOf<E | T> {
|
|
36
35
|
return getFromStore(IMPLICIT.STORE, ...params)
|
|
37
36
|
}
|
package/src/main/realm.ts
CHANGED
|
@@ -1,24 +1,39 @@
|
|
|
1
|
-
import type { Each,
|
|
1
|
+
import type { Each, RootStore } from "atom.io/internal"
|
|
2
2
|
import {
|
|
3
|
+
actUponStore,
|
|
3
4
|
allocateIntoStore,
|
|
5
|
+
arbitrary,
|
|
4
6
|
claimWithinStore,
|
|
5
|
-
|
|
7
|
+
createClaimTX,
|
|
8
|
+
createDeallocateTX,
|
|
6
9
|
fuseWithinStore,
|
|
7
10
|
IMPLICIT,
|
|
8
11
|
makeRootMoleculeInStore,
|
|
9
12
|
} from "atom.io/internal"
|
|
10
13
|
import type { Canonical } from "atom.io/json"
|
|
11
14
|
|
|
15
|
+
import type { TransactionToken } from "./tokens"
|
|
16
|
+
|
|
12
17
|
export const $claim: unique symbol = Symbol.for(`claim`)
|
|
13
18
|
export type Claim<K extends Canonical> = K & { [$claim]?: true }
|
|
14
19
|
|
|
15
20
|
export class Realm<H extends Hierarchy> {
|
|
16
|
-
public store:
|
|
21
|
+
public store: RootStore
|
|
22
|
+
public deallocateTX: TransactionToken<(claim: Claim<Vassal<H>>) => void>
|
|
23
|
+
public claimTX: TransactionToken<
|
|
24
|
+
<V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(
|
|
25
|
+
newProvenance: A,
|
|
26
|
+
claim: Claim<V>,
|
|
27
|
+
exclusive?: `exclusive`,
|
|
28
|
+
) => void
|
|
29
|
+
>
|
|
17
30
|
/**
|
|
18
31
|
* @param store - The store to which the realm will be attached
|
|
19
32
|
*/
|
|
20
|
-
public constructor(store:
|
|
33
|
+
public constructor(store: RootStore = IMPLICIT.STORE) {
|
|
21
34
|
this.store = store
|
|
35
|
+
this.deallocateTX = createDeallocateTX(store)
|
|
36
|
+
this.claimTX = createClaimTX(store)
|
|
22
37
|
makeRootMoleculeInStore(`root`, store)
|
|
23
38
|
}
|
|
24
39
|
/**
|
|
@@ -66,7 +81,7 @@ export class Realm<H extends Hierarchy> {
|
|
|
66
81
|
* @param claim - The subject to be deallocated
|
|
67
82
|
*/
|
|
68
83
|
public deallocate<V extends Vassal<H>>(claim: Claim<V>): void {
|
|
69
|
-
|
|
84
|
+
actUponStore(this.store, this.deallocateTX, arbitrary())(claim)
|
|
70
85
|
}
|
|
71
86
|
/**
|
|
72
87
|
* Transfer a subject of the realm from one owner to another
|
|
@@ -79,21 +94,30 @@ export class Realm<H extends Hierarchy> {
|
|
|
79
94
|
public claim<
|
|
80
95
|
V extends Exclude<Vassal<H>, CompoundTypedKey>,
|
|
81
96
|
A extends Above<V, H>,
|
|
82
|
-
>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`):
|
|
83
|
-
|
|
97
|
+
>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): void {
|
|
98
|
+
actUponStore(this.store, this.claimTX, arbitrary())(
|
|
99
|
+
newProvenance,
|
|
100
|
+
claim,
|
|
101
|
+
exclusive,
|
|
102
|
+
)
|
|
84
103
|
}
|
|
85
104
|
}
|
|
86
105
|
|
|
87
106
|
export class Anarchy {
|
|
88
|
-
public store:
|
|
89
|
-
public
|
|
107
|
+
public store: RootStore
|
|
108
|
+
public deallocateTX: TransactionToken<(key: Canonical) => void>
|
|
109
|
+
public claimTX: TransactionToken<
|
|
110
|
+
(newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`) => void
|
|
111
|
+
>
|
|
90
112
|
|
|
91
113
|
/**
|
|
92
114
|
* @param store - The store to which the anarchy-realm will be attached
|
|
93
115
|
*/
|
|
94
|
-
public constructor(store:
|
|
116
|
+
public constructor(store: RootStore = IMPLICIT.STORE) {
|
|
95
117
|
this.store = store
|
|
96
|
-
this.
|
|
118
|
+
this.deallocateTX = createDeallocateTX(store)
|
|
119
|
+
this.claimTX = createClaimTX(store)
|
|
120
|
+
makeRootMoleculeInStore(`root`, store)
|
|
97
121
|
}
|
|
98
122
|
/**
|
|
99
123
|
* Declare a new entity
|
|
@@ -118,7 +142,7 @@ export class Anarchy {
|
|
|
118
142
|
* @param key - The entity to be deallocated
|
|
119
143
|
*/
|
|
120
144
|
public deallocate(key: Canonical): void {
|
|
121
|
-
|
|
145
|
+
actUponStore(this.store, this.deallocateTX, arbitrary())(key)
|
|
122
146
|
}
|
|
123
147
|
/**
|
|
124
148
|
* Transfer an entity from one owner to another
|
package/src/main/reset-state.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { WritableFamilyToken, WritableToken } from "."
|
|
|
9
9
|
* @overload Default
|
|
10
10
|
* @default
|
|
11
11
|
*/
|
|
12
|
-
export function resetState(token: WritableToken<any>): void
|
|
12
|
+
export function resetState(token: WritableToken<any, any, any>): void
|
|
13
13
|
/**
|
|
14
14
|
* Set the value of a state into the implicit store back to its default value.
|
|
15
15
|
* @param token - An atom family or writable selector family token.
|
|
@@ -17,17 +17,13 @@ export function resetState(token: WritableToken<any>): void
|
|
|
17
17
|
* @overload Streamlined
|
|
18
18
|
*/
|
|
19
19
|
export function resetState<K extends Canonical>(
|
|
20
|
-
token: WritableFamilyToken<any, K>,
|
|
20
|
+
token: WritableFamilyToken<any, K, any>,
|
|
21
21
|
key: K,
|
|
22
22
|
): void
|
|
23
23
|
export function resetState(
|
|
24
24
|
...params:
|
|
25
|
-
| [token: WritableFamilyToken<any, Canonical>, key: Canonical]
|
|
26
|
-
| [token: WritableToken<any>]
|
|
25
|
+
| [token: WritableFamilyToken<any, Canonical, any>, key: Canonical]
|
|
26
|
+
| [token: WritableToken<any, any, any>]
|
|
27
27
|
): void {
|
|
28
|
-
|
|
29
|
-
resetInStore(IMPLICIT.STORE, ...params)
|
|
30
|
-
} else {
|
|
31
|
-
resetInStore(IMPLICIT.STORE, ...params)
|
|
32
|
-
}
|
|
28
|
+
resetInStore(IMPLICIT.STORE, ...params)
|
|
33
29
|
}
|
package/src/main/selector.ts
CHANGED
|
@@ -17,19 +17,23 @@ import type {
|
|
|
17
17
|
} from "./tokens"
|
|
18
18
|
import type { Read, Write } from "./transaction"
|
|
19
19
|
|
|
20
|
-
export type WritablePureSelectorOptions<T> = {
|
|
20
|
+
export type WritablePureSelectorOptions<T, E = never> = {
|
|
21
21
|
/** The unique identifier of the selector */
|
|
22
22
|
key: string
|
|
23
23
|
/** For each instantiated selector, a function that computes its value */
|
|
24
24
|
get: Read<() => T>
|
|
25
25
|
/** For each instantiated selector, a function that sets its value */
|
|
26
26
|
set: Write<(newValue: T) => void>
|
|
27
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
28
|
+
catch?: readonly (new () => E)[]
|
|
27
29
|
}
|
|
28
|
-
export type ReadonlyPureSelectorOptions<T> = {
|
|
30
|
+
export type ReadonlyPureSelectorOptions<T, E = never> = {
|
|
29
31
|
/** The unique identifier of the selector */
|
|
30
32
|
key: string
|
|
31
33
|
/** For each instantiated selector, a function that computes its value */
|
|
32
34
|
get: Read<() => T>
|
|
35
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
36
|
+
catch?: readonly (new () => E)[]
|
|
33
37
|
}
|
|
34
38
|
export type ReadonlyHeldSelectorOptions<T extends object> = {
|
|
35
39
|
/** The unique identifier of the selector */
|
|
@@ -104,9 +108,9 @@ export function selector<T extends object>(
|
|
|
104
108
|
* The token for your selector.
|
|
105
109
|
* @overload WritablePure
|
|
106
110
|
*/
|
|
107
|
-
export function selector<T>(
|
|
108
|
-
options: WritablePureSelectorOptions<T>,
|
|
109
|
-
): WritablePureSelectorToken<T>
|
|
111
|
+
export function selector<T, E = never>(
|
|
112
|
+
options: WritablePureSelectorOptions<T, E>,
|
|
113
|
+
): WritablePureSelectorToken<T, any, E>
|
|
110
114
|
/**
|
|
111
115
|
* Declare a selector. The value of a selector should depend
|
|
112
116
|
* on the value of atoms or other selectors in the store.
|
|
@@ -121,36 +125,48 @@ export function selector<T>(
|
|
|
121
125
|
* The token for your selector.
|
|
122
126
|
* @overload ReadonlyPure
|
|
123
127
|
*/
|
|
124
|
-
export function selector<T>(
|
|
125
|
-
options: ReadonlyPureSelectorOptions<T>,
|
|
126
|
-
): ReadonlyPureSelectorToken<T>
|
|
128
|
+
export function selector<T, E = never>(
|
|
129
|
+
options: ReadonlyPureSelectorOptions<T, E>,
|
|
130
|
+
): ReadonlyPureSelectorToken<T, any, E>
|
|
127
131
|
export function selector(
|
|
128
132
|
options:
|
|
129
133
|
| ReadonlyHeldSelectorOptions<any>
|
|
130
|
-
| ReadonlyPureSelectorOptions<any>
|
|
134
|
+
| ReadonlyPureSelectorOptions<any, any>
|
|
131
135
|
| WritableHeldSelectorOptions<any>
|
|
132
|
-
| WritablePureSelectorOptions<any>,
|
|
136
|
+
| WritablePureSelectorOptions<any, any>,
|
|
133
137
|
):
|
|
134
138
|
| ReadonlyHeldSelectorToken<any>
|
|
135
|
-
| ReadonlyPureSelectorToken<any>
|
|
139
|
+
| ReadonlyPureSelectorToken<any, any, any>
|
|
136
140
|
| WritableHeldSelectorToken<any>
|
|
137
|
-
| WritablePureSelectorToken<any> {
|
|
141
|
+
| WritablePureSelectorToken<any, any, any> {
|
|
138
142
|
return createStandaloneSelector(IMPLICIT.STORE, options)
|
|
139
143
|
}
|
|
140
144
|
|
|
141
|
-
export type WritablePureSelectorFamilyOptions<
|
|
145
|
+
export type WritablePureSelectorFamilyOptions<
|
|
146
|
+
T,
|
|
147
|
+
K extends Canonical,
|
|
148
|
+
E = never,
|
|
149
|
+
> = {
|
|
142
150
|
/** The unique identifier of the family */
|
|
143
151
|
key: string
|
|
144
152
|
/** For each instantiated family member, a function that computes its value */
|
|
145
153
|
get: (key: K) => Read<() => T>
|
|
146
154
|
/** For each instantiated family member, a function that sets its value */
|
|
147
155
|
set: (key: K) => Write<(newValue: T) => void>
|
|
156
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
157
|
+
catch?: readonly (new () => E)[]
|
|
148
158
|
}
|
|
149
|
-
export type ReadonlyPureSelectorFamilyOptions<
|
|
159
|
+
export type ReadonlyPureSelectorFamilyOptions<
|
|
160
|
+
T,
|
|
161
|
+
K extends Canonical,
|
|
162
|
+
E = never,
|
|
163
|
+
> = {
|
|
150
164
|
/** The unique identifier of the family */
|
|
151
165
|
key: string
|
|
152
166
|
/** For each instantiated family member, a function that computes its value */
|
|
153
167
|
get: (key: K) => Read<() => T>
|
|
168
|
+
/** The classes of errors that might be thrown when deriving the atom's default value */
|
|
169
|
+
catch?: readonly (new () => E)[]
|
|
154
170
|
}
|
|
155
171
|
export type WritableHeldSelectorFamilyOptions<
|
|
156
172
|
T extends object,
|
|
@@ -234,9 +250,9 @@ export function selectorFamily<T extends object, K extends Canonical>(
|
|
|
234
250
|
* A reference to the selector family created: a {@link TransientWritableSelectorFamilyToken}
|
|
235
251
|
* @overload WritablePure
|
|
236
252
|
*/
|
|
237
|
-
export function selectorFamily<T, K extends Canonical>(
|
|
238
|
-
options: WritablePureSelectorFamilyOptions<T, K>,
|
|
239
|
-
): WritablePureSelectorFamilyToken<T, K>
|
|
253
|
+
export function selectorFamily<T, K extends Canonical, E = never>(
|
|
254
|
+
options: WritablePureSelectorFamilyOptions<T, K, E>,
|
|
255
|
+
): WritablePureSelectorFamilyToken<T, K, E>
|
|
240
256
|
/**
|
|
241
257
|
* Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
|
|
242
258
|
*
|
|
@@ -252,19 +268,19 @@ export function selectorFamily<T, K extends Canonical>(
|
|
|
252
268
|
* A reference to the selector family created: a {@link ReadonlyPureSelectorFamilyToken}
|
|
253
269
|
* @overload ReadonlyPure
|
|
254
270
|
*/
|
|
255
|
-
export function selectorFamily<T, K extends Canonical>(
|
|
256
|
-
options: ReadonlyPureSelectorFamilyOptions<T, K>,
|
|
257
|
-
): ReadonlyPureSelectorFamilyToken<T, K>
|
|
271
|
+
export function selectorFamily<T, K extends Canonical, E = never>(
|
|
272
|
+
options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
|
|
273
|
+
): ReadonlyPureSelectorFamilyToken<T, K, E>
|
|
258
274
|
export function selectorFamily(
|
|
259
275
|
options:
|
|
260
276
|
| ReadonlyHeldSelectorFamilyOptions<any, any>
|
|
261
|
-
| ReadonlyPureSelectorFamilyOptions<any, any>
|
|
277
|
+
| ReadonlyPureSelectorFamilyOptions<any, any, any>
|
|
262
278
|
| WritableHeldSelectorFamilyOptions<any, any>
|
|
263
|
-
| WritablePureSelectorFamilyOptions<any, any>,
|
|
279
|
+
| WritablePureSelectorFamilyOptions<any, any, any>,
|
|
264
280
|
):
|
|
265
281
|
| ReadonlyHeldSelectorFamilyToken<any, any>
|
|
266
|
-
| ReadonlyPureSelectorFamilyToken<any, any>
|
|
282
|
+
| ReadonlyPureSelectorFamilyToken<any, any, any>
|
|
267
283
|
| WritableHeldSelectorFamilyToken<any, any>
|
|
268
|
-
| WritablePureSelectorFamilyToken<any, any> {
|
|
284
|
+
| WritablePureSelectorFamilyToken<any, any, any> {
|
|
269
285
|
return createSelectorFamily(IMPLICIT.STORE, options)
|
|
270
286
|
}
|
package/src/main/set-state.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type Setter<T, New extends T> = (oldValue: T) => New
|
|
|
19
19
|
* @default
|
|
20
20
|
*/
|
|
21
21
|
export function setState<T, New extends T>(
|
|
22
|
-
token: WritableToken<T>,
|
|
22
|
+
token: WritableToken<T, any, any>,
|
|
23
23
|
value: New | Setter<T, New>,
|
|
24
24
|
): void
|
|
25
25
|
|
|
@@ -31,22 +31,19 @@ export function setState<T, New extends T>(
|
|
|
31
31
|
* @overload Streamlined
|
|
32
32
|
*/
|
|
33
33
|
export function setState<T, K extends Canonical, New extends T, Key extends K>(
|
|
34
|
-
token: WritableFamilyToken<T, K>,
|
|
34
|
+
token: WritableFamilyToken<T, K, any>,
|
|
35
35
|
key: Key,
|
|
36
36
|
value: New | Setter<T, New>,
|
|
37
37
|
): void
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
export function setState<T, K extends Canonical, New extends T, Key extends K>(
|
|
39
40
|
...params:
|
|
40
41
|
| [
|
|
41
|
-
token: WritableFamilyToken<T,
|
|
42
|
-
key:
|
|
42
|
+
token: WritableFamilyToken<T, K, any>,
|
|
43
|
+
key: Key,
|
|
43
44
|
value: New | Setter<T, New>,
|
|
44
45
|
]
|
|
45
|
-
| [token: WritableToken<T>, value: New | Setter<T, New>]
|
|
46
|
+
| [token: WritableToken<T, any, any>, value: New | Setter<T, New>]
|
|
46
47
|
): void {
|
|
47
|
-
|
|
48
|
-
setIntoStore(IMPLICIT.STORE, ...params)
|
|
49
|
-
} else {
|
|
50
|
-
setIntoStore(IMPLICIT.STORE, ...params)
|
|
51
|
-
}
|
|
48
|
+
setIntoStore(IMPLICIT.STORE, ...params)
|
|
52
49
|
}
|