atom.io 0.6.7 → 0.6.8
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 +27 -17
- package/dist/index.d.ts +27 -17
- package/dist/index.js +28 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -22
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +14 -15
- package/introspection/dist/index.d.ts +14 -15
- package/introspection/dist/index.js +2 -2
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +2 -2
- package/introspection/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +5 -7
- package/json/dist/index.d.ts +5 -7
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs.map +1 -1
- package/package.json +15 -7
- package/react-devtools/dist/index.css +9 -1
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +14 -15
- package/react-devtools/dist/index.d.ts +14 -15
- package/react-devtools/dist/index.js +769 -249
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +752 -227
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime/dist/index.d.mts +6 -8
- package/realtime/dist/index.d.ts +6 -8
- package/realtime/dist/index.js +0 -1
- package/realtime/dist/index.js.map +1 -1
- package/realtime/dist/index.mjs +0 -1
- package/realtime/dist/index.mjs.map +1 -1
- package/realtime-react/dist/index.d.mts +11 -13
- package/realtime-react/dist/index.d.ts +11 -13
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs.map +1 -1
- package/src/atom.ts +4 -4
- package/src/index.ts +1 -1
- package/src/internal/families-internal.ts +23 -20
- package/src/internal/index.ts +1 -1
- package/src/internal/selector/create-read-write-selector.ts +3 -1
- package/src/internal/selector/create-readonly-selector.ts +3 -1
- package/src/internal/time-travel-internal.ts +4 -4
- package/src/internal/timeline/add-atom-to-timeline.ts +2 -2
- package/src/internal/timeline-internal.ts +2 -2
- package/src/introspection/attach-timeline-family.ts +1 -1
- package/src/json/select-json.ts +1 -1
- package/src/react-devtools/StateEditor.tsx +5 -1
- package/src/react-devtools/StateIndex.tsx +4 -1
- package/src/react-devtools/devtools.scss +0 -1
- package/src/realtime/hook-composition/expose-family.ts +2 -2
- package/src/realtime/hook-composition/expose-single.ts +1 -1
- package/src/realtime/hook-composition/receive-state.ts +1 -1
- package/src/realtime-react/realtime-hooks.ts +4 -4
- package/src/realtime-react/use-pull-family-member.ts +2 -2
- package/src/realtime-react/use-pull-family.ts +2 -2
- package/src/realtime-react/use-pull.ts +3 -1
- package/src/realtime-react/use-push.ts +3 -1
- package/src/selector.ts +14 -12
- package/src/subscribe.ts +1 -1
- package/src/tracker/index.ts +3 -0
- package/src/tracker/tracker.ts +61 -0
- package/src/web-effects/storage.ts +1 -1
- package/src/internal/subject.ts +0 -24
|
@@ -31,7 +31,7 @@ export type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
|
|
|
31
31
|
export type Timeline = {
|
|
32
32
|
key: string
|
|
33
33
|
at: number
|
|
34
|
-
timeTraveling:
|
|
34
|
+
timeTraveling: `into_future` | `into_past` | null
|
|
35
35
|
history: TimelineUpdate[]
|
|
36
36
|
selectorTime: number | null
|
|
37
37
|
transactionKey: string | null
|
|
@@ -53,7 +53,7 @@ export function timeline__INTERNAL(
|
|
|
53
53
|
const tl: Timeline = {
|
|
54
54
|
key: options.key,
|
|
55
55
|
at: 0,
|
|
56
|
-
timeTraveling:
|
|
56
|
+
timeTraveling: null,
|
|
57
57
|
selectorTime: null,
|
|
58
58
|
transactionKey: null,
|
|
59
59
|
...data,
|
package/src/json/select-json.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as AtomIO from "atom.io"
|
|
|
2
2
|
|
|
3
3
|
import type { Json, JsonInterface } from "~/packages/anvl/src/json"
|
|
4
4
|
|
|
5
|
-
export const selectJson = <T, J extends Json>(
|
|
5
|
+
export const selectJson = <T, J extends Json.Serializable>(
|
|
6
6
|
atom: AtomIO.AtomToken<T>,
|
|
7
7
|
transform: JsonInterface<T, J>,
|
|
8
8
|
store: AtomIO.Store = AtomIO.__INTERNAL__.IMPLICIT.STORE,
|
|
@@ -3,7 +3,9 @@ import { useO, useIO } from "atom.io/react"
|
|
|
3
3
|
import type { FC } from "react"
|
|
4
4
|
|
|
5
5
|
import { fallback } from "~/packages/anvl/src/function"
|
|
6
|
-
import {
|
|
6
|
+
import { Join } from "~/packages/anvl/src/join"
|
|
7
|
+
import { isJson } from "~/packages/anvl/src/refinement/refine-json"
|
|
8
|
+
import { RelationEditor } from "~/packages/hamr/src/react-data-designer"
|
|
7
9
|
import { ElasticInput } from "~/packages/hamr/src/react-elastic-input"
|
|
8
10
|
import { JsonEditor } from "~/packages/hamr/src/react-json-editor"
|
|
9
11
|
|
|
@@ -13,6 +15,8 @@ export const StateEditor: FC<{
|
|
|
13
15
|
const [data, set] = useIO(token)
|
|
14
16
|
return isJson(data) ? (
|
|
15
17
|
<JsonEditor data={data} set={set} schema={true} />
|
|
18
|
+
) : data instanceof Join ? (
|
|
19
|
+
<RelationEditor data={data} set={set} />
|
|
16
20
|
) : (
|
|
17
21
|
<div className="json_editor">
|
|
18
22
|
<ElasticInput
|
|
@@ -3,7 +3,10 @@ import { getState, selectorFamily } from "atom.io"
|
|
|
3
3
|
import { useO, useIO } from "atom.io/react"
|
|
4
4
|
import type { FC } from "react"
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
isJson,
|
|
8
|
+
refineJsonType,
|
|
9
|
+
} from "~/packages/anvl/src/refinement/refine-json"
|
|
7
10
|
|
|
8
11
|
import { findViewIsOpenState, primitiveRefinery } from "."
|
|
9
12
|
import { button } from "./Button"
|
|
@@ -17,7 +17,7 @@ const subscribeToTokenCreation = <T>(
|
|
|
17
17
|
|
|
18
18
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
19
19
|
export const useExposeFamily = ({ socket, store }: ServerConfig) => {
|
|
20
|
-
return function exposeFamily<J extends Json>(
|
|
20
|
+
return function exposeFamily<J extends Json.Serializable>(
|
|
21
21
|
family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
|
|
22
22
|
index: AtomIO.StateToken<Set<string>>,
|
|
23
23
|
): () => void {
|
|
@@ -39,7 +39,7 @@ export const useExposeFamily = ({ socket, store }: ServerConfig) => {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const fillSubRequest = (subKey?: AtomIO.Serializable) => {
|
|
42
|
+
const fillSubRequest = (subKey?: AtomIO.Json.Serializable) => {
|
|
43
43
|
if (subKey === undefined) {
|
|
44
44
|
const keys = AtomIO.getState(index, store)
|
|
45
45
|
keys.forEach((key) => {
|
|
@@ -5,7 +5,7 @@ import type { ServerConfig } from ".."
|
|
|
5
5
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
7
7
|
export const useExposeSingle = ({ socket, store }: ServerConfig) => {
|
|
8
|
-
return function exposeSingle<J extends Json>(
|
|
8
|
+
return function exposeSingle<J extends Json.Serializable>(
|
|
9
9
|
token: AtomIO.StateToken<J>,
|
|
10
10
|
): () => void {
|
|
11
11
|
let unsubscribeFromStateUpdates: (() => void) | null = null
|
|
@@ -5,7 +5,7 @@ import type { ServerConfig } from ".."
|
|
|
5
5
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
7
7
|
export const useReceiveState = ({ socket, store }: ServerConfig) => {
|
|
8
|
-
return function receiveState<J extends Json>(
|
|
8
|
+
return function receiveState<J extends Json.Serializable>(
|
|
9
9
|
token: AtomIO.StateToken<J>,
|
|
10
10
|
): () => void {
|
|
11
11
|
const publish = (newValue: J) => AtomIO.setState(token, newValue, store)
|
|
@@ -10,15 +10,15 @@ import { usePush } from "./use-push"
|
|
|
10
10
|
import { useServerAction } from "./use-server-action"
|
|
11
11
|
|
|
12
12
|
export type RealtimeHooks = {
|
|
13
|
-
usePull: <J extends Json>(token: AtomIO.StateToken<J>) => void
|
|
14
|
-
usePullFamily: <J extends Json>(
|
|
13
|
+
usePull: <J extends Json.Serializable>(token: AtomIO.StateToken<J>) => void
|
|
14
|
+
usePullFamily: <J extends Json.Serializable>(
|
|
15
15
|
family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
|
|
16
16
|
) => void
|
|
17
|
-
usePullFamilyMember: <J extends Json>(
|
|
17
|
+
usePullFamilyMember: <J extends Json.Serializable>(
|
|
18
18
|
family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
|
|
19
19
|
subKey: string,
|
|
20
20
|
) => void
|
|
21
|
-
usePush: <J extends Json>(token: AtomIO.StateToken<J>) => void
|
|
21
|
+
usePush: <J extends Json.Serializable>(token: AtomIO.StateToken<J>) => void
|
|
22
22
|
useServerAction: <ƒ extends ƒn>(
|
|
23
23
|
token: AtomIO.TransactionToken<ƒ>,
|
|
24
24
|
) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>
|
|
@@ -6,9 +6,9 @@ import type { Json } from "~/packages/anvl/src/json"
|
|
|
6
6
|
import { RealtimeContext } from "./realtime-context"
|
|
7
7
|
import { StoreContext } from "../react"
|
|
8
8
|
|
|
9
|
-
export function usePullFamilyMember<J extends Json>(
|
|
9
|
+
export function usePullFamilyMember<J extends Json.Serializable>(
|
|
10
10
|
family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
|
|
11
|
-
subKey: AtomIO.Serializable,
|
|
11
|
+
subKey: AtomIO.Json.Serializable,
|
|
12
12
|
): void {
|
|
13
13
|
const token = family(subKey)
|
|
14
14
|
const { socket } = React.useContext(RealtimeContext)
|
|
@@ -6,13 +6,13 @@ import type { Json } from "~/packages/anvl/src/json"
|
|
|
6
6
|
import { RealtimeContext } from "./realtime-context"
|
|
7
7
|
import { StoreContext } from "../react"
|
|
8
8
|
|
|
9
|
-
export function usePullFamily<J extends Json>(
|
|
9
|
+
export function usePullFamily<J extends Json.Serializable>(
|
|
10
10
|
family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,
|
|
11
11
|
): void {
|
|
12
12
|
const { socket } = React.useContext(RealtimeContext)
|
|
13
13
|
const store = React.useContext(StoreContext)
|
|
14
14
|
React.useEffect(() => {
|
|
15
|
-
socket.on(`serve:${family.key}`, (key: Json, data: J) => {
|
|
15
|
+
socket.on(`serve:${family.key}`, (key: Json.Serializable, data: J) => {
|
|
16
16
|
AtomIO.setState(family(key), data, store)
|
|
17
17
|
})
|
|
18
18
|
socket?.emit(`sub:${family.key}`)
|
|
@@ -6,7 +6,9 @@ import type { Json } from "~/packages/anvl/src/json"
|
|
|
6
6
|
import { RealtimeContext } from "./realtime-context"
|
|
7
7
|
import { StoreContext } from "../react"
|
|
8
8
|
|
|
9
|
-
export function usePull<J extends Json>(
|
|
9
|
+
export function usePull<J extends Json.Serializable>(
|
|
10
|
+
token: AtomIO.StateToken<J>,
|
|
11
|
+
): void {
|
|
10
12
|
const { socket } = React.useContext(RealtimeContext)
|
|
11
13
|
const store = React.useContext(StoreContext)
|
|
12
14
|
React.useEffect(() => {
|
|
@@ -6,7 +6,9 @@ import type { Json } from "~/packages/anvl/src/json"
|
|
|
6
6
|
import { RealtimeContext } from "./realtime-context"
|
|
7
7
|
import { StoreContext } from "../react"
|
|
8
8
|
|
|
9
|
-
export function usePush<J extends Json>(
|
|
9
|
+
export function usePush<J extends Json.Serializable>(
|
|
10
|
+
token: AtomIO.StateToken<J>,
|
|
11
|
+
): void {
|
|
10
12
|
const { socket } = React.useContext(RealtimeContext)
|
|
11
13
|
const store = React.useContext(StoreContext)
|
|
12
14
|
React.useEffect(() => {
|
package/src/selector.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Json } from "~/packages/anvl/src/json"
|
|
2
2
|
|
|
3
3
|
import type { ReadonlySelectorToken, SelectorToken } from "."
|
|
4
4
|
import type { Subject } from "./internal"
|
|
@@ -25,39 +25,41 @@ export function selector<T>(
|
|
|
25
25
|
return selector__INTERNAL(options)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export type SelectorFamilyOptions<T, K extends Serializable> = {
|
|
28
|
+
export type SelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
29
29
|
key: string
|
|
30
30
|
get: (key: K) => Read<() => T>
|
|
31
31
|
set: (key: K) => Write<(newValue: T) => void>
|
|
32
32
|
}
|
|
33
|
-
export type ReadonlySelectorFamilyOptions<T, K extends Serializable> = {
|
|
33
|
+
export type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
34
34
|
key: string
|
|
35
35
|
get: (key: K) => Read<() => T>
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export type SelectorFamily<
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
export type SelectorFamily<
|
|
39
|
+
T,
|
|
40
|
+
K extends Json.Serializable = Json.Serializable,
|
|
41
|
+
> = ((key: K) => SelectorToken<T>) & {
|
|
41
42
|
key: string
|
|
42
43
|
type: `selector_family`
|
|
43
44
|
subject: Subject<SelectorToken<T>>
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export type ReadonlySelectorFamily<
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
export type ReadonlySelectorFamily<
|
|
48
|
+
T,
|
|
49
|
+
K extends Json.Serializable = Json.Serializable,
|
|
50
|
+
> = ((key: K) => ReadonlySelectorToken<T>) & {
|
|
49
51
|
key: string
|
|
50
52
|
type: `readonly_selector_family`
|
|
51
53
|
subject: Subject<ReadonlySelectorToken<T>>
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
export function selectorFamily<T, K extends Serializable>(
|
|
56
|
+
export function selectorFamily<T, K extends Json.Serializable>(
|
|
55
57
|
options: SelectorFamilyOptions<T, K>,
|
|
56
58
|
): SelectorFamily<T, K>
|
|
57
|
-
export function selectorFamily<T, K extends Serializable>(
|
|
59
|
+
export function selectorFamily<T, K extends Json.Serializable>(
|
|
58
60
|
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
59
61
|
): ReadonlySelectorFamily<T, K>
|
|
60
|
-
export function selectorFamily<T, K extends Serializable>(
|
|
62
|
+
export function selectorFamily<T, K extends Json.Serializable>(
|
|
61
63
|
options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,
|
|
62
64
|
): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {
|
|
63
65
|
return selectorFamily__INTERNAL(options)
|
package/src/subscribe.ts
CHANGED
|
@@ -76,7 +76,7 @@ export const subscribeToTransaction = <ƒ extends ƒn>(
|
|
|
76
76
|
|
|
77
77
|
export const subscribeToTimeline = (
|
|
78
78
|
token: TimelineToken,
|
|
79
|
-
handleUpdate: (update: TimelineUpdate) => void,
|
|
79
|
+
handleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,
|
|
80
80
|
store = IMPLICIT.STORE,
|
|
81
81
|
): (() => void) => {
|
|
82
82
|
const tl = withdraw(token, store)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as AtomIO from "atom.io"
|
|
2
|
+
|
|
3
|
+
import type { Transceiver } from "."
|
|
4
|
+
|
|
5
|
+
export type CacheOptions<Core extends Transceiver<any>> = {
|
|
6
|
+
key: string
|
|
7
|
+
default: Core
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const tracker = <Core extends Transceiver<any>>(
|
|
11
|
+
coreState: AtomIO.AtomToken<Core>,
|
|
12
|
+
store: AtomIO.__INTERNAL__.Store = AtomIO.__INTERNAL__.IMPLICIT.STORE,
|
|
13
|
+
): AtomIO.AtomToken<
|
|
14
|
+
(Core extends Transceiver<infer Signal> ? Signal : never) | null
|
|
15
|
+
> => {
|
|
16
|
+
const trackerKey = `${coreState.key}:signal`
|
|
17
|
+
const trackerState = AtomIO.atom<
|
|
18
|
+
(Core extends Transceiver<infer Signal> ? Signal : never) | null
|
|
19
|
+
>({
|
|
20
|
+
key: trackerKey,
|
|
21
|
+
default: null,
|
|
22
|
+
effects: [
|
|
23
|
+
({ setSelf }) => {
|
|
24
|
+
AtomIO.getState(coreState).observe((update) => setSelf(update))
|
|
25
|
+
},
|
|
26
|
+
({ onSet }) => {
|
|
27
|
+
onSet(({ newValue, oldValue }) => {
|
|
28
|
+
const timelineId = store.timelineAtoms.getRelatedId(trackerKey)
|
|
29
|
+
if (timelineId) {
|
|
30
|
+
const timelineData = store.timelines.get(timelineId)
|
|
31
|
+
if (timelineData?.timeTraveling) {
|
|
32
|
+
const unsubscribe = AtomIO.subscribeToTimeline(
|
|
33
|
+
{ key: timelineId, type: `timeline` },
|
|
34
|
+
(update) => {
|
|
35
|
+
unsubscribe()
|
|
36
|
+
AtomIO.setState(coreState, (core) => {
|
|
37
|
+
if (update === `redo` && newValue) {
|
|
38
|
+
core.do(newValue)
|
|
39
|
+
} else if (update === `undo` && oldValue) {
|
|
40
|
+
core.undo(oldValue)
|
|
41
|
+
}
|
|
42
|
+
return core
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const { unsubscribe } = store.subject.operationStatus.subscribe(() => {
|
|
51
|
+
unsubscribe()
|
|
52
|
+
if (newValue) {
|
|
53
|
+
AtomIO.setState(coreState, (core) => (core.do(newValue), core))
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
})
|
|
60
|
+
return trackerState
|
|
61
|
+
}
|
package/src/internal/subject.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
type Subscriber<T> = (value: T) => void
|
|
2
|
-
|
|
3
|
-
export class Subject<T> {
|
|
4
|
-
public subscribers: Subscriber<T>[] = []
|
|
5
|
-
|
|
6
|
-
public subscribe(subscriber: Subscriber<T>): { unsubscribe: () => void } {
|
|
7
|
-
this.subscribers.push(subscriber)
|
|
8
|
-
const unsubscribe = () => this.unsubscribe(subscriber)
|
|
9
|
-
return { unsubscribe }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
private unsubscribe(subscriber: Subscriber<T>) {
|
|
13
|
-
const subscriberIndex = this.subscribers.indexOf(subscriber)
|
|
14
|
-
if (subscriberIndex !== -1) {
|
|
15
|
-
this.subscribers.splice(subscriberIndex, 1)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public next(value: T): void {
|
|
20
|
-
for (const subscriber of this.subscribers) {
|
|
21
|
-
subscriber(value)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|