atom.io 0.7.0 → 0.8.1
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/index.d.mts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +67 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -38
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +42 -26
- package/internal/dist/index.d.ts +42 -26
- package/internal/dist/index.js +85 -76
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +74 -47
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/atom/create-atom.ts +1 -1
- package/internal/src/caching.ts +25 -1
- package/internal/src/future.ts +37 -0
- package/internal/src/index.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +4 -4
- package/internal/src/mutable/create-mutable-atom.ts +6 -5
- package/internal/src/mutable/is-atom-token-mutable.ts +3 -3
- package/internal/src/mutable/tracker-family.ts +4 -4
- package/internal/src/mutable/tracker.ts +20 -19
- package/internal/src/operation.ts +5 -2
- package/internal/src/selector/create-read-write-selector.ts +4 -4
- package/internal/src/selector/create-readonly-selector.ts +1 -1
- package/internal/src/selector/register-selector.ts +2 -2
- package/internal/src/set-state/{set-atom-state.ts → set-atom.ts} +2 -2
- package/internal/src/set-state/set-selector-state.ts +1 -12
- package/internal/src/set-state/set-state-internal.ts +4 -5
- package/internal/src/store/withdraw-new-family-member.ts +7 -7
- package/internal/src/store/withdraw.ts +15 -9
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +1 -1
- package/internal/src/transaction/redo-transaction.ts +1 -1
- package/internal/src/transaction/undo-transaction.ts +1 -1
- package/package.json +9 -9
- package/react-devtools/dist/index.d.mts +4 -4
- package/react-devtools/dist/index.d.ts +4 -4
- package/react-devtools/dist/index.js +19 -5
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +15 -1
- package/react-devtools/dist/index.mjs.map +1 -1
- package/react-devtools/src/index.ts +1 -1
- package/src/get-set.ts +48 -0
- package/src/index.ts +4 -67
- package/src/subscribe.ts +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { atom, atomFamily } from "atom.io"
|
|
2
2
|
import { attachIntrospectionStates } from "atom.io/introspection"
|
|
3
|
-
import { lazyLocalStorageEffect } from "atom.io/web-effects"
|
|
3
|
+
import { lazyLocalStorageEffect } from "~/packages/atom.io/__unstable__/web-effects/src"
|
|
4
4
|
|
|
5
5
|
import { isPlainObject } from "~/packages/anvl/src/object"
|
|
6
6
|
import { Refinery } from "~/packages/anvl/src/refinement/refinery"
|
package/src/get-set.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as Internal from "atom.io/internal"
|
|
2
|
+
import type { ReadonlySelectorToken, StateToken } from "."
|
|
3
|
+
|
|
4
|
+
export const getState = <T>(
|
|
5
|
+
token: ReadonlySelectorToken<T> | StateToken<T>,
|
|
6
|
+
store: Internal.Store = Internal.IMPLICIT.STORE,
|
|
7
|
+
): T => {
|
|
8
|
+
const state =
|
|
9
|
+
Internal.withdraw(token, store) ??
|
|
10
|
+
Internal.withdrawNewFamilyMember(token, store)
|
|
11
|
+
if (state === undefined) {
|
|
12
|
+
throw new NotFoundError(token, store)
|
|
13
|
+
}
|
|
14
|
+
return Internal.getState__INTERNAL(state, store)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const setState = <T, New extends T>(
|
|
18
|
+
token: StateToken<T>,
|
|
19
|
+
value: New | ((oldValue: T) => New),
|
|
20
|
+
store: Internal.Store = Internal.IMPLICIT.STORE,
|
|
21
|
+
): void => {
|
|
22
|
+
const rejection = Internal.openOperation(token, store)
|
|
23
|
+
if (rejection) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
const state =
|
|
27
|
+
Internal.withdraw(token, store) ??
|
|
28
|
+
Internal.withdrawNewFamilyMember(token, store)
|
|
29
|
+
if (state === undefined) {
|
|
30
|
+
throw new NotFoundError(token, store)
|
|
31
|
+
}
|
|
32
|
+
Internal.setState__INTERNAL(state, value, store)
|
|
33
|
+
Internal.closeOperation(store)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
|
|
37
|
+
export class NotFoundError extends Error {
|
|
38
|
+
public constructor(
|
|
39
|
+
token: ReadonlySelectorToken<any> | StateToken<any>,
|
|
40
|
+
store: Internal.Store,
|
|
41
|
+
) {
|
|
42
|
+
super(
|
|
43
|
+
`${capitalize(token.type)} "${token.key}" not found in store "${
|
|
44
|
+
store.config.name
|
|
45
|
+
}".`,
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Store, Transceiver } from "atom.io/internal"
|
|
1
|
+
import type { Transceiver } from "atom.io/internal"
|
|
3
2
|
import type { Json } from "atom.io/json"
|
|
4
3
|
|
|
5
4
|
export * from "./atom"
|
|
5
|
+
export * from "./get-set"
|
|
6
6
|
export * from "./logger"
|
|
7
7
|
export * from "./selector"
|
|
8
8
|
export * from "./silo"
|
|
9
|
-
export
|
|
10
|
-
subscribe,
|
|
11
|
-
subscribeToTimeline,
|
|
12
|
-
subscribeToTransaction,
|
|
13
|
-
KeyedStateUpdate,
|
|
14
|
-
StateUpdate,
|
|
15
|
-
UpdateHandler,
|
|
16
|
-
} from "./subscribe"
|
|
9
|
+
export * from "./subscribe"
|
|
17
10
|
export * from "./timeline"
|
|
18
11
|
export * from "./transaction"
|
|
19
12
|
|
|
@@ -47,60 +40,4 @@ export type ReadonlySelectorToken<_> = {
|
|
|
47
40
|
__brand?: _
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
export type FamilyMetadata = {
|
|
51
|
-
key: string
|
|
52
|
-
subKey: string
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const capitalize = (str: string): string =>
|
|
56
|
-
str[0].toUpperCase() + str.slice(1)
|
|
57
|
-
|
|
58
|
-
export const getState = <T>(
|
|
59
|
-
token: ReadonlySelectorToken<T> | StateToken<T>,
|
|
60
|
-
store: Store = IO.IMPLICIT.STORE,
|
|
61
|
-
): T => {
|
|
62
|
-
const state =
|
|
63
|
-
IO.withdraw(token, store) ?? IO.withdrawNewFamilyMember(token, store)
|
|
64
|
-
if (state === null) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`${capitalize(token.type)} "${token.key}" not found in store "${
|
|
67
|
-
store.config.name
|
|
68
|
-
}".`,
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
return IO.getState__INTERNAL(state, store)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const setState = <T, New extends T>(
|
|
75
|
-
token: StateToken<T>,
|
|
76
|
-
value: New | ((oldValue: T) => New),
|
|
77
|
-
store: Store = IO.IMPLICIT.STORE,
|
|
78
|
-
): void => {
|
|
79
|
-
try {
|
|
80
|
-
IO.openOperation(token, store)
|
|
81
|
-
} catch (thrown) {
|
|
82
|
-
if (!(typeof thrown === `symbol`)) {
|
|
83
|
-
throw thrown
|
|
84
|
-
}
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
const state =
|
|
88
|
-
IO.withdraw(token, store) ?? IO.withdrawNewFamilyMember(token, store)
|
|
89
|
-
if (state === null) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
`${capitalize(token.type)} "${token.key}" not found in store "${
|
|
92
|
-
store.config.name
|
|
93
|
-
}".`,
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
IO.setState__INTERNAL(state, value, store)
|
|
97
|
-
IO.closeOperation(store)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export const isDefault = (
|
|
101
|
-
token: ReadonlySelectorToken<unknown> | StateToken<unknown>,
|
|
102
|
-
store: Store = IO.IMPLICIT.STORE,
|
|
103
|
-
): boolean =>
|
|
104
|
-
token.type === `atom`
|
|
105
|
-
? IO.isAtomDefault(token.key, store)
|
|
106
|
-
: IO.isSelectorDefault(token.key, store)
|
|
43
|
+
export type FamilyMetadata = { key: string; subKey: string }
|
package/src/subscribe.ts
CHANGED
|
@@ -26,7 +26,7 @@ export function subscribe<T>(
|
|
|
26
26
|
store: Store = IMPLICIT.STORE,
|
|
27
27
|
): () => void {
|
|
28
28
|
const state = withdraw<T>(token, store)
|
|
29
|
-
if (state ===
|
|
29
|
+
if (state === undefined) {
|
|
30
30
|
throw new Error(
|
|
31
31
|
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
32
32
|
)
|
|
@@ -66,7 +66,7 @@ export const subscribeToTransaction = <ƒ extends ƒn>(
|
|
|
66
66
|
store = IMPLICIT.STORE,
|
|
67
67
|
): (() => void) => {
|
|
68
68
|
const tx = withdraw(token, store)
|
|
69
|
-
if (tx ===
|
|
69
|
+
if (tx === undefined) {
|
|
70
70
|
throw new Error(
|
|
71
71
|
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`,
|
|
72
72
|
)
|
|
@@ -86,7 +86,7 @@ export const subscribeToTimeline = (
|
|
|
86
86
|
store = IMPLICIT.STORE,
|
|
87
87
|
): (() => void) => {
|
|
88
88
|
const tl = withdraw(token, store)
|
|
89
|
-
if (tl ===
|
|
89
|
+
if (tl === undefined) {
|
|
90
90
|
throw new Error(
|
|
91
91
|
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`,
|
|
92
92
|
)
|