atom.io 0.37.1 → 0.38.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/dist/internal/index.d.ts +22 -24
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +193 -138
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +1 -1
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +6 -3
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +22 -2
- package/dist/main/index.js.map +1 -1
- package/package.json +1 -1
- package/src/internal/atom/dispose-atom.ts +1 -2
- package/src/internal/families/create-readonly-held-selector-family.ts +2 -4
- package/src/internal/families/create-readonly-pure-selector-family.ts +2 -4
- package/src/internal/families/create-regular-atom-family.ts +3 -4
- package/src/internal/families/create-writable-held-selector-family.ts +3 -4
- package/src/internal/families/create-writable-pure-selector-family.ts +2 -4
- package/src/internal/families/find-in-store.ts +7 -1
- package/src/internal/families/get-family-of-token.ts +21 -24
- package/src/internal/families/mint-in-store.ts +59 -35
- package/src/internal/get-state/get-fallback.ts +57 -0
- package/src/internal/get-state/get-from-store.ts +11 -61
- package/src/internal/get-state/reduce-reference.ts +66 -0
- package/src/internal/index.ts +0 -1
- package/src/internal/ingest-updates/ingest-creation-disposal.ts +4 -3
- package/src/internal/molecule.ts +5 -5
- package/src/internal/mutable/create-mutable-atom-family.ts +3 -8
- package/src/internal/mutable/get-json-token.ts +2 -1
- package/src/internal/not-found-error.ts +2 -3
- package/src/internal/operation.ts +1 -1
- package/src/internal/selector/register-selector.ts +17 -24
- package/src/internal/selector/update-selector-atoms.ts +2 -2
- package/src/internal/set-state/operate-on-store.ts +17 -13
- package/src/internal/set-state/set-into-store.ts +2 -2
- package/src/internal/store/index.ts +1 -1
- package/src/internal/store/{counterfeit.ts → mint-or-counterfeit.ts} +27 -15
- package/src/internal/subscribe/subscribe-to-state.ts +2 -0
- package/src/internal/timeline/create-timeline.ts +2 -0
- package/src/json/index.ts +3 -3
- package/src/main/logger.ts +26 -4
- package/src/internal/pretty-print.ts +0 -7
|
@@ -2,7 +2,7 @@ import type { WritableFamilyToken, WritableToken } from "atom.io"
|
|
|
2
2
|
import type { Canonical } from "atom.io/json"
|
|
3
3
|
|
|
4
4
|
import type { Store } from "../store"
|
|
5
|
-
import { operateOnStore } from "./operate-on-store"
|
|
5
|
+
import { operateOnStore, OWN_OP } from "./operate-on-store"
|
|
6
6
|
import type { RESET_STATE } from "./reset-in-store"
|
|
7
7
|
|
|
8
8
|
export function setIntoStore<T, New extends T>(
|
|
@@ -36,5 +36,5 @@ export function setIntoStore<T, New extends T>(
|
|
|
36
36
|
value: New | typeof RESET_STATE | ((oldValue: T) => New),
|
|
37
37
|
]
|
|
38
38
|
): void {
|
|
39
|
-
operateOnStore(store,
|
|
39
|
+
operateOnStore(store, OWN_OP, ...params)
|
|
40
40
|
}
|
|
@@ -21,6 +21,8 @@ import { stringifyJson } from "atom.io/json"
|
|
|
21
21
|
|
|
22
22
|
import type { Transceiver } from "../mutable"
|
|
23
23
|
|
|
24
|
+
export const COUNTERFEIT: unique symbol = Symbol(`counterfeit`)
|
|
25
|
+
|
|
24
26
|
export const FAMILY_MEMBER_TOKEN_TYPES = {
|
|
25
27
|
atom_family: `atom`,
|
|
26
28
|
molecule_family: `molecule`,
|
|
@@ -31,66 +33,76 @@ export const FAMILY_MEMBER_TOKEN_TYPES = {
|
|
|
31
33
|
writable_pure_selector_family: `writable_pure_selector`,
|
|
32
34
|
} as const
|
|
33
35
|
|
|
34
|
-
export function
|
|
36
|
+
export function mint<
|
|
35
37
|
T extends Transceiver<any, any, any>,
|
|
36
38
|
K extends Canonical,
|
|
37
39
|
Key extends K,
|
|
38
40
|
>(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>
|
|
39
41
|
|
|
40
|
-
export function
|
|
42
|
+
export function mint<T, K extends Canonical, Key extends K>(
|
|
41
43
|
token: RegularAtomFamilyToken<T, K>,
|
|
42
44
|
key: Key,
|
|
45
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
43
46
|
): RegularAtomToken<T>
|
|
44
47
|
|
|
45
|
-
export function
|
|
48
|
+
export function mint<T, K extends Canonical, Key extends K>(
|
|
46
49
|
token: AtomFamilyToken<T, K>,
|
|
47
50
|
key: Key,
|
|
51
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
48
52
|
): AtomToken<T>
|
|
49
53
|
|
|
50
|
-
export function
|
|
54
|
+
export function mint<T, K extends Canonical, Key extends K>(
|
|
51
55
|
token: WritablePureSelectorFamilyToken<T, K>,
|
|
52
56
|
key: Key,
|
|
57
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
53
58
|
): WritablePureSelectorToken<T>
|
|
54
59
|
|
|
55
|
-
export function
|
|
60
|
+
export function mint<T, K extends Canonical, Key extends K>(
|
|
56
61
|
token: ReadonlyPureSelectorFamilyToken<T, K>,
|
|
57
62
|
key: Key,
|
|
63
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
58
64
|
): ReadonlyPureSelectorToken<T>
|
|
59
65
|
|
|
60
|
-
export function
|
|
66
|
+
export function mint<T, K extends Canonical, Key extends K>(
|
|
61
67
|
token: SelectorFamilyToken<T, K>,
|
|
62
68
|
key: Key,
|
|
69
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
63
70
|
): SelectorToken<T>
|
|
64
71
|
|
|
65
|
-
export function
|
|
72
|
+
export function mint<T, K extends Canonical, Key extends K>(
|
|
66
73
|
token: WritableFamilyToken<T, K>,
|
|
67
74
|
key: Key,
|
|
75
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
68
76
|
): WritableToken<T>
|
|
69
77
|
|
|
70
|
-
export function
|
|
78
|
+
export function mint<T, K extends Canonical, Key extends K>(
|
|
71
79
|
token: ReadableFamilyToken<T, K>,
|
|
72
80
|
key: Key,
|
|
81
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
73
82
|
): ReadableToken<T>
|
|
74
83
|
|
|
75
|
-
export function
|
|
84
|
+
export function mint(
|
|
76
85
|
token: ReadableFamilyToken<any, any>,
|
|
77
86
|
key: Canonical,
|
|
87
|
+
counterfeit?: typeof COUNTERFEIT,
|
|
78
88
|
): ReadableToken<any> {
|
|
79
89
|
const subKey = stringifyJson(key)
|
|
80
90
|
const fullKey = `${token.key}(${subKey})`
|
|
81
91
|
const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
|
|
82
|
-
const stateToken
|
|
92
|
+
const stateToken: ReadableToken<any> & {
|
|
93
|
+
counterfeit?: boolean
|
|
94
|
+
} = {
|
|
83
95
|
key: fullKey,
|
|
84
96
|
type,
|
|
85
|
-
} satisfies ReadableToken<any>
|
|
86
|
-
|
|
87
|
-
Object.assign(stateToken, {
|
|
88
97
|
family: {
|
|
89
98
|
key: token.key,
|
|
90
99
|
subKey,
|
|
91
100
|
},
|
|
92
|
-
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (counterfeit) {
|
|
104
|
+
stateToken.counterfeit = true
|
|
105
|
+
}
|
|
93
106
|
|
|
94
|
-
Object.assign(stateToken, { counterfeit: true })
|
|
95
107
|
return stateToken
|
|
96
108
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReadableToken, StateUpdate, UpdateHandler } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import { readOrComputeValue } from "../get-state"
|
|
4
|
+
import { reduceReference } from "../get-state/reduce-reference"
|
|
4
5
|
import { traceRootSelectorAtoms } from "../selector"
|
|
5
6
|
import type { Store } from "../store"
|
|
6
7
|
import { withdraw } from "../store"
|
|
@@ -25,6 +26,7 @@ export function subscribeToState<T>(
|
|
|
25
26
|
handleUpdate(update)
|
|
26
27
|
}
|
|
27
28
|
}
|
|
29
|
+
reduceReference(store, token)
|
|
28
30
|
const state = withdraw(store, token)
|
|
29
31
|
store.logger.info(`👀`, state.type, state.key, `Adding subscription "${key}"`)
|
|
30
32
|
const isSelector =
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
TransactionToken,
|
|
14
14
|
} from "atom.io"
|
|
15
15
|
|
|
16
|
+
import { reduceReference } from "../get-state/reduce-reference"
|
|
16
17
|
import { newest } from "../lineage"
|
|
17
18
|
import { getUpdateToken } from "../mutable"
|
|
18
19
|
import { deposit, type Store, withdraw } from "../store"
|
|
@@ -130,6 +131,7 @@ function addAtomToTimeline(
|
|
|
130
131
|
atomToken: AtomToken<any>,
|
|
131
132
|
tl: Timeline<any>,
|
|
132
133
|
): void {
|
|
134
|
+
reduceReference(store, atomToken)
|
|
133
135
|
let maybeAtom = withdraw(store, atomToken)
|
|
134
136
|
if (maybeAtom.type === `mutable_atom`) {
|
|
135
137
|
const updateToken = getUpdateToken(maybeAtom)
|
package/src/json/index.ts
CHANGED
|
@@ -66,9 +66,9 @@ export type stringified<J extends Json.Serializable> = (
|
|
|
66
66
|
)
|
|
67
67
|
|
|
68
68
|
/** Type-safe wrapper for {@link JSON.parse} */
|
|
69
|
-
export const parseJson = <
|
|
70
|
-
str:
|
|
71
|
-
):
|
|
69
|
+
export const parseJson = <J extends Json.Serializable>(
|
|
70
|
+
str: stringified<J> | string,
|
|
71
|
+
): J => JSON.parse(str)
|
|
72
72
|
|
|
73
73
|
/** Type-safe wrapper for {@link JSON.stringify} */
|
|
74
74
|
export const stringifyJson = <J extends Json.Serializable>(
|
package/src/main/logger.ts
CHANGED
|
@@ -8,10 +8,12 @@ const LOGGER_ICON_DICTIONARY = {
|
|
|
8
8
|
"⏹️": `Time-travel complete`,
|
|
9
9
|
"✅": `Realtime transaction success`,
|
|
10
10
|
"✨": `Computation complete`,
|
|
11
|
+
"💣": `Dangerous action likely to cause bad errors`,
|
|
12
|
+
"❗": `Dangerous action unless in development mode`,
|
|
11
13
|
"❌": `Conflict prevents attempted action`,
|
|
12
14
|
"⭕": `Operation start`,
|
|
13
15
|
"🔴": `Operation complete`,
|
|
14
|
-
"
|
|
16
|
+
"🚫": `Operation blocked`,
|
|
15
17
|
"🟢": `Operation unblocked`,
|
|
16
18
|
"🐞": `Possible bug in AtomIO`,
|
|
17
19
|
"👀": `Subscription added`,
|
|
@@ -55,8 +57,7 @@ export type TokenDenomination =
|
|
|
55
57
|
| `atom_family`
|
|
56
58
|
| `atom`
|
|
57
59
|
| `continuity`
|
|
58
|
-
| `
|
|
59
|
-
| `molecule`
|
|
60
|
+
| `key`
|
|
60
61
|
| `mutable_atom_family`
|
|
61
62
|
| `mutable_atom`
|
|
62
63
|
| `readonly_held_selector_family`
|
|
@@ -72,6 +73,27 @@ export type TokenDenomination =
|
|
|
72
73
|
| `writable_pure_selector_family`
|
|
73
74
|
| `writable_pure_selector`
|
|
74
75
|
|
|
76
|
+
export const PRETTY_TOKEN_TYPES: Record<TokenDenomination, string> = {
|
|
77
|
+
atom_family: `atom family`,
|
|
78
|
+
atom: `atom`,
|
|
79
|
+
continuity: `continuity`,
|
|
80
|
+
key: `key`,
|
|
81
|
+
mutable_atom_family: `atom family [m]`,
|
|
82
|
+
mutable_atom: `atom [m]`,
|
|
83
|
+
readonly_held_selector_family: `selector family [h]`,
|
|
84
|
+
readonly_held_selector: `selector [h]`,
|
|
85
|
+
readonly_pure_selector_family: `selector family`,
|
|
86
|
+
readonly_pure_selector: `selector`,
|
|
87
|
+
state: `state`,
|
|
88
|
+
timeline: `timeline`,
|
|
89
|
+
transaction: `transaction`,
|
|
90
|
+
unknown: `unknown`,
|
|
91
|
+
writable_held_selector_family: `selector family [wh]`,
|
|
92
|
+
writable_held_selector: `selector [wh]`,
|
|
93
|
+
writable_pure_selector_family: `selector family [w]`,
|
|
94
|
+
writable_pure_selector: `selector [w]`,
|
|
95
|
+
}
|
|
96
|
+
|
|
75
97
|
export const LOG_LEVELS = [`info`, `warn`, `error`] as const
|
|
76
98
|
export type LogLevel = (typeof LOG_LEVELS)[number]
|
|
77
99
|
|
|
@@ -93,7 +115,7 @@ export const simpleLog =
|
|
|
93
115
|
(icon, denomination, tokenKey, message, ...rest) => {
|
|
94
116
|
/* eslint-disable-next-line no-console */
|
|
95
117
|
console[logLevel](
|
|
96
|
-
`${icon} ${denomination}
|
|
118
|
+
`${icon} ${PRETTY_TOKEN_TYPES[denomination]} \`${tokenKey}\` ${message}`,
|
|
97
119
|
...rest,
|
|
98
120
|
)
|
|
99
121
|
}
|