atom.io 0.6.8 → 0.7.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/README.md +21 -2
- package/dist/index.d.mts +42 -461
- package/dist/index.d.ts +42 -461
- package/dist/index.js +128 -1792
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -1742
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +342 -0
- package/internal/dist/index.d.ts +342 -0
- package/internal/dist/index.js +1873 -0
- package/internal/dist/index.js.map +1 -0
- package/internal/dist/index.mjs +1798 -0
- package/internal/dist/index.mjs.map +1 -0
- package/internal/package.json +15 -0
- package/internal/src/atom/create-atom.ts +75 -0
- package/internal/src/atom/delete-atom.ts +10 -0
- package/internal/src/atom/index.ts +3 -0
- package/{src/internal → internal/src/atom}/is-default.ts +4 -2
- package/internal/src/caching.ts +21 -0
- package/internal/src/families/create-atom-family.ts +59 -0
- package/internal/src/families/create-readonly-selector-family.ts +45 -0
- package/internal/src/families/create-selector-family.ts +67 -0
- package/internal/src/families/index.ts +3 -0
- package/internal/src/get-state-internal.ts +23 -0
- package/internal/src/index.ts +13 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
- package/internal/src/mutable/create-mutable-atom.ts +49 -0
- package/internal/src/mutable/get-json-token.ts +22 -0
- package/internal/src/mutable/get-update-token.ts +20 -0
- package/internal/src/mutable/index.ts +17 -0
- package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
- package/internal/src/mutable/tracker-family.ts +61 -0
- package/internal/src/mutable/tracker.ts +164 -0
- package/internal/src/mutable/transceiver.ts +110 -0
- package/internal/src/operation.ts +68 -0
- package/{src/internal → internal/src}/selector/create-read-write-selector.ts +10 -13
- package/{src/internal → internal/src}/selector/create-readonly-selector.ts +9 -8
- package/internal/src/selector/create-selector.ts +65 -0
- package/{src/internal → internal/src}/selector/index.ts +1 -0
- package/internal/src/selector/lookup-selector-sources.ts +20 -0
- package/{src/internal → internal/src}/selector/register-selector.ts +13 -9
- package/{src/internal → internal/src}/selector/trace-selector-atoms.ts +4 -2
- package/{src/internal → internal/src}/selector/update-selector-atoms.ts +4 -3
- package/internal/src/set-state/become.ts +10 -0
- package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
- package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
- package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
- package/internal/src/set-state/emit-update.ts +23 -0
- package/internal/src/set-state/evict-downstream.ts +39 -0
- package/internal/src/set-state/index.ts +2 -0
- package/internal/src/set-state/set-atom-state.ts +38 -0
- package/internal/src/set-state/set-selector-state.ts +19 -0
- package/internal/src/set-state/set-state-internal.ts +18 -0
- package/internal/src/set-state/stow-update.ts +42 -0
- package/internal/src/store/deposit.ts +43 -0
- package/internal/src/store/index.ts +5 -0
- package/internal/src/store/lookup.ts +26 -0
- package/internal/src/store/store.ts +154 -0
- package/internal/src/store/withdraw-new-family-member.ts +53 -0
- package/internal/src/store/withdraw.ts +113 -0
- package/internal/src/subject.ts +21 -0
- package/internal/src/subscribe/index.ts +1 -0
- package/internal/src/subscribe/recall-state.ts +19 -0
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
- package/{src/internal → internal/src}/timeline/add-atom-to-timeline.ts +50 -29
- package/internal/src/timeline/index.ts +3 -0
- package/{src/internal → internal/src/timeline}/time-travel-internal.ts +6 -6
- package/{src/internal → internal/src/timeline}/timeline-internal.ts +20 -12
- package/{src/internal → internal/src}/transaction/abort-transaction.ts +1 -1
- package/{src/internal → internal/src}/transaction/apply-transaction.ts +25 -18
- package/{src/internal → internal/src}/transaction/build-transaction.ts +12 -6
- package/{src/internal → internal/src}/transaction/index.ts +3 -2
- package/{src/internal → internal/src}/transaction/redo-transaction.ts +4 -5
- package/{src/internal → internal/src/transaction}/transaction-internal.ts +16 -13
- package/{src/internal → internal/src}/transaction/undo-transaction.ts +4 -5
- package/introspection/dist/index.d.mts +12 -260
- package/introspection/dist/index.d.ts +12 -260
- package/introspection/dist/index.js +125 -140
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +103 -116
- package/introspection/dist/index.mjs.map +1 -1
- package/{src/introspection → introspection/src}/attach-atom-index.ts +41 -30
- package/{src/introspection → introspection/src}/attach-introspection-states.ts +6 -10
- package/introspection/src/attach-selector-index.ts +90 -0
- package/{src/introspection → introspection/src}/attach-timeline-family.ts +16 -16
- package/introspection/src/attach-timeline-index.ts +38 -0
- package/introspection/src/attach-transaction-index.ts +40 -0
- package/{src/introspection → introspection/src}/attach-transaction-logs.ts +11 -8
- package/json/dist/index.d.mts +41 -2
- package/json/dist/index.d.ts +41 -2
- package/json/dist/index.js +88 -48
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +76 -13
- package/json/dist/index.mjs.map +1 -1
- package/json/src/index.ts +5 -0
- package/json/src/select-json-family.ts +35 -0
- package/json/src/select-json.ts +22 -0
- package/package.json +105 -57
- package/react/dist/index.d.mts +9 -17
- package/react/dist/index.d.ts +9 -17
- package/react/dist/index.js +45 -77
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +18 -34
- package/react/dist/index.mjs.map +1 -1
- package/react/src/store-context.tsx +12 -0
- package/react/src/store-hooks.ts +36 -0
- package/react-devtools/dist/index.css +1 -1
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +199 -230
- package/react-devtools/dist/index.d.ts +199 -230
- package/react-devtools/dist/index.js +610 -2466
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +543 -2401
- package/react-devtools/dist/index.mjs.map +1 -1
- package/{src/react-devtools → react-devtools/src}/AtomIODevtools.tsx +5 -3
- package/{src/react-devtools → react-devtools/src}/Button.tsx +2 -3
- package/{src/react-devtools → react-devtools/src}/StateEditor.tsx +3 -2
- package/{src/react-devtools → react-devtools/src}/StateIndex.tsx +7 -4
- package/{src/react-devtools → react-devtools/src}/TimelineIndex.tsx +7 -11
- package/{src/react-devtools → react-devtools/src}/TransactionIndex.tsx +4 -4
- package/{src/react-devtools → react-devtools/src}/Updates.tsx +9 -4
- package/{src/react-devtools → react-devtools/src}/index.ts +5 -5
- package/realtime-react/dist/index.d.mts +9 -25
- package/realtime-react/dist/index.d.ts +9 -25
- package/realtime-react/dist/index.js +75 -193
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +44 -148
- package/realtime-react/dist/index.mjs.map +1 -1
- package/realtime-react/src/index.ts +7 -0
- package/{src/realtime-react → realtime-react/src}/realtime-context.tsx +3 -4
- package/realtime-react/src/use-pull-family-member.ts +15 -0
- package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
- package/realtime-react/src/use-pull-mutable.ts +17 -0
- package/realtime-react/src/use-pull.ts +15 -0
- package/realtime-react/src/use-push.ts +19 -0
- package/realtime-react/src/use-server-action.ts +18 -0
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +147 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +116 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/{src/realtime-testing → realtime-testing/src}/setup-realtime-test.tsx +10 -8
- package/src/atom.ts +64 -8
- package/src/index.ts +36 -29
- package/src/logger.ts +7 -7
- package/src/selector.ts +5 -5
- package/src/silo.ts +49 -43
- package/src/subscribe.ts +27 -22
- package/src/timeline.ts +9 -4
- package/src/transaction.ts +3 -4
- package/transceivers/set-rtx/dist/index.d.mts +39 -0
- package/transceivers/set-rtx/dist/index.d.ts +39 -0
- package/transceivers/set-rtx/dist/index.js +213 -0
- package/transceivers/set-rtx/dist/index.js.map +1 -0
- package/transceivers/set-rtx/dist/index.mjs +211 -0
- package/transceivers/set-rtx/dist/index.mjs.map +1 -0
- package/{realtime → transceivers/set-rtx}/package.json +1 -1
- package/transceivers/set-rtx/src/index.ts +1 -0
- package/transceivers/set-rtx/src/set-rtx.ts +242 -0
- package/realtime/dist/index.d.mts +0 -25
- package/realtime/dist/index.d.ts +0 -25
- package/realtime/dist/index.js +0 -190
- package/realtime/dist/index.js.map +0 -1
- package/realtime/dist/index.mjs +0 -151
- package/realtime/dist/index.mjs.map +0 -1
- package/src/internal/atom-internal.ts +0 -54
- package/src/internal/families-internal.ts +0 -144
- package/src/internal/get.ts +0 -129
- package/src/internal/index.ts +0 -15
- package/src/internal/operation.ts +0 -139
- package/src/internal/selector/lookup-selector-sources.ts +0 -16
- package/src/internal/selector-internal.ts +0 -58
- package/src/internal/set.ts +0 -99
- package/src/internal/store.ts +0 -151
- package/src/internal/subscribe-internal.ts +0 -88
- package/src/internal/timeline/index.ts +0 -1
- package/src/introspection/attach-selector-index.ts +0 -77
- package/src/introspection/attach-timeline-index.ts +0 -36
- package/src/introspection/attach-transaction-index.ts +0 -38
- package/src/json/index.ts +0 -1
- package/src/json/select-json.ts +0 -18
- package/src/react/store-context.tsx +0 -13
- package/src/react/store-hooks.ts +0 -47
- package/src/react-explorer/AtomIOExplorer.tsx +0 -218
- package/src/react-explorer/explorer-effects.ts +0 -20
- package/src/react-explorer/explorer-states.ts +0 -217
- package/src/react-explorer/index.ts +0 -23
- package/src/react-explorer/space-states.ts +0 -72
- package/src/react-explorer/view-states.ts +0 -41
- package/src/realtime/README.md +0 -33
- package/src/realtime/hook-composition/expose-family.ts +0 -101
- package/src/realtime/hook-composition/expose-single.ts +0 -38
- package/src/realtime/hook-composition/expose-timeline.ts +0 -60
- package/src/realtime/hook-composition/index.ts +0 -12
- package/src/realtime/hook-composition/receive-state.ts +0 -29
- package/src/realtime/hook-composition/receive-transaction.ts +0 -18
- package/src/realtime/index.ts +0 -1
- package/src/realtime-react/index.ts +0 -3
- package/src/realtime-react/realtime-hooks.ts +0 -39
- package/src/realtime-react/realtime-state.ts +0 -10
- package/src/realtime-react/use-pull-family-member.ts +0 -26
- package/src/realtime-react/use-pull-family.ts +0 -24
- package/src/realtime-react/use-pull.ts +0 -24
- package/src/realtime-react/use-push.ts +0 -27
- package/src/realtime-react/use-server-action.ts +0 -33
- package/src/tracker/index.ts +0 -3
- package/src/tracker/tracker.ts +0 -61
- package/src/web-effects/index.ts +0 -1
- package/src/web-effects/storage.ts +0 -30
- /package/{src/introspection → introspection/src}/index.ts +0 -0
- /package/{src/react → react/src}/index.ts +0 -0
- /package/{src/react-devtools → react-devtools/src}/devtools.scss +0 -0
- /package/{src/realtime-testing → realtime-testing/src}/index.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useI, useO } from "atom.io/react"
|
|
2
2
|
import { LayoutGroup, motion, spring } from "framer-motion"
|
|
3
3
|
import { useRef } from "react"
|
|
4
4
|
|
|
@@ -18,8 +18,10 @@ import "./devtools.scss"
|
|
|
18
18
|
export const AtomIODevtools = (): JSX.Element => {
|
|
19
19
|
const constraintsRef = useRef(null)
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
21
|
+
const setDevtoolsAreOpen = useI(devtoolsAreOpenState)
|
|
22
|
+
const devtoolsAreOpen = useO(devtoolsAreOpenState)
|
|
23
|
+
const setDevtoolsView = useI(devtoolsViewSelectionState)
|
|
24
|
+
const devtoolsView = useO(devtoolsViewSelectionState)
|
|
23
25
|
const devtoolsViewOptions = useO(devtoolsViewOptionsState)
|
|
24
26
|
|
|
25
27
|
const mouseHasMoved = useRef(false)
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import type { Modify } from "atom.io/internal"
|
|
1
2
|
import type { FC } from "react"
|
|
2
3
|
|
|
3
|
-
import type { Modifier } from "~/packages/anvl/src/function"
|
|
4
|
-
|
|
5
4
|
export const OpenClose: FC<{
|
|
6
5
|
isOpen: boolean
|
|
7
|
-
setIsOpen: (next:
|
|
6
|
+
setIsOpen: (next: Modify<boolean> | boolean) => void
|
|
8
7
|
disabled?: boolean
|
|
9
8
|
}> = ({ isOpen, setIsOpen, disabled }) => {
|
|
10
9
|
return (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReadonlySelectorToken, StateToken } from "atom.io"
|
|
2
|
-
import {
|
|
2
|
+
import { useI, useO } from "atom.io/react"
|
|
3
3
|
import type { FC } from "react"
|
|
4
4
|
|
|
5
5
|
import { fallback } from "~/packages/anvl/src/function"
|
|
@@ -12,7 +12,8 @@ import { JsonEditor } from "~/packages/hamr/src/react-json-editor"
|
|
|
12
12
|
export const StateEditor: FC<{
|
|
13
13
|
token: StateToken<unknown>
|
|
14
14
|
}> = ({ token }) => {
|
|
15
|
-
const
|
|
15
|
+
const set = useI(token)
|
|
16
|
+
const data = useO(token)
|
|
16
17
|
return isJson(data) ? (
|
|
17
18
|
<JsonEditor data={data} set={set} schema={true} />
|
|
18
19
|
) : data instanceof Join ? (
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AtomToken, ReadonlySelectorToken, SelectorToken } from "atom.io"
|
|
2
2
|
import { getState, selectorFamily } from "atom.io"
|
|
3
|
-
import {
|
|
3
|
+
import type { FamilyNode, StateTokenIndex } from "atom.io/introspection"
|
|
4
|
+
import { useI, useO } from "atom.io/react"
|
|
4
5
|
import type { FC } from "react"
|
|
5
6
|
|
|
6
7
|
import {
|
|
@@ -11,7 +12,6 @@ import {
|
|
|
11
12
|
import { findViewIsOpenState, primitiveRefinery } from "."
|
|
12
13
|
import { button } from "./Button"
|
|
13
14
|
import { StoreEditor } from "./StateEditor"
|
|
14
|
-
import type { FamilyNode, StateTokenIndex } from "../introspection"
|
|
15
15
|
|
|
16
16
|
const findStateTypeState = selectorFamily<string, { key: string }>({
|
|
17
17
|
key: `👁🗨 State Type`,
|
|
@@ -36,7 +36,9 @@ export const StateIndexLeafNode: FC<{
|
|
|
36
36
|
isOpenState: AtomToken<boolean>
|
|
37
37
|
typeState: ReadonlySelectorToken<string>
|
|
38
38
|
}> = ({ node, isOpenState, typeState }) => {
|
|
39
|
-
const
|
|
39
|
+
const setIsOpen = useI(isOpenState)
|
|
40
|
+
const isOpen = useO(isOpenState)
|
|
41
|
+
|
|
40
42
|
const state = useO(node)
|
|
41
43
|
const stateType = useO(typeState)
|
|
42
44
|
|
|
@@ -73,7 +75,8 @@ export const StateIndexTreeNode: FC<{
|
|
|
73
75
|
>
|
|
74
76
|
isOpenState: AtomToken<boolean>
|
|
75
77
|
}> = ({ node, isOpenState }) => {
|
|
76
|
-
const
|
|
78
|
+
const setIsOpen = useI(isOpenState)
|
|
79
|
+
const isOpen = useO(isOpenState)
|
|
77
80
|
Object.entries(node.familyMembers).forEach(([key, childNode]) => {
|
|
78
81
|
findViewIsOpenState(key)
|
|
79
82
|
findStateTypeState(childNode)
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
redo,
|
|
7
|
-
} from "atom.io"
|
|
8
|
-
import { useIO, useO } from "atom.io/react"
|
|
9
|
-
import { Fragment, type FC } from "react"
|
|
1
|
+
import type { AtomToken, ReadonlySelectorToken, TimelineToken } from "atom.io"
|
|
2
|
+
import { redo, undo } from "atom.io"
|
|
3
|
+
import type { Timeline } from "atom.io/internal"
|
|
4
|
+
import { useI, useO } from "atom.io/react"
|
|
5
|
+
import { type FC, Fragment } from "react"
|
|
10
6
|
|
|
11
7
|
import { findTimelineState, findViewIsOpenState, timelineIndex } from "."
|
|
12
8
|
import { button } from "./Button"
|
|
13
9
|
import { article } from "./Updates"
|
|
14
|
-
import type { Timeline } from "../internal"
|
|
15
10
|
|
|
16
11
|
export const YouAreHere: FC = () => {
|
|
17
12
|
return <span className="you_are_here">you are here</span>
|
|
@@ -23,7 +18,8 @@ export const TimelineLog: FC<{
|
|
|
23
18
|
timelineState: ReadonlySelectorToken<Timeline>
|
|
24
19
|
}> = ({ token, isOpenState, timelineState }) => {
|
|
25
20
|
const timeline = useO(timelineState)
|
|
26
|
-
const
|
|
21
|
+
const isOpen = useO(isOpenState)
|
|
22
|
+
const setIsOpen = useI(isOpenState)
|
|
27
23
|
|
|
28
24
|
return (
|
|
29
25
|
<section className="node timeline_log">
|
|
@@ -3,12 +3,11 @@ import type {
|
|
|
3
3
|
ReadonlySelectorToken,
|
|
4
4
|
TransactionToken,
|
|
5
5
|
TransactionUpdate,
|
|
6
|
+
ƒn,
|
|
6
7
|
} from "atom.io"
|
|
7
|
-
import {
|
|
8
|
+
import { useI, useO } from "atom.io/react"
|
|
8
9
|
import type { FC } from "react"
|
|
9
10
|
|
|
10
|
-
import type { ƒn } from "~/packages/anvl/src/function"
|
|
11
|
-
|
|
12
11
|
import {
|
|
13
12
|
findTransactionLogState,
|
|
14
13
|
findViewIsOpenState,
|
|
@@ -23,7 +22,8 @@ export const TransactionLog: FC<{
|
|
|
23
22
|
logState: ReadonlySelectorToken<TransactionUpdate<ƒn>[]>
|
|
24
23
|
}> = ({ token, isOpenState, logState }) => {
|
|
25
24
|
const log = useO(logState)
|
|
26
|
-
const
|
|
25
|
+
const isOpen = useO(isOpenState)
|
|
26
|
+
const setIsOpen = useI(isOpenState)
|
|
27
27
|
|
|
28
28
|
return (
|
|
29
29
|
<section className="node transaction_log">
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
KeyedStateUpdate,
|
|
3
|
+
TimelineUpdate,
|
|
4
|
+
TransactionUpdate,
|
|
5
|
+
ƒn,
|
|
6
|
+
} from "atom.io"
|
|
7
|
+
import * as React from "react"
|
|
8
|
+
|
|
2
9
|
import { discoverType } from "~/packages/anvl/src/refinement/refinery"
|
|
3
10
|
|
|
4
11
|
import { prettyJson } from "."
|
|
5
|
-
import type { KeyedStateUpdate } from "../subscribe"
|
|
6
|
-
import type { TimelineUpdate } from "../timeline"
|
|
7
|
-
import type { TransactionUpdate } from "../transaction"
|
|
8
12
|
|
|
9
13
|
const AtomUpdateFC: React.FC<{
|
|
10
14
|
serialNumber: number
|
|
@@ -50,6 +54,7 @@ const TransactionUpdateFC: React.FC<{
|
|
|
50
54
|
<span className="detail">{discoverType(param)}: </span>
|
|
51
55
|
<span className="summary">
|
|
52
56
|
{typeof param === `object` &&
|
|
57
|
+
param !== null &&
|
|
53
58
|
`type` in param &&
|
|
54
59
|
`target` in param ? (
|
|
55
60
|
<>{JSON.stringify(param.type)}</>
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import { atom, atomFamily } from "atom.io"
|
|
2
|
+
import { attachIntrospectionStates } from "atom.io/introspection"
|
|
3
|
+
import { lazyLocalStorageEffect } from "atom.io/web-effects"
|
|
4
|
+
|
|
1
5
|
import { isPlainObject } from "~/packages/anvl/src/object"
|
|
2
6
|
import { Refinery } from "~/packages/anvl/src/refinement/refinery"
|
|
3
7
|
import {
|
|
8
|
+
Differ,
|
|
4
9
|
diffArray,
|
|
5
10
|
diffBoolean,
|
|
6
11
|
diffNumber,
|
|
7
12
|
diffObject,
|
|
8
13
|
diffString,
|
|
9
|
-
Differ,
|
|
10
14
|
} from "~/packages/anvl/src/tree/differ"
|
|
11
15
|
|
|
12
|
-
import { atom, atomFamily } from ".."
|
|
13
|
-
import { attachIntrospectionStates } from "../introspection"
|
|
14
|
-
import { lazyLocalStorageEffect } from "../web-effects"
|
|
15
|
-
|
|
16
16
|
export * from "./AtomIODevtools"
|
|
17
17
|
|
|
18
18
|
export const {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
3
|
import * as AtomIO from 'atom.io';
|
|
4
|
+
import { Json } from 'atom.io/json';
|
|
5
|
+
import { Transceiver } from 'atom.io/internal';
|
|
4
6
|
|
|
5
7
|
declare const RealtimeContext: React.Context<{
|
|
6
8
|
socket: Socket;
|
|
@@ -10,34 +12,16 @@ declare const RealtimeProvider: React.FC<{
|
|
|
10
12
|
socket: Socket;
|
|
11
13
|
}>;
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
declare function usePull<J extends Json.Serializable>(token: AtomIO.StateToken<J>): void;
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
declare function usePullFamilyMember<J extends Json.Serializable>(token: AtomIO.AtomToken<J>): void;
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
[key: string]: Serializable;
|
|
19
|
-
}> | ReadonlyArray<Serializable>;
|
|
19
|
+
declare function usePullMutable<T extends Transceiver<Json.Serializable>, J extends Json.Serializable>(token: AtomIO.MutableAtomToken<T, J>): void;
|
|
20
20
|
|
|
21
|
-
declare function
|
|
21
|
+
declare function usePullMutableFamilyMember<T extends Transceiver<Json.Serializable>, J extends Json.Serializable>(token: AtomIO.MutableAtomToken<T, J>): void;
|
|
22
22
|
|
|
23
|
-
declare function
|
|
23
|
+
declare function usePush<J extends Json.Serializable>(token: AtomIO.StateToken<J>): void;
|
|
24
24
|
|
|
25
|
-
declare function
|
|
25
|
+
declare function useServerAction<ƒ extends AtomIO.ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
declare function useServerAction<ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
30
|
-
|
|
31
|
-
type RealtimeHooks = {
|
|
32
|
-
usePull: <J extends Serializable>(token: AtomIO.StateToken<J>) => void;
|
|
33
|
-
usePullFamily: <J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>) => void;
|
|
34
|
-
usePullFamilyMember: <J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: string) => void;
|
|
35
|
-
usePush: <J extends Serializable>(token: AtomIO.StateToken<J>) => void;
|
|
36
|
-
useServerAction: <ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
37
|
-
};
|
|
38
|
-
declare const realtimeHooks: RealtimeHooks;
|
|
39
|
-
|
|
40
|
-
declare const myIdState__INTERNAL: AtomIO.AtomToken<string | null>;
|
|
41
|
-
declare const myIdState: AtomIO.ReadonlySelectorToken<string | null>;
|
|
42
|
-
|
|
43
|
-
export { RealtimeContext, RealtimeHooks, RealtimeProvider, myIdState, myIdState__INTERNAL, realtimeHooks, usePull, usePullFamily, usePullFamilyMember, usePush, useServerAction };
|
|
27
|
+
export { RealtimeContext, RealtimeProvider, usePull, usePullFamilyMember, usePullMutable, usePullMutableFamilyMember, usePush, useServerAction };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
3
|
import * as AtomIO from 'atom.io';
|
|
4
|
+
import { Json } from 'atom.io/json';
|
|
5
|
+
import { Transceiver } from 'atom.io/internal';
|
|
4
6
|
|
|
5
7
|
declare const RealtimeContext: React.Context<{
|
|
6
8
|
socket: Socket;
|
|
@@ -10,34 +12,16 @@ declare const RealtimeProvider: React.FC<{
|
|
|
10
12
|
socket: Socket;
|
|
11
13
|
}>;
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
declare function usePull<J extends Json.Serializable>(token: AtomIO.StateToken<J>): void;
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
declare function usePullFamilyMember<J extends Json.Serializable>(token: AtomIO.AtomToken<J>): void;
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
[key: string]: Serializable;
|
|
19
|
-
}> | ReadonlyArray<Serializable>;
|
|
19
|
+
declare function usePullMutable<T extends Transceiver<Json.Serializable>, J extends Json.Serializable>(token: AtomIO.MutableAtomToken<T, J>): void;
|
|
20
20
|
|
|
21
|
-
declare function
|
|
21
|
+
declare function usePullMutableFamilyMember<T extends Transceiver<Json.Serializable>, J extends Json.Serializable>(token: AtomIO.MutableAtomToken<T, J>): void;
|
|
22
22
|
|
|
23
|
-
declare function
|
|
23
|
+
declare function usePush<J extends Json.Serializable>(token: AtomIO.StateToken<J>): void;
|
|
24
24
|
|
|
25
|
-
declare function
|
|
25
|
+
declare function useServerAction<ƒ extends AtomIO.ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
declare function useServerAction<ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
30
|
-
|
|
31
|
-
type RealtimeHooks = {
|
|
32
|
-
usePull: <J extends Serializable>(token: AtomIO.StateToken<J>) => void;
|
|
33
|
-
usePullFamily: <J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>) => void;
|
|
34
|
-
usePullFamilyMember: <J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: string) => void;
|
|
35
|
-
usePush: <J extends Serializable>(token: AtomIO.StateToken<J>) => void;
|
|
36
|
-
useServerAction: <ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
37
|
-
};
|
|
38
|
-
declare const realtimeHooks: RealtimeHooks;
|
|
39
|
-
|
|
40
|
-
declare const myIdState__INTERNAL: AtomIO.AtomToken<string | null>;
|
|
41
|
-
declare const myIdState: AtomIO.ReadonlySelectorToken<string | null>;
|
|
42
|
-
|
|
43
|
-
export { RealtimeContext, RealtimeHooks, RealtimeProvider, myIdState, myIdState__INTERNAL, realtimeHooks, usePull, usePullFamily, usePullFamilyMember, usePush, useServerAction };
|
|
27
|
+
export { RealtimeContext, RealtimeProvider, usePull, usePullFamilyMember, usePullMutable, usePullMutableFamilyMember, usePush, useServerAction };
|
|
@@ -1,71 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
28
2
|
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
myIdState__INTERNAL: () => myIdState__INTERNAL,
|
|
36
|
-
realtimeHooks: () => realtimeHooks,
|
|
37
|
-
usePull: () => usePull,
|
|
38
|
-
usePullFamily: () => usePullFamily,
|
|
39
|
-
usePullFamilyMember: () => usePullFamilyMember,
|
|
40
|
-
usePush: () => usePush,
|
|
41
|
-
useServerAction: () => useServerAction
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(realtime_react_exports);
|
|
3
|
+
var react = require('atom.io/react');
|
|
4
|
+
var RTC = require('atom.io/realtime-client');
|
|
5
|
+
var React6 = require('react');
|
|
6
|
+
var socket_ioClient = require('socket.io-client');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var AtomIO = require('atom.io');
|
|
44
9
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
49
27
|
|
|
50
|
-
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
key: `myId__INTERNAL`,
|
|
54
|
-
default: null
|
|
55
|
-
});
|
|
56
|
-
var myIdState = AtomIO.selector({
|
|
57
|
-
key: `myId`,
|
|
58
|
-
get: ({ get }) => get(myIdState__INTERNAL)
|
|
59
|
-
});
|
|
28
|
+
var RTC__namespace = /*#__PURE__*/_interopNamespace(RTC);
|
|
29
|
+
var React6__namespace = /*#__PURE__*/_interopNamespace(React6);
|
|
30
|
+
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
60
31
|
|
|
61
|
-
//
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
socket: (0, import_socket.io)()
|
|
32
|
+
// src/realtime-context.tsx
|
|
33
|
+
var RealtimeContext = React6__namespace.createContext({
|
|
34
|
+
socket: socket_ioClient.io()
|
|
65
35
|
});
|
|
66
36
|
var RealtimeProvider = ({ children, socket }) => {
|
|
67
|
-
const setMyId =
|
|
68
|
-
|
|
37
|
+
const setMyId = react.useI(RTC__namespace.myIdState__INTERNAL);
|
|
38
|
+
React6__namespace.useEffect(() => {
|
|
69
39
|
socket.on(`connect`, () => {
|
|
70
40
|
setMyId(socket.id);
|
|
71
41
|
});
|
|
@@ -73,145 +43,57 @@ var RealtimeProvider = ({ children, socket }) => {
|
|
|
73
43
|
setMyId(null);
|
|
74
44
|
});
|
|
75
45
|
}, [socket, setMyId]);
|
|
76
|
-
return /* @__PURE__ */
|
|
77
|
-
fileName: "../src/realtime-react/realtime-context.tsx",
|
|
78
|
-
lineNumber: 26,
|
|
79
|
-
columnNumber: 3
|
|
80
|
-
}, this);
|
|
46
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RealtimeContext.Provider, { value: { socket }, children });
|
|
81
47
|
};
|
|
82
|
-
|
|
83
|
-
// ../src/realtime-react/use-pull.ts
|
|
84
|
-
var AtomIO3 = __toESM(require("atom.io"));
|
|
85
|
-
var React3 = __toESM(require("react"));
|
|
86
|
-
|
|
87
|
-
// ../src/react/store-context.tsx
|
|
88
|
-
var AtomIO2 = __toESM(require("atom.io"));
|
|
89
|
-
var React2 = __toESM(require("react"));
|
|
90
|
-
var import_jsx_dev_runtime2 = require("react/jsx-dev-runtime");
|
|
91
|
-
var StoreContext = React2.createContext(
|
|
92
|
-
AtomIO2.__INTERNAL__.IMPLICIT.STORE
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
// ../src/realtime-react/use-pull.ts
|
|
96
48
|
function usePull(token) {
|
|
97
|
-
const { socket } =
|
|
98
|
-
const store =
|
|
99
|
-
|
|
100
|
-
socket.on(`serve:${token.key}`, (data) => {
|
|
101
|
-
AtomIO3.setState(token, data, store);
|
|
102
|
-
});
|
|
103
|
-
socket.emit(`sub:${token.key}`);
|
|
104
|
-
return () => {
|
|
105
|
-
socket.off(`serve:${token.key}`);
|
|
106
|
-
socket.emit(`unsub:${token.key}`);
|
|
107
|
-
};
|
|
108
|
-
}, [token.key]);
|
|
49
|
+
const { socket } = React6__namespace.useContext(RealtimeContext);
|
|
50
|
+
const store = React6__namespace.useContext(react.StoreContext);
|
|
51
|
+
React6__namespace.useEffect(() => RTC__namespace.pullState(token, socket, store), [token.key]);
|
|
109
52
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
function usePullFamily(family) {
|
|
115
|
-
const { socket } = React4.useContext(RealtimeContext);
|
|
116
|
-
const store = React4.useContext(StoreContext);
|
|
117
|
-
React4.useEffect(() => {
|
|
118
|
-
socket.on(`serve:${family.key}`, (key, data) => {
|
|
119
|
-
AtomIO4.setState(family(key), data, store);
|
|
120
|
-
});
|
|
121
|
-
socket == null ? void 0 : socket.emit(`sub:${family.key}`);
|
|
122
|
-
return () => {
|
|
123
|
-
socket == null ? void 0 : socket.off(`serve:${family.key}`);
|
|
124
|
-
socket == null ? void 0 : socket.emit(`unsub:${family.key}`);
|
|
125
|
-
};
|
|
126
|
-
}, [family.key]);
|
|
53
|
+
function usePullFamilyMember(token) {
|
|
54
|
+
const { socket } = React6__namespace.useContext(RealtimeContext);
|
|
55
|
+
const store = React6__namespace.useContext(react.StoreContext);
|
|
56
|
+
React6__namespace.useEffect(() => RTC__namespace.pullFamilyMember(token, socket, store), [token.key]);
|
|
127
57
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const { socket } =
|
|
135
|
-
const store =
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
socket == null ? void 0 : socket.emit(`sub:${family.key}`, subKey);
|
|
141
|
-
return () => {
|
|
142
|
-
socket == null ? void 0 : socket.off(`serve:${token.key}`);
|
|
143
|
-
socket == null ? void 0 : socket.emit(`unsub:${token.key}`);
|
|
144
|
-
};
|
|
145
|
-
}, [family.key]);
|
|
58
|
+
function usePullMutable(token) {
|
|
59
|
+
const { socket } = React6__namespace.useContext(RealtimeContext);
|
|
60
|
+
const store = React6__namespace.useContext(react.StoreContext);
|
|
61
|
+
React6__namespace.useEffect(() => RTC__namespace.pullMutableState(token, socket, store), [token.key]);
|
|
62
|
+
}
|
|
63
|
+
function usePullMutableFamilyMember(token) {
|
|
64
|
+
const { socket } = React6__namespace.useContext(RealtimeContext);
|
|
65
|
+
const store = React6__namespace.useContext(react.StoreContext);
|
|
66
|
+
React6__namespace.useEffect(
|
|
67
|
+
() => RTC__namespace.pullMutableFamilyMember(token, socket, store),
|
|
68
|
+
[token.key]
|
|
69
|
+
);
|
|
146
70
|
}
|
|
147
|
-
|
|
148
|
-
// ../src/realtime-react/use-push.ts
|
|
149
|
-
var AtomIO6 = __toESM(require("atom.io"));
|
|
150
|
-
var React6 = __toESM(require("react"));
|
|
151
71
|
function usePush(token) {
|
|
152
|
-
const { socket } =
|
|
153
|
-
const store =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
socket.emit(`pub:${token.key}`, newValue);
|
|
160
|
-
},
|
|
161
|
-
store
|
|
162
|
-
);
|
|
163
|
-
return () => {
|
|
164
|
-
socket.emit(`unclaim:${token.key}`);
|
|
165
|
-
};
|
|
166
|
-
}, [token.key]);
|
|
72
|
+
const { socket } = React6__namespace.useContext(RealtimeContext);
|
|
73
|
+
const store = React6__namespace.useContext(react.StoreContext);
|
|
74
|
+
const id = React6__namespace.useId();
|
|
75
|
+
React6__namespace.useEffect(
|
|
76
|
+
() => RTC__namespace.pushState(token, socket, `use-push:${id}`, store),
|
|
77
|
+
[token.key]
|
|
78
|
+
);
|
|
167
79
|
}
|
|
168
|
-
|
|
169
|
-
// ../src/realtime-react/use-server-action.ts
|
|
170
|
-
var AtomIO7 = __toESM(require("atom.io"));
|
|
171
|
-
var import_react5 = require("atom.io/react");
|
|
172
|
-
var React7 = __toESM(require("react"));
|
|
173
|
-
var TX_SUBS = /* @__PURE__ */ new Map();
|
|
174
80
|
function useServerAction(token) {
|
|
175
|
-
const store =
|
|
176
|
-
const { socket } =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
token,
|
|
183
|
-
(update) => socket.emit(`tx:${token.key}`, update),
|
|
184
|
-
store
|
|
185
|
-
) : () => null;
|
|
186
|
-
return () => {
|
|
187
|
-
var _a2;
|
|
188
|
-
const newCount = (_a2 = TX_SUBS.get(token.key)) != null ? _a2 : 0;
|
|
189
|
-
TX_SUBS.set(token.key, newCount - 1);
|
|
190
|
-
unsubscribe();
|
|
191
|
-
};
|
|
192
|
-
}, [token.key]);
|
|
193
|
-
return AtomIO7.runTransaction(token, store);
|
|
81
|
+
const store = React6__namespace.useContext(react.StoreContext);
|
|
82
|
+
const { socket } = React6__namespace.useContext(RealtimeContext);
|
|
83
|
+
React6__namespace.useEffect(
|
|
84
|
+
() => RTC__namespace.synchronizeTransactionResults(token, socket, store),
|
|
85
|
+
[token.key]
|
|
86
|
+
);
|
|
87
|
+
return AtomIO__namespace.runTransaction(token, store);
|
|
194
88
|
}
|
|
195
89
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
0 && (module.exports = {
|
|
206
|
-
RealtimeContext,
|
|
207
|
-
RealtimeProvider,
|
|
208
|
-
myIdState,
|
|
209
|
-
myIdState__INTERNAL,
|
|
210
|
-
realtimeHooks,
|
|
211
|
-
usePull,
|
|
212
|
-
usePullFamily,
|
|
213
|
-
usePullFamilyMember,
|
|
214
|
-
usePush,
|
|
215
|
-
useServerAction
|
|
216
|
-
});
|
|
90
|
+
exports.RealtimeContext = RealtimeContext;
|
|
91
|
+
exports.RealtimeProvider = RealtimeProvider;
|
|
92
|
+
exports.usePull = usePull;
|
|
93
|
+
exports.usePullFamilyMember = usePullFamilyMember;
|
|
94
|
+
exports.usePullMutable = usePullMutable;
|
|
95
|
+
exports.usePullMutableFamilyMember = usePullMutableFamilyMember;
|
|
96
|
+
exports.usePush = usePush;
|
|
97
|
+
exports.useServerAction = useServerAction;
|
|
98
|
+
//# sourceMappingURL=out.js.map
|
|
217
99
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/realtime-react/index.ts","../../src/realtime-react/realtime-context.tsx","../../src/realtime-react/realtime-state.ts","../../src/realtime-react/use-pull.ts","../../src/react/store-context.tsx","../../src/realtime-react/use-pull-family.ts","../../src/realtime-react/use-pull-family-member.ts","../../src/realtime-react/use-push.ts","../../src/realtime-react/use-server-action.ts","../../src/realtime-react/realtime-hooks.ts"],"sourcesContent":["export * from \"./realtime-context\"\nexport * from \"./realtime-hooks\"\nexport * from \"./realtime-state\"\n","import * as AR from \"atom.io/react\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nimport { myIdState__INTERNAL } from \"./realtime-state\"\n\nexport const RealtimeContext = React.createContext<{ socket: Socket }>({\n\tsocket: io(),\n})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket\n}> = ({ children, socket }) => {\n\tconst setMyId = AR.useI(myIdState__INTERNAL)\n\tReact.useEffect(() => {\n\t\tsocket.on(`connect`, () => {\n\t\t\tsetMyId(socket.id)\n\t\t})\n\t\tsocket.on(`disconnect`, () => {\n\t\t\tsetMyId(null)\n\t\t})\n\t}, [socket, setMyId])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n","import * as AtomIO from \"atom.io\"\n\nexport const myIdState__INTERNAL = AtomIO.atom<string | null>({\n\tkey: `myId__INTERNAL`,\n\tdefault: null,\n})\nexport const myIdState = AtomIO.selector<string | null>({\n\tkey: `myId`,\n\tget: ({ get }) => get(myIdState__INTERNAL),\n})\n","import * as AtomIO from \"atom.io\"\nimport * as React from \"react\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePull<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket.on(`serve:${token.key}`, (data: J) => {\n\t\t\tAtomIO.setState(token, data, store)\n\t\t})\n\t\tsocket.emit(`sub:${token.key}`)\n\t\treturn () => {\n\t\t\tsocket.off(`serve:${token.key}`)\n\t\t\tsocket.emit(`unsub:${token.key}`)\n\t\t}\n\t}, [token.key])\n}\n","import * as AtomIO from \"atom.io\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<AtomIO.Store>(\n\tAtomIO.__INTERNAL__.IMPLICIT.STORE,\n)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: AtomIO.Store\n}> = ({ children, store = AtomIO.__INTERNAL__.IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import * as AtomIO from \"atom.io\"\nimport * as React from \"react\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePullFamily<J extends Json.Serializable>(\n\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket.on(`serve:${family.key}`, (key: Json.Serializable, data: J) => {\n\t\t\tAtomIO.setState(family(key), data, store)\n\t\t})\n\t\tsocket?.emit(`sub:${family.key}`)\n\t\treturn () => {\n\t\t\tsocket?.off(`serve:${family.key}`)\n\t\t\tsocket?.emit(`unsub:${family.key}`)\n\t\t}\n\t}, [family.key])\n}\n","import * as AtomIO from \"atom.io\"\nimport * as React from \"react\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePullFamilyMember<J extends Json.Serializable>(\n\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\tsubKey: AtomIO.Json.Serializable,\n): void {\n\tconst token = family(subKey)\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket?.on(`serve:${token.key}`, (data: J) => {\n\t\t\tAtomIO.setState(family(subKey), data, store)\n\t\t})\n\t\tsocket?.emit(`sub:${family.key}`, subKey)\n\t\treturn () => {\n\t\t\tsocket?.off(`serve:${token.key}`)\n\t\t\tsocket?.emit(`unsub:${token.key}`)\n\t\t}\n\t}, [family.key])\n}\n","import * as AtomIO from \"atom.io\"\nimport * as React from \"react\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePush<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket.emit(`claim:${token.key}`)\n\t\tAtomIO.subscribe(\n\t\t\ttoken,\n\t\t\t({ newValue }) => {\n\t\t\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\treturn () => {\n\t\t\tsocket.emit(`unclaim:${token.key}`)\n\t\t}\n\t}, [token.key])\n}\n","import * as AtomIO from \"atom.io\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as React from \"react\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nconst TX_SUBS = new Map<string, number>()\nexport function useServerAction<ƒ extends ƒn>(\n\ttoken: AtomIO.TransactionToken<ƒ>,\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n\tconst store = React.useContext(StoreContext)\n\tconst { socket } = React.useContext(RealtimeContext)\n\tReact.useEffect(() => {\n\t\tconst count = TX_SUBS.get(token.key) ?? 0\n\t\tTX_SUBS.set(token.key, count + 1)\n\t\tconst unsubscribe =\n\t\t\tcount === 0\n\t\t\t\t? AtomIO.subscribeToTransaction(\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t(update) => socket.emit(`tx:${token.key}`, update),\n\t\t\t\t\t\tstore,\n\t\t\t\t )\n\t\t\t\t: () => null\n\t\treturn () => {\n\t\t\tconst newCount = TX_SUBS.get(token.key) ?? 0\n\t\t\tTX_SUBS.set(token.key, newCount - 1)\n\t\t\tunsubscribe()\n\t\t}\n\t}, [token.key])\n\treturn AtomIO.runTransaction(token, store)\n}\n","import type * as AtomIO from \"atom.io\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { usePull } from \"./use-pull\"\nimport { usePullFamily } from \"./use-pull-family\"\nimport { usePullFamilyMember } from \"./use-pull-family-member\"\nimport { usePush } from \"./use-push\"\nimport { useServerAction } from \"./use-server-action\"\n\nexport type RealtimeHooks = {\n\tusePull: <J extends Json.Serializable>(token: AtomIO.StateToken<J>) => void\n\tusePullFamily: <J extends Json.Serializable>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t) => void\n\tusePullFamilyMember: <J extends Json.Serializable>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t\tsubKey: string,\n\t) => void\n\tusePush: <J extends Json.Serializable>(token: AtomIO.StateToken<J>) => void\n\tuseServerAction: <ƒ extends ƒn>(\n\t\ttoken: AtomIO.TransactionToken<ƒ>,\n\t) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>\n}\n\nexport const realtimeHooks: RealtimeHooks = {\n\tusePull,\n\tusePullFamily,\n\tusePullFamilyMember,\n\tusePush,\n\tuseServerAction,\n}\n\nexport * from \"./use-pull\"\nexport * from \"./use-pull-family\"\nexport * from \"./use-pull-family-member\"\nexport * from \"./use-push\"\nexport * from \"./use-server-action\"\n"],"mappings":"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","names":["AtomIO","React","AtomIO","React","import_jsx_dev_runtime","AtomIO","React","AtomIO","React","AtomIO","React","AtomIO","import_react","React","_a"]}
|
|
1
|
+
{"version":3,"sources":["../src/realtime-context.tsx","../src/use-pull.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts","../src/use-server-action.ts"],"names":["RTC","React","StoreContext"],"mappings":";AAAA,SAAS,YAAY;AACrB,YAAY,SAAS;AACrB,YAAY,WAAW;AAEvB,SAAS,UAAU;AAoBjB;AAlBK,IAAM,kBAAwB,oBAAkC;AAAA,EACtE,QAAQ,GAAG;AACZ,CAAC;AAEM,IAAM,mBAGR,CAAC,EAAE,UAAU,OAAO,MAAM;AAC9B,QAAM,UAAU,KAAS,uBAAmB;AAC5C,EAAM,gBAAU,MAAM;AACrB,WAAO,GAAG,WAAW,MAAM;AAC1B,cAAQ,OAAO,EAAE;AAAA,IAClB,CAAC;AACD,WAAO,GAAG,cAAc,MAAM;AAC7B,cAAQ,IAAI;AAAA,IACb,CAAC;AAAA,EACF,GAAG,CAAC,QAAQ,OAAO,CAAC;AACpB,SACC,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,OAAO,GACxC,UACF;AAEF;;;AC1BA,SAAS,oBAAoB;AAC7B,YAAYA,UAAS;AACrB,YAAYC,YAAW;AAIhB,SAAS,QACf,OACO;AACP,QAAM,EAAE,OAAO,IAAU,kBAAW,eAAe;AACnD,QAAM,QAAc,kBAAW,YAAY;AAC3C,EAAM,iBAAU,MAAU,eAAU,OAAO,QAAQ,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC;AACvE;;;ACZA,SAAS,gBAAAC,qBAAoB;AAC7B,YAAYF,UAAS;AACrB,YAAYC,YAAW;AAIhB,SAAS,oBACf,OACO;AACP,QAAM,EAAE,OAAO,IAAU,kBAAW,eAAe;AACnD,QAAM,QAAc,kBAAWC,aAAY;AAC3C,EAAM,iBAAU,MAAU,sBAAiB,OAAO,QAAQ,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC;AAC9E;;;ACXA,SAAS,gBAAAA,qBAAoB;AAC7B,YAAYF,UAAS;AACrB,YAAYC,YAAW;AAIhB,SAAS,eAGd,OAA4C;AAC7C,QAAM,EAAE,OAAO,IAAU,kBAAW,eAAe;AACnD,QAAM,QAAc,kBAAWC,aAAY;AAC3C,EAAM,iBAAU,MAAU,sBAAiB,OAAO,QAAQ,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC;AAC9E;;;ACbA,SAAS,gBAAAA,qBAAoB;AAC7B,YAAYF,UAAS;AACrB,YAAYC,YAAW;AAIhB,SAAS,2BAGd,OAA4C;AAC7C,QAAM,EAAE,OAAO,IAAU,kBAAW,eAAe;AACnD,QAAM,QAAc,kBAAWC,aAAY;AAC3C,EAAM;AAAA,IACL,MAAU,6BAAwB,OAAO,QAAQ,KAAK;AAAA,IACtD,CAAC,MAAM,GAAG;AAAA,EACX;AACD;;;ACjBA,SAAS,gBAAAA,qBAAoB;AAC7B,YAAYF,UAAS;AACrB,YAAYC,YAAW;AAIhB,SAAS,QACf,OACO;AACP,QAAM,EAAE,OAAO,IAAU,kBAAW,eAAe;AACnD,QAAM,QAAc,kBAAWC,aAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,EAAM;AAAA,IACL,MAAU,eAAU,OAAO,QAAQ,YAAY,EAAE,IAAI,KAAK;AAAA,IAC1D,CAAC,MAAM,GAAG;AAAA,EACX;AACD;;;AClBA,YAAY,YAAY;AACxB,SAAS,gBAAAA,qBAAoB;AAC7B,YAAYF,UAAS;AACrB,YAAYC,YAAW;AAIhB,SAAS,gBACf,OACkD;AAClD,QAAM,QAAc,kBAAWC,aAAY;AAC3C,QAAM,EAAE,OAAO,IAAU,kBAAW,eAAe;AACnD,EAAM;AAAA,IACL,MAAU,mCAA8B,OAAO,QAAQ,KAAK;AAAA,IAC5D,CAAC,MAAM,GAAG;AAAA,EACX;AACA,SAAc,sBAAe,OAAO,KAAK;AAC1C","sourcesContent":["import { useI } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nexport const RealtimeContext = React.createContext<{ socket: Socket }>({\n\tsocket: io(),\n})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket\n}> = ({ children, socket }) => {\n\tconst setMyId = useI(RTC.myIdState__INTERNAL)\n\tReact.useEffect(() => {\n\t\tsocket.on(`connect`, () => {\n\t\t\tsetMyId(socket.id)\n\t\t})\n\t\tsocket.on(`disconnect`, () => {\n\t\t\tsetMyId(null)\n\t\t})\n\t}, [socket, setMyId])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function usePull<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => RTC.pullState(token, socket, store), [token.key])\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function usePullFamilyMember<J extends Json.Serializable>(\n\ttoken: AtomIO.AtomToken<J>,\n): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => RTC.pullFamilyMember(token, socket, store), [token.key])\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function usePullMutable<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(token: AtomIO.MutableAtomToken<T, J>): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => RTC.pullMutableState(token, socket, store), [token.key])\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function usePullMutableFamilyMember<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(token: AtomIO.MutableAtomToken<T, J>): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(\n\t\t() => RTC.pullMutableFamilyMember(token, socket, store),\n\t\t[token.key],\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function usePush<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tReact.useEffect(\n\t\t() => RTC.pushState(token, socket, `use-push:${id}`, store),\n\t\t[token.key],\n\t)\n}\n","import * as AtomIO from \"atom.io\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function useServerAction<ƒ extends AtomIO.ƒn>(\n\ttoken: AtomIO.TransactionToken<ƒ>,\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n\tconst store = React.useContext(StoreContext)\n\tconst { socket } = React.useContext(RealtimeContext)\n\tReact.useEffect(\n\t\t() => RTC.synchronizeTransactionResults(token, socket, store),\n\t\t[token.key],\n\t)\n\treturn AtomIO.runTransaction(token, store)\n}\n"]}
|