atom.io 0.38.2 → 0.39.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/data/index.js.map +1 -1
- package/dist/eslint-plugin/index.js +2 -1
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +128 -85
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +429 -286
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js.map +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 +45 -35
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +43 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js +4 -5
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.js +5 -5
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +4 -4
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.d.ts.map +1 -1
- package/dist/realtime-testing/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/package.json +10 -11
- package/src/internal/atom/create-regular-atom.ts +2 -6
- package/src/internal/caching.ts +2 -4
- package/src/internal/{ingest-updates → events}/ingest-atom-update.ts +4 -5
- package/src/internal/{ingest-updates → events}/ingest-creation-disposal.ts +37 -37
- package/src/internal/{ingest-updates → events}/ingest-selector-update.ts +5 -5
- package/src/internal/events/ingest-transaction-update.ts +45 -0
- package/src/internal/families/create-readonly-held-selector-family.ts +1 -1
- package/src/internal/families/create-readonly-pure-selector-family.ts +1 -1
- package/src/internal/families/create-regular-atom-family.ts +4 -3
- package/src/internal/families/create-writable-held-selector-family.ts +1 -1
- package/src/internal/families/create-writable-pure-selector-family.ts +1 -1
- package/src/internal/families/find-in-store.ts +2 -2
- package/src/internal/families/get-family-of-token.ts +1 -0
- package/src/internal/families/index.ts +0 -1
- package/src/internal/families/mint-in-store.ts +30 -64
- package/src/internal/get-state/get-from-store.ts +2 -3
- package/src/internal/get-state/read-or-compute-value.ts +6 -15
- package/src/internal/get-state/reduce-reference.ts +52 -11
- package/src/internal/index.ts +2 -2
- package/src/internal/is-fn.ts +9 -0
- package/src/internal/junction.ts +177 -133
- package/src/internal/mutable/create-mutable-atom-family.ts +1 -1
- package/src/internal/overlays/index.ts +3 -0
- package/src/internal/overlays/map-overlay.ts +86 -0
- package/src/internal/{lazy-map.ts → overlays/relations-overlay.ts} +6 -6
- package/src/internal/overlays/set-overlay.ts +55 -0
- package/src/internal/selector/create-readonly-held-selector.ts +8 -11
- package/src/internal/selector/create-readonly-pure-selector.ts +8 -10
- package/src/internal/selector/create-writable-held-selector.ts +6 -6
- package/src/internal/selector/create-writable-pure-selector.ts +2 -2
- package/src/internal/selector/register-selector.ts +3 -4
- package/src/internal/set-state/become.ts +11 -6
- package/src/internal/set-state/dispatch-state-update.ts +47 -12
- package/src/internal/set-state/operate-on-store.ts +10 -8
- package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
- package/src/internal/set-state/set-atom-or-selector.ts +3 -2
- package/src/internal/set-state/set-atom.ts +5 -4
- package/src/internal/set-state/set-selector.ts +9 -8
- package/src/internal/store/withdraw.ts +4 -4
- package/src/internal/timeline/time-travel.ts +11 -11
- package/src/internal/transaction/apply-transaction.ts +5 -5
- package/src/internal/transaction/build-transaction.ts +17 -26
- package/src/internal/transaction/create-transaction.ts +1 -1
- package/src/internal/transaction/is-root-store.ts +2 -2
- package/src/main/events.ts +14 -3
- package/src/main/logger.ts +43 -32
- package/src/react-devtools/json-editor/editors-by-type/array-editor.tsx +1 -1
- package/src/react-devtools/json-editor/editors-by-type/object-editor.tsx +2 -3
- package/src/react-devtools/json-editor/editors-by-type/utilities/array-elements.ts +1 -1
- package/src/react-devtools/json-editor/editors-by-type/utilities/object-properties.ts +1 -1
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +5 -5
- package/src/realtime-server/continuity/subscribe-to-continuity-perpectives.ts +4 -4
- package/dist/use-o-DXPncKmZ.js +0 -47
- package/dist/use-o-DXPncKmZ.js.map +0 -1
- package/src/internal/families/init-family-member.ts +0 -33
- package/src/internal/ingest-updates/ingest-transaction-update.ts +0 -47
- /package/src/internal/{ingest-updates → events}/index.ts +0 -0
|
@@ -37,7 +37,7 @@ export function createTransaction<F extends Fn>(
|
|
|
37
37
|
const target = newest(store)
|
|
38
38
|
const { toolkit } = childStore.transactionMeta
|
|
39
39
|
const output = options.do(toolkit, ...params)
|
|
40
|
-
applyTransaction(
|
|
40
|
+
applyTransaction<F>(target, output)
|
|
41
41
|
return output
|
|
42
42
|
} catch (thrown) {
|
|
43
43
|
abortTransaction(target)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MapOverlay } from "../overlays/map-overlay"
|
|
2
2
|
import type { Store } from "../store"
|
|
3
3
|
import type { Fn } from "../utility-types"
|
|
4
4
|
import type { TransactionEpoch, TransactionProgress } from "."
|
|
@@ -12,7 +12,7 @@ export interface ChildStore extends Store {
|
|
|
12
12
|
transactionMeta: TransactionProgress<Fn>
|
|
13
13
|
parent: ChildStore | RootStore
|
|
14
14
|
child: ChildStore | null
|
|
15
|
-
valueMap:
|
|
15
|
+
valueMap: MapOverlay<string, any>
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function isRootStore(store: Store): store is RootStore {
|
package/src/main/events.ts
CHANGED
|
@@ -7,11 +7,12 @@ import type {
|
|
|
7
7
|
ReadableToken,
|
|
8
8
|
SelectorToken,
|
|
9
9
|
TransactionToken,
|
|
10
|
+
WritableToken,
|
|
10
11
|
} from "./tokens"
|
|
11
12
|
import type { TokenType } from "./validators"
|
|
12
13
|
|
|
13
14
|
export type StateUpdate<T> = {
|
|
14
|
-
readonly oldValue
|
|
15
|
+
readonly oldValue?: ViewOf<T>
|
|
15
16
|
readonly newValue: ViewOf<T>
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -32,15 +33,25 @@ export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
|
|
|
32
33
|
export type StateLifecycleEvent<R extends ReadableToken<any>> =
|
|
33
34
|
| StateCreationEvent<R>
|
|
34
35
|
| StateDisposalEvent<R>
|
|
35
|
-
export type StateCreationEvent<R extends ReadableToken<any>> =
|
|
36
|
+
export type StateCreationEvent<R extends ReadableToken<any>> =
|
|
37
|
+
| ReadableStateCreationEvent<R>
|
|
38
|
+
| (R extends WritableToken<any> ? WritableStateCreationEvent<R> : never)
|
|
39
|
+
export type ReadableStateCreationEvent<R extends ReadableToken<any>> = {
|
|
36
40
|
type: `state_creation`
|
|
41
|
+
subType: `readable`
|
|
37
42
|
token: R
|
|
38
43
|
timestamp: number
|
|
39
44
|
}
|
|
45
|
+
export type WritableStateCreationEvent<W extends WritableToken<any>> = {
|
|
46
|
+
type: `state_creation`
|
|
47
|
+
subType: `writable`
|
|
48
|
+
token: W
|
|
49
|
+
timestamp: number
|
|
50
|
+
value?: TokenType<W>
|
|
51
|
+
}
|
|
40
52
|
export type StateDisposalEvent<R extends ReadableToken<any>> =
|
|
41
53
|
| AtomDisposalEvent<R>
|
|
42
54
|
| SelectorDisposalEvent<R>
|
|
43
|
-
|
|
44
55
|
export type AtomDisposalEvent<R extends ReadableToken<any>> = {
|
|
45
56
|
type: `state_disposal`
|
|
46
57
|
subType: `atom`
|
package/src/main/logger.ts
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
const LOGGER_ICON_DICTIONARY = {
|
|
2
|
+
// Lifecycle
|
|
3
|
+
"🔨": `Create state`,
|
|
4
|
+
"🛠️": `Install state into store`,
|
|
5
|
+
// Families
|
|
6
|
+
"👪": `Family member added`,
|
|
7
|
+
"🔥": `Family member deleted`,
|
|
8
|
+
// Cache
|
|
9
|
+
"📃": `Copy mutable`,
|
|
10
|
+
"📖": `Read from cache`,
|
|
11
|
+
"📝": `Write to cache`,
|
|
12
|
+
"❔": `Cache miss`,
|
|
13
|
+
"✨": `Value derived`,
|
|
14
|
+
"⭐": `Value set`,
|
|
15
|
+
// Operations
|
|
16
|
+
"⭕": `Operation start`,
|
|
17
|
+
"🔴": `Operation complete`,
|
|
18
|
+
"🚫": `Operation blocked`,
|
|
19
|
+
"🟢": `Operation unblocked`,
|
|
20
|
+
// Selectors
|
|
21
|
+
"🗑": `Evict cached value`,
|
|
22
|
+
"🧹": `Prepare to evict`,
|
|
23
|
+
"🧮": `Computing selector`,
|
|
24
|
+
"🔌": `Register direct dependency`,
|
|
25
|
+
"🔍": `Discover root`,
|
|
26
|
+
// Transactions
|
|
27
|
+
"📁": `Stow update`,
|
|
28
|
+
"🛫": `Begin transaction`,
|
|
29
|
+
"🛄": `Apply transaction`,
|
|
30
|
+
"🛬": `Complete transaction`,
|
|
31
|
+
"💥": `Transaction caught error`,
|
|
32
|
+
"🪂": `Abort transaction`,
|
|
33
|
+
// Timelines
|
|
2
34
|
"⌛": `Timeline event fully captured`,
|
|
3
35
|
"⏩": `Timeline redo`,
|
|
4
36
|
"⏪": `Timeline undo`,
|
|
@@ -6,51 +38,30 @@ const LOGGER_ICON_DICTIONARY = {
|
|
|
6
38
|
"⏮️": `Transaction undo`,
|
|
7
39
|
"⏳": `Timeline event partially captured`,
|
|
8
40
|
"⏹️": `Time-travel complete`,
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"💣": `Dangerous action likely to cause bad errors`,
|
|
41
|
+
// Problems
|
|
42
|
+
"💣": `Dangerous action likely to cause bad errors down the line`,
|
|
12
43
|
"❗": `Dangerous action unless in development mode`,
|
|
13
44
|
"❌": `Conflict prevents attempted action`,
|
|
14
|
-
"⭕": `Operation start`,
|
|
15
|
-
"🔴": `Operation complete`,
|
|
16
|
-
"🚫": `Operation blocked`,
|
|
17
|
-
"🟢": `Operation unblocked`,
|
|
18
45
|
"🐞": `Possible bug in AtomIO`,
|
|
46
|
+
"💁": `Advice and guidance to the developer`,
|
|
47
|
+
// Subscriptions
|
|
19
48
|
"👀": `Subscription added`,
|
|
20
|
-
"
|
|
21
|
-
"👍": `Realtime acknowledgment`,
|
|
22
|
-
"👪": `Family member added`,
|
|
23
|
-
"💁": `Notice`,
|
|
24
|
-
"💥": `Caught`,
|
|
25
|
-
"📁": `Stow update`,
|
|
26
|
-
"📃": `Copy mutable`,
|
|
27
|
-
"📖": `Read state`,
|
|
28
|
-
"📝": `Write state`,
|
|
49
|
+
"🙈": `Subscription canceled`,
|
|
29
50
|
"📢": `Notify subscribers`,
|
|
30
|
-
"🔄": `Realtime transaction synchronized`,
|
|
31
|
-
"🔌": `Register dependency`,
|
|
32
|
-
"🔍": `Discover root`,
|
|
33
|
-
"🔥": `Delete state`,
|
|
34
|
-
"🔧": `Create mutable atom`,
|
|
35
|
-
"🔨": `Create immutable atom`,
|
|
36
51
|
|
|
37
|
-
|
|
38
|
-
"🙈": `Subscription canceled`,
|
|
52
|
+
// Realtime
|
|
39
53
|
"🚀": `Performance measure`,
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"🛫": `Begin transaction`,
|
|
43
|
-
"🛬": `Complete transaction`,
|
|
44
|
-
"🧮": `Computing selector`,
|
|
45
|
-
"🧹": `Prepare to evict`,
|
|
46
|
-
"🪂": `Abort transaction`,
|
|
54
|
+
"✅": `Realtime transaction success`,
|
|
55
|
+
"🔄": `Realtime transaction synchronized`,
|
|
47
56
|
"🤞": `Realtime optimistic update enqueued`,
|
|
48
57
|
"👈": `Realtime confirmed update enqueued`,
|
|
49
58
|
"🧑⚖️": `Realtime update beginning reconciliation`,
|
|
50
59
|
"🛎️": `Realtime transaction received`,
|
|
60
|
+
"👁": `Determining perspective`,
|
|
51
61
|
"🔭": `Determining realtime perspective`,
|
|
52
62
|
"🖌": `Redacting realtime update`,
|
|
53
|
-
"
|
|
63
|
+
"👋": `Realtime greeting`,
|
|
64
|
+
"👍": `Realtime acknowledgment`,
|
|
54
65
|
} as const
|
|
55
66
|
export type LoggerIcon = keyof typeof LOGGER_ICON_DICTIONARY
|
|
56
67
|
export type TokenDenomination =
|
|
@@ -3,9 +3,9 @@ import { findInStore } from "atom.io/internal"
|
|
|
3
3
|
import type { Json, JsonTypes } from "atom.io/json"
|
|
4
4
|
import { JSON_DEFAULTS } from "atom.io/json"
|
|
5
5
|
import { useI, useO } from "atom.io/react"
|
|
6
|
-
import { DevtoolsContext } from "atom.io/react-devtools/store"
|
|
7
6
|
import { type ReactElement, useContext } from "react"
|
|
8
7
|
|
|
8
|
+
import { DevtoolsContext } from "../../store"
|
|
9
9
|
import type { JsonEditorComponents, SetterOrUpdater } from ".."
|
|
10
10
|
import type { JsonEditorProps_INTERNAL } from "../json-editor-internal"
|
|
11
11
|
import { JsonEditor_INTERNAL } from "../json-editor-internal"
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { RegularAtomToken } from "atom.io"
|
|
2
2
|
import { findInStore } from "atom.io/internal"
|
|
3
3
|
import type { Json, JsonTypes } from "atom.io/json"
|
|
4
|
-
import { useI } from "atom.io/react
|
|
5
|
-
import { useO } from "atom.io/react/use-o"
|
|
6
|
-
import { DevtoolsContext } from "atom.io/react-devtools/store"
|
|
4
|
+
import { useI, useO } from "atom.io/react"
|
|
7
5
|
import type { FC, ReactElement } from "react"
|
|
8
6
|
import { useContext, useRef } from "react"
|
|
9
7
|
|
|
10
8
|
import { ElasticInput } from "../../elastic-input"
|
|
9
|
+
import { DevtoolsContext } from "../../store"
|
|
11
10
|
import type { SetterOrUpdater } from ".."
|
|
12
11
|
import type { JsonEditorComponents } from "../default-components"
|
|
13
12
|
import type { JsonEditorProps_INTERNAL } from "../json-editor-internal"
|
|
@@ -10,7 +10,7 @@ export const makeElementSetters = <T extends Json.Tree.Array>(
|
|
|
10
10
|
data.map((value, index) => (newValue) => {
|
|
11
11
|
set((): T => {
|
|
12
12
|
const newData = [...data]
|
|
13
|
-
newData[index] = become(newValue
|
|
13
|
+
newData[index] = become(newValue, value)
|
|
14
14
|
return newData as unknown as T
|
|
15
15
|
})
|
|
16
16
|
})
|
|
@@ -14,7 +14,7 @@ export const makePropertySetters = <T extends Json.Tree.Object>(
|
|
|
14
14
|
toEntries(data).map(([key, value]) => [
|
|
15
15
|
key,
|
|
16
16
|
(newValue: unknown) => {
|
|
17
|
-
set({ ...data, [key]: become(newValue
|
|
17
|
+
set({ ...data, [key]: become(newValue, value) })
|
|
18
18
|
},
|
|
19
19
|
]),
|
|
20
20
|
)
|
|
@@ -3,7 +3,7 @@ import type { Fn, Store } from "atom.io/internal"
|
|
|
3
3
|
import {
|
|
4
4
|
actUponStore,
|
|
5
5
|
getEpochNumberOfContinuity,
|
|
6
|
-
|
|
6
|
+
ingestTransactionOutcomeEvent,
|
|
7
7
|
isRootStore,
|
|
8
8
|
setEpochNumberOfContinuity,
|
|
9
9
|
setIntoStore,
|
|
@@ -79,7 +79,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
79
79
|
)
|
|
80
80
|
const reversedOptimisticUpdates = optimisticUpdates.toReversed()
|
|
81
81
|
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
82
|
-
|
|
82
|
+
ingestTransactionOutcomeEvent(store, subsequentOptimistic, `oldValue`)
|
|
83
83
|
}
|
|
84
84
|
store.logger.info(
|
|
85
85
|
`⏪`,
|
|
@@ -88,7 +88,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
88
88
|
`undid optimistic updates:`,
|
|
89
89
|
reversedOptimisticUpdates,
|
|
90
90
|
)
|
|
91
|
-
|
|
91
|
+
ingestTransactionOutcomeEvent(store, optimisticUpdate, `oldValue`)
|
|
92
92
|
store.logger.info(
|
|
93
93
|
`⏪`,
|
|
94
94
|
`continuity`,
|
|
@@ -96,7 +96,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
96
96
|
`undid zeroth optimistic update`,
|
|
97
97
|
optimisticUpdate,
|
|
98
98
|
)
|
|
99
|
-
|
|
99
|
+
ingestTransactionOutcomeEvent(store, confirmedUpdate, `newValue`)
|
|
100
100
|
store.logger.info(
|
|
101
101
|
`⏩`,
|
|
102
102
|
`continuity`,
|
|
@@ -200,7 +200,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
200
200
|
continuityKey,
|
|
201
201
|
`integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`,
|
|
202
202
|
)
|
|
203
|
-
|
|
203
|
+
ingestTransactionOutcomeEvent(store, confirmed, `newValue`)
|
|
204
204
|
socket.emit(`ack:${continuityKey}`, confirmed.epoch)
|
|
205
205
|
setEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)
|
|
206
206
|
} else if (isRoot && continuityEpoch !== undefined) {
|
|
@@ -26,13 +26,13 @@ export function subscribeToContinuityPerspectives(
|
|
|
26
26
|
userViewState,
|
|
27
27
|
`sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`,
|
|
28
28
|
({ oldValue, newValue }) => {
|
|
29
|
-
const oldKeys = oldValue
|
|
29
|
+
const oldKeys = oldValue?.map((token) => token.key)
|
|
30
30
|
const newKeys = newValue.map((token) => token.key)
|
|
31
|
-
const concealed = oldValue
|
|
31
|
+
const concealed = oldValue?.filter(
|
|
32
32
|
(token) => !newKeys.includes(token.key),
|
|
33
33
|
)
|
|
34
34
|
const revealed = newValue
|
|
35
|
-
.filter((token) => !oldKeys
|
|
35
|
+
.filter((token) => !oldKeys?.includes(token.key))
|
|
36
36
|
.flatMap((token) => {
|
|
37
37
|
const resourceToken =
|
|
38
38
|
token.type === `mutable_atom` ? getJsonToken(store, token) : token
|
|
@@ -49,7 +49,7 @@ export function subscribeToContinuityPerspectives(
|
|
|
49
49
|
if (revealed.length > 0) {
|
|
50
50
|
socket?.emit(`reveal:${continuityKey}`, revealed)
|
|
51
51
|
}
|
|
52
|
-
if (concealed.length > 0) {
|
|
52
|
+
if (concealed && concealed.length > 0) {
|
|
53
53
|
socket?.emit(`conceal:${continuityKey}`, concealed)
|
|
54
54
|
}
|
|
55
55
|
},
|
package/dist/use-o-DXPncKmZ.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { IMPLICIT, findInStore, getFromStore, setIntoStore, subscribeToState } from "atom.io/internal";
|
|
2
|
-
import * as React$1 from "react";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
|
-
//#region src/react/store-context.tsx
|
|
6
|
-
const StoreContext = React$1.createContext(IMPLICIT.STORE);
|
|
7
|
-
const StoreProvider = ({ children, store = IMPLICIT.STORE }) => /* @__PURE__ */ jsx(StoreContext.Provider, {
|
|
8
|
-
value: store,
|
|
9
|
-
children
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/react/parse-state-overloads.ts
|
|
14
|
-
function parseStateOverloads(store, ...rest) {
|
|
15
|
-
let token;
|
|
16
|
-
if (rest.length === 2) {
|
|
17
|
-
const family = rest[0];
|
|
18
|
-
const key = rest[1];
|
|
19
|
-
token = findInStore(store, family, key);
|
|
20
|
-
} else token = rest[0];
|
|
21
|
-
return token;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/react/use-i.ts
|
|
26
|
-
function useI(...params) {
|
|
27
|
-
const store = React$1.useContext(StoreContext);
|
|
28
|
-
const token = parseStateOverloads(store, ...params);
|
|
29
|
-
const setter = React$1.useRef(null);
|
|
30
|
-
setter.current ??= (next) => {
|
|
31
|
-
setIntoStore(store, token, next);
|
|
32
|
-
};
|
|
33
|
-
return setter.current;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/react/use-o.ts
|
|
38
|
-
function useO(...params) {
|
|
39
|
-
const store = React$1.useContext(StoreContext);
|
|
40
|
-
const token = parseStateOverloads(store, ...params);
|
|
41
|
-
const id = React$1.useId();
|
|
42
|
-
return React$1.useSyncExternalStore((dispatch) => subscribeToState(store, token, `use-o:${id}`, dispatch), () => getFromStore(store, token), () => getFromStore(store, token));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
export { StoreContext, StoreProvider, useI, useO };
|
|
47
|
-
//# sourceMappingURL=use-o-DXPncKmZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-o-DXPncKmZ.js","names":["StoreContext: React.Context<Store>","React","StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}>","token: ReadableToken<any>","React","setter: React.RefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t>","React"],"sources":["../src/react/store-context.tsx","../src/react/parse-state-overloads.ts","../src/react/use-i.ts","../src/react/use-o.ts"],"sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext: React.Context<Store> = React.createContext(\n\tIMPLICIT.STORE,\n)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tWritableFamilyToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\n\nexport function parseStateOverloads<T, K extends Canonical>(\n\tstore: Store,\n\t...rest: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]\n): WritableToken<T>\n\nexport function parseStateOverloads<T, K extends Canonical>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]\n): ReadableToken<T>\n\nexport function parseStateOverloads<T, K extends Canonical>(\n\tstore: Store,\n\t...rest: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]\n): ReadableToken<T> {\n\tlet token: ReadableToken<any>\n\tif (rest.length === 2) {\n\t\tconst family = rest[0]\n\t\tconst key = rest[1]\n\n\t\ttoken = findInStore(store, family, key)\n\t} else {\n\t\ttoken = rest[0]\n\t}\n\treturn token\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { setIntoStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Canonical>(\n\t...params: [WritableFamilyToken<T, K>, K] | [WritableToken<T>]\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst setter: React.RefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tsetter.current ??= (next) => {\n\t\tsetIntoStore(store, token, next)\n\t}\n\treturn setter.current\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport { getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { parseStateOverloads } from \"./parse-state-overloads\"\nimport { StoreContext } from \"./store-context\"\n\nexport function useO<T>(token: ReadableToken<T>): T\n\nexport function useO<T, K extends Canonical>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function useO<T, K extends Canonical>(\n\t...params: [ReadableFamilyToken<T, K>, K] | [ReadableToken<T>]\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = parseStateOverloads(store, ...params)\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(store, token, `use-o:${id}`, dispatch),\n\t\t() => getFromStore(store, token),\n\t\t() => getFromStore(store, token),\n\t)\n}\n"],"mappings":";;;;;AAIA,MAAaA,eAAqCC,QAAM,cACvD,SAAS;AAGV,MAAaC,iBAGP,EAAE,UAAU,QAAQ,SAAS,OAAO,KACzC,oBAAC,aAAa;CAAS,OAAO;CAAQ;;;;;ACQvC,SAAgB,oBACf,OACA,GAAG,MACgB;CACnB,IAAIC;AACJ,KAAI,KAAK,WAAW,GAAG;EACtB,MAAM,SAAS,KAAK;EACpB,MAAM,MAAM,KAAK;AAEjB,UAAQ,YAAY,OAAO,QAAQ;CACnC,MACA,SAAQ,KAAK;AAEd,QAAO;AACP;;;;ACjBD,SAAgB,KACf,GAAG,QACsD;CACzD,MAAM,QAAQC,QAAM,WAAW;CAC/B,MAAM,QAAQ,oBAAoB,OAAO,GAAG;CAC5C,MAAMC,SAEFD,QAAM,OAAO;AACjB,QAAO,aAAa,SAAS;AAC5B,eAAa,OAAO,OAAO;CAC3B;AACD,QAAO,OAAO;AACd;;;;ACdD,SAAgB,KACf,GAAG,QACC;CACJ,MAAM,QAAQE,QAAM,WAAW;CAC/B,MAAM,QAAQ,oBAAoB,OAAO,GAAG;CAC5C,MAAM,KAAKA,QAAM;AACjB,QAAOA,QAAM,sBACX,aAAa,iBAAiB,OAAO,OAAO,SAAS,MAAM,iBACtD,aAAa,OAAO,cACpB,aAAa,OAAO;AAE3B"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ReadableFamilyToken,
|
|
3
|
-
ReadableToken,
|
|
4
|
-
WritableFamilyToken,
|
|
5
|
-
WritableToken,
|
|
6
|
-
} from "atom.io"
|
|
7
|
-
import type { Canonical } from "atom.io/json"
|
|
8
|
-
|
|
9
|
-
import type { Store } from "../store"
|
|
10
|
-
import { withdraw } from "../store"
|
|
11
|
-
|
|
12
|
-
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
13
|
-
store: Store,
|
|
14
|
-
token: WritableFamilyToken<T, K>,
|
|
15
|
-
key: Key,
|
|
16
|
-
): WritableToken<T, K>
|
|
17
|
-
|
|
18
|
-
export function initFamilyMemberInStore<T, K extends Canonical, Key extends K>(
|
|
19
|
-
store: Store,
|
|
20
|
-
token: ReadableFamilyToken<T, K>,
|
|
21
|
-
key: Key,
|
|
22
|
-
): ReadableToken<T, K>
|
|
23
|
-
|
|
24
|
-
export function initFamilyMemberInStore(
|
|
25
|
-
store: Store,
|
|
26
|
-
token: ReadableFamilyToken<any, any>,
|
|
27
|
-
key: Canonical,
|
|
28
|
-
): ReadableToken<any> {
|
|
29
|
-
const family = withdraw(store, token)
|
|
30
|
-
const state = family(key)
|
|
31
|
-
|
|
32
|
-
return state
|
|
33
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { TransactionOutcomeEvent } from "atom.io"
|
|
2
|
-
|
|
3
|
-
import type { Store } from "../store"
|
|
4
|
-
import { ingestAtomUpdate } from "./ingest-atom-update"
|
|
5
|
-
import {
|
|
6
|
-
ingestCreationEvent,
|
|
7
|
-
ingestDisposalEvent,
|
|
8
|
-
ingestMoleculeCreationEvent,
|
|
9
|
-
ingestMoleculeDisposalEvent,
|
|
10
|
-
ingestMoleculeTransferEvent,
|
|
11
|
-
} from "./ingest-creation-disposal"
|
|
12
|
-
|
|
13
|
-
export function ingestTransactionUpdate(
|
|
14
|
-
applying: `newValue` | `oldValue`,
|
|
15
|
-
transactionUpdate: TransactionOutcomeEvent<any>,
|
|
16
|
-
store: Store,
|
|
17
|
-
): void {
|
|
18
|
-
const updates =
|
|
19
|
-
applying === `newValue`
|
|
20
|
-
? transactionUpdate.subEvents
|
|
21
|
-
: [...transactionUpdate.subEvents].reverse()
|
|
22
|
-
for (const updateFromTransaction of updates) {
|
|
23
|
-
switch (updateFromTransaction.type) {
|
|
24
|
-
case `atom_update`:
|
|
25
|
-
ingestAtomUpdate(applying, updateFromTransaction, store)
|
|
26
|
-
break
|
|
27
|
-
case `state_creation`:
|
|
28
|
-
ingestCreationEvent(updateFromTransaction, applying, store)
|
|
29
|
-
break
|
|
30
|
-
case `state_disposal`:
|
|
31
|
-
ingestDisposalEvent(updateFromTransaction, applying, store)
|
|
32
|
-
break
|
|
33
|
-
case `molecule_creation`:
|
|
34
|
-
ingestMoleculeCreationEvent(updateFromTransaction, applying, store)
|
|
35
|
-
break
|
|
36
|
-
case `molecule_disposal`:
|
|
37
|
-
ingestMoleculeDisposalEvent(updateFromTransaction, applying, store)
|
|
38
|
-
break
|
|
39
|
-
case `molecule_transfer`:
|
|
40
|
-
ingestMoleculeTransferEvent(updateFromTransaction, applying, store)
|
|
41
|
-
break
|
|
42
|
-
case `transaction_outcome`:
|
|
43
|
-
ingestTransactionUpdate(applying, updateFromTransaction, store)
|
|
44
|
-
break
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
File without changes
|