atom.io 0.34.2 → 0.36.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.
Files changed (113) hide show
  1. package/dist/eslint-plugin/index.d.ts +2 -18
  2. package/dist/eslint-plugin/index.d.ts.map +1 -1
  3. package/dist/eslint-plugin/index.js +4 -141
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +74 -77
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +197 -202
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/json/index.d.ts +9 -17
  10. package/dist/json/index.d.ts.map +1 -1
  11. package/dist/json/index.js +3 -33
  12. package/dist/json/index.js.map +1 -1
  13. package/dist/main/index.d.ts +689 -795
  14. package/dist/main/index.d.ts.map +1 -1
  15. package/dist/main/index.js +55 -23
  16. package/dist/main/index.js.map +1 -1
  17. package/dist/react/index.d.ts +4 -4
  18. package/dist/react/index.d.ts.map +1 -1
  19. package/dist/react/index.js.map +1 -1
  20. package/dist/react-devtools/index.d.ts.map +1 -1
  21. package/dist/react-devtools/index.js +10 -10
  22. package/dist/react-devtools/index.js.map +1 -1
  23. package/dist/realtime/index.d.ts +4 -4
  24. package/dist/realtime/index.d.ts.map +1 -1
  25. package/dist/realtime/index.js +5 -11
  26. package/dist/realtime/index.js.map +1 -1
  27. package/dist/realtime-client/index.d.ts +2 -2
  28. package/dist/realtime-client/index.d.ts.map +1 -1
  29. package/dist/realtime-client/index.js +10 -10
  30. package/dist/realtime-client/index.js.map +1 -1
  31. package/dist/realtime-react/index.d.ts +2 -2
  32. package/dist/realtime-react/index.d.ts.map +1 -1
  33. package/dist/realtime-react/index.js.map +1 -1
  34. package/dist/realtime-server/index.d.ts +18 -18
  35. package/dist/realtime-server/index.d.ts.map +1 -1
  36. package/dist/realtime-server/index.js +13 -19
  37. package/dist/realtime-server/index.js.map +1 -1
  38. package/dist/transceivers/set-rtx/index.d.ts +1 -1
  39. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  40. package/dist/transceivers/set-rtx/index.js.map +1 -1
  41. package/package.json +7 -7
  42. package/src/eslint-plugin/index.ts +0 -1
  43. package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
  44. package/src/eslint-plugin/rules/index.ts +0 -1
  45. package/src/internal/atom/create-regular-atom.ts +1 -0
  46. package/src/internal/atom/dispose-atom.ts +1 -0
  47. package/src/internal/atom/index.ts +0 -1
  48. package/src/internal/families/find-in-store.ts +4 -5
  49. package/src/internal/families/get-family-of-token.ts +4 -5
  50. package/src/internal/families/index.ts +0 -1
  51. package/src/internal/families/init-family-member.ts +3 -4
  52. package/src/internal/families/seek-in-store.ts +4 -5
  53. package/src/internal/get-state/read-or-compute-value.ts +14 -2
  54. package/src/internal/index.ts +116 -96
  55. package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
  56. package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
  57. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  58. package/src/internal/join/join-internal.ts +6 -18
  59. package/src/internal/molecule.ts +1 -0
  60. package/src/internal/mutable/create-mutable-atom-family.ts +37 -21
  61. package/src/internal/mutable/create-mutable-atom.ts +17 -13
  62. package/src/internal/mutable/get-json-family.ts +7 -6
  63. package/src/internal/mutable/get-json-token.ts +6 -13
  64. package/src/internal/mutable/get-update-family.ts +7 -8
  65. package/src/internal/mutable/get-update-token.ts +5 -9
  66. package/src/internal/mutable/tracker-family.ts +10 -13
  67. package/src/internal/mutable/tracker.ts +66 -90
  68. package/src/internal/mutable/transceiver.ts +35 -8
  69. package/src/internal/selector/dispose-selector.ts +9 -9
  70. package/src/internal/selector/register-selector.ts +2 -2
  71. package/src/internal/set-state/copy-mutable-if-needed.ts +8 -6
  72. package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
  73. package/src/internal/set-state/set-atom.ts +1 -1
  74. package/src/internal/store/counterfeit.ts +3 -4
  75. package/src/internal/store/deposit.ts +7 -9
  76. package/src/internal/store/store.ts +2 -2
  77. package/src/internal/store/withdraw.ts +7 -11
  78. package/src/json/entries.ts +7 -7
  79. package/src/json/index.ts +0 -2
  80. package/src/main/atom.ts +68 -127
  81. package/src/main/dispose-state.ts +4 -6
  82. package/src/main/find-state.ts +6 -13
  83. package/src/main/get-state.ts +0 -2
  84. package/src/main/index.ts +1 -176
  85. package/src/main/join.ts +2 -9
  86. package/src/main/logger.ts +7 -7
  87. package/src/main/reset-state.ts +0 -2
  88. package/src/main/selector.ts +5 -72
  89. package/src/main/set-state.ts +1 -4
  90. package/src/main/silo.ts +14 -5
  91. package/src/main/subscribe.ts +0 -7
  92. package/src/main/timeline.ts +1 -18
  93. package/src/main/tokens.ts +245 -0
  94. package/src/main/transaction.ts +28 -60
  95. package/src/main/validators.ts +2 -2
  96. package/src/react/use-json.ts +15 -25
  97. package/src/react-devtools/store.ts +61 -45
  98. package/src/realtime/shared-room-store.ts +12 -25
  99. package/src/realtime-client/pull-mutable-atom-family-member.ts +5 -9
  100. package/src/realtime-client/pull-mutable-atom.ts +5 -9
  101. package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
  102. package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
  103. package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
  104. package/src/realtime-server/realtime-mutable-provider.ts +2 -3
  105. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
  106. package/src/realtime-server/realtime-server-stores/server-user-store.ts +9 -18
  107. package/src/transceivers/set-rtx/set-rtx.ts +1 -1
  108. package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
  109. package/src/eslint-plugin/walk.ts +0 -81
  110. package/src/internal/atom/create-standalone-atom.ts +0 -39
  111. package/src/internal/families/create-atom-family.ts +0 -38
  112. package/src/json/select-json-family.ts +0 -55
  113. package/src/json/select-json.ts +0 -19
@@ -1,19 +1,15 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, Store, Transceiver } from "atom.io/internal"
3
3
  import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
4
- import type { Json } from "atom.io/json"
5
4
  import { parseJson } from "atom.io/json"
6
5
  import type { Socket } from "socket.io-client"
7
6
 
8
7
  /* eslint-disable no-console */
9
8
 
10
- export function pullMutableAtomFamilyMember<
11
- T extends Transceiver<any>,
12
- J extends Json.Serializable,
13
- >(
9
+ export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
14
10
  store: Store,
15
11
  socket: Socket,
16
- token: AtomIO.MutableAtomToken<T, J>,
12
+ token: AtomIO.MutableAtomToken<T>,
17
13
  ): () => void {
18
14
  if (!(`family` in token)) {
19
15
  console.error(`Token is not a family member:`, token)
@@ -21,13 +17,13 @@ export function pullMutableAtomFamilyMember<
21
17
  }
22
18
  const { key: familyKey, subKey: serializedSubKey } = token.family
23
19
  const subKey = parseJson(serializedSubKey)
24
- socket.on(`init:${token.key}`, (data: J) => {
20
+ socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
25
21
  const jsonToken = getJsonToken(store, token)
26
22
  setIntoStore(store, jsonToken, data)
27
23
  })
28
24
  socket.on(
29
25
  `next:${token.key}`,
30
- (data: T extends Transceiver<infer Signal> ? Signal : never) => {
26
+ (data: T extends Transceiver<infer Signal, any> ? Signal : never) => {
31
27
  const trackerToken = getUpdateToken(token)
32
28
  setIntoStore(store, trackerToken, data)
33
29
  },
@@ -1,25 +1,21 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, Store, Transceiver } from "atom.io/internal"
3
3
  import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
4
- import type { Json } from "atom.io/json"
5
4
  import type { Socket } from "socket.io-client"
6
5
 
7
- export function pullMutableAtom<
8
- T extends Transceiver<any>,
9
- J extends Json.Serializable,
10
- >(
6
+ export function pullMutableAtom<T extends Transceiver<any, any>>(
11
7
  store: Store,
12
8
  socket: Socket,
13
- token: AtomIO.MutableAtomToken<T, J>,
9
+ token: AtomIO.MutableAtomToken<T>,
14
10
  ): () => void {
15
11
  const jsonToken = getJsonToken(store, token)
16
12
  const updateToken = getUpdateToken(token)
17
- socket.on(`init:${token.key}`, (data: J) => {
13
+ socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
18
14
  setIntoStore(store, jsonToken, data)
19
15
  })
20
16
  socket.on(
21
17
  `next:${token.key}`,
22
- (data: T extends Transceiver<infer Update> ? Update : never) => {
18
+ (data: T extends Transceiver<infer Update, any> ? Update : never) => {
23
19
  setIntoStore(store, updateToken, data)
24
20
  },
25
21
  )
@@ -1,16 +1,14 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { Transceiver } from "atom.io/internal"
3
- import type { Json } from "atom.io/json"
4
3
  import { StoreContext, useO } from "atom.io/react"
5
4
  import * as RTC from "atom.io/realtime-client"
6
5
  import * as React from "react"
7
6
 
8
7
  import { useRealtimeService } from "./use-realtime-service"
9
8
 
10
- export function usePullMutable<
11
- T extends Transceiver<any>,
12
- J extends Json.Serializable,
13
- >(token: AtomIO.MutableAtomToken<T, J>): T {
9
+ export function usePullMutable<T extends Transceiver<any, any>>(
10
+ token: AtomIO.MutableAtomToken<T>,
11
+ ): T {
14
12
  const store = React.useContext(StoreContext)
15
13
  useRealtimeService(`pull:${token.key}`, (socket) =>
16
14
  RTC.pullMutableAtom(store, socket, token),
@@ -1,7 +1,7 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { Transceiver } from "atom.io/internal"
3
3
  import { findInStore } from "atom.io/internal"
4
- import type { Canonical, Json } from "atom.io/json"
4
+ import type { Canonical } from "atom.io/json"
5
5
  import { StoreContext, useO } from "atom.io/react"
6
6
  import * as RTC from "atom.io/realtime-client"
7
7
  import * as React from "react"
@@ -9,11 +9,10 @@ import * as React from "react"
9
9
  import { useRealtimeService } from "./use-realtime-service"
10
10
 
11
11
  export function usePullMutableAtomFamilyMember<
12
- T extends Transceiver<any>,
13
- J extends Json.Serializable,
12
+ T extends Transceiver<any, any>,
14
13
  K extends Canonical,
15
14
  Key extends K,
16
- >(familyToken: AtomIO.MutableAtomFamilyToken<T, J, K>, key: Key): T {
15
+ >(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: Key): T {
17
16
  const store = React.useContext(StoreContext)
18
17
  const token = findInStore(store, familyToken, key)
19
18
  useRealtimeService(`pull:${token.key}`, (socket) =>
@@ -8,7 +8,7 @@ import {
8
8
  IMPLICIT,
9
9
  subscribeToState,
10
10
  } from "atom.io/internal"
11
- import type { Canonical, Json } from "atom.io/json"
11
+ import type { Canonical } from "atom.io/json"
12
12
  import { stringifyJson } from "atom.io/json"
13
13
 
14
14
  import type { ServerConfig } from "."
@@ -21,11 +21,10 @@ export function realtimeMutableFamilyProvider({
21
21
  store = IMPLICIT.STORE,
22
22
  }: ServerConfig) {
23
23
  return function mutableFamilyProvider<
24
- T extends Transceiver<any>,
25
- J extends Json.Serializable,
24
+ T extends Transceiver<any, any>,
26
25
  K extends Canonical,
27
26
  >(
28
- family: AtomIO.MutableAtomFamilyToken<T, J, K>,
27
+ family: AtomIO.MutableAtomFamilyToken<T, K>,
29
28
  index: AtomIO.ReadableToken<Iterable<K>>,
30
29
  ): () => void {
31
30
  const unsubCallbacksByKey = new Map<string, () => void>()
@@ -17,9 +17,8 @@ export function realtimeMutableProvider({
17
17
  store = IMPLICIT.STORE,
18
18
  }: ServerConfig) {
19
19
  return function mutableProvider<
20
- Core extends Transceiver<Json.Serializable>,
21
- SerializableCore extends Json.Serializable,
22
- >(token: AtomIO.MutableAtomToken<Core, SerializableCore>): () => void {
20
+ Core extends Transceiver<Json.Serializable, Json.Serializable>,
21
+ >(token: AtomIO.MutableAtomToken<Core>): () => void {
23
22
  let unsubscribeFromStateUpdates: (() => void) | null = null
24
23
 
25
24
  const jsonToken = getJsonToken(store, token)
@@ -7,10 +7,11 @@ import { roomIndex, usersInRooms } from "atom.io/realtime"
7
7
  import type { ChildSocket } from "../ipc-sockets"
8
8
  import type { RoomArguments } from "./server-room-external-store"
9
9
  import { roomArgumentsAtoms, roomSelectors } from "./server-room-external-store"
10
+ import type { RoomKey } from "./server-user-store"
10
11
 
11
12
  export const createRoomTX: AtomIO.TransactionToken<
12
13
  (
13
- roomId: string,
14
+ roomKey: RoomKey,
14
15
  script: string,
15
16
  options?: string[],
16
17
  ) => Loadable<ChildSocket<any, any>>
@@ -62,17 +63,17 @@ export const leaveRoomTX: AtomIO.TransactionToken<
62
63
  })
63
64
  export type LeaveRoomIO = AtomIO.TransactionIO<typeof leaveRoomTX>
64
65
 
65
- export const destroyRoomTX: AtomIO.TransactionToken<(roomId: string) => void> =
66
+ export const destroyRoomTX: AtomIO.TransactionToken<(roomKey: RoomKey) => void> =
66
67
  AtomIO.transaction({
67
68
  key: `destroyRoom`,
68
- do: (tools, roomId) => {
69
+ do: (tools, roomKey) => {
69
70
  editRelationsInStore(
70
71
  usersInRooms,
71
72
  (relations) => {
72
- relations.delete({ room: roomId })
73
+ relations.delete({ room: roomKey })
73
74
  },
74
75
  tools.env().store,
75
76
  )
76
- tools.set(roomIndex, (s) => (s.delete(roomId), s))
77
+ tools.set(roomIndex, (s) => (s.delete(roomKey), s))
77
78
  },
78
79
  })
@@ -4,8 +4,7 @@ import type {
4
4
  MutableAtomToken,
5
5
  RegularAtomFamilyToken,
6
6
  } from "atom.io"
7
- import { atom, atomFamily, join } from "atom.io"
8
- import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
7
+ import { atomFamily, join, mutableAtom } from "atom.io"
9
8
  import { SetRTX } from "atom.io/transceivers/set-rtx"
10
9
 
11
10
  import type { Socket } from ".."
@@ -29,25 +28,17 @@ export const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =
29
28
  default: null,
30
29
  })
31
30
 
32
- export const socketIndex: MutableAtomToken<
33
- SetRTX<SocketKey>,
34
- SetRTXJson<SocketKey>
35
- > = atom<SetRTX<SocketKey>, SetRTXJson<SocketKey>>({
31
+ export const socketIndex: MutableAtomToken<SetRTX<SocketKey>> = mutableAtom<
32
+ SetRTX<SocketKey>
33
+ >({
36
34
  key: `socketsIndex`,
37
- mutable: true,
38
- default: () => new SetRTX(),
39
- toJson: (set) => set.toJSON(),
40
- fromJson: (json) => SetRTX.fromJSON(json),
35
+ class: SetRTX,
41
36
  })
42
- export const userIndex: MutableAtomToken<
43
- SetRTX<UserKey>,
44
- SetRTXJson<UserKey>
45
- > = atom<SetRTX<UserKey>, SetRTXJson<UserKey>>({
37
+ export const userIndex: MutableAtomToken<SetRTX<UserKey>> = mutableAtom<
38
+ SetRTX<UserKey>
39
+ >({
46
40
  key: `usersIndex`,
47
- mutable: true,
48
- default: () => new SetRTX(),
49
- toJson: (set) => set.toJSON(),
50
- fromJson: (json) => SetRTX.fromJSON(json),
41
+ class: SetRTX,
51
42
  })
52
43
  export const usersOfSockets: JoinToken<
53
44
  `user`,
@@ -16,7 +16,7 @@ export interface SetRTXJson<P extends primitive> extends Json.Object {
16
16
  }
17
17
  export class SetRTX<P extends primitive>
18
18
  extends Set<P>
19
- implements Transceiver<NumberedSetUpdate>, Lineage
19
+ implements Transceiver<NumberedSetUpdate, SetRTXJson<P>>, Lineage
20
20
  {
21
21
  public mode: TransceiverMode = `record`
22
22
  public readonly subject: Subject<SetUpdate> = new Subject<SetUpdate>()
@@ -1,140 +0,0 @@
1
- /* eslint-disable @typescript-eslint/switch-exhaustiveness-check */
2
- import type { RuleType } from "@eslint/core"
3
- import type { Rule } from "eslint"
4
- import type * as ESTree from "estree"
5
-
6
- import { walk } from "../walk"
7
-
8
- export const synchronousSelectorDependencies: {
9
- meta: {
10
- type: RuleType
11
- docs: {
12
- description: string
13
- category: string
14
- recommended: boolean
15
- url: string
16
- }
17
- schema: never[]
18
- }
19
- create(context: Rule.RuleContext): Rule.NodeListener
20
- } = {
21
- meta: {
22
- type: `problem`,
23
- docs: {
24
- description: `disallow await before calling get on the parameter's get method inside selector`,
25
- category: `Possible Errors`,
26
- recommended: false,
27
- url: ``, // URL to documentation page for this rule
28
- },
29
- schema: [], // no options
30
- },
31
- create(context) {
32
- return {
33
- CallExpression(node) {
34
- let selectorComputation: ESTree.Node | undefined
35
- if (`name` in node.callee && node.callee.name === `selectorFamily`) {
36
- if (node.arguments[0].type === `ObjectExpression`) {
37
- const selectorLookupProperty = node.arguments[0].properties.find(
38
- (prop): prop is ESTree.Property => {
39
- return (
40
- `key` in prop && `name` in prop.key && prop.key.name === `get`
41
- )
42
- },
43
- )
44
- const selectorLookup = selectorLookupProperty?.value
45
- if (
46
- selectorLookup?.type === `FunctionExpression` ||
47
- selectorLookup?.type === `ArrowFunctionExpression`
48
- ) {
49
- if (selectorLookup.body.type === `BlockStatement`) {
50
- for (const statement of selectorLookup.body.body) {
51
- if (
52
- statement.type === `ReturnStatement` &&
53
- statement.argument
54
- ) {
55
- selectorComputation = statement.argument
56
- }
57
- }
58
- } else if (
59
- selectorLookup.body.type === `FunctionExpression` ||
60
- selectorLookup.body.type === `ArrowFunctionExpression`
61
- ) {
62
- selectorComputation = selectorLookup.body
63
- }
64
- }
65
- }
66
- }
67
- if (`name` in node.callee && node.callee.name === `selector`) {
68
- if (node.arguments[0].type === `ObjectExpression`) {
69
- const selectorComputationProperty =
70
- node.arguments[0].properties.find(
71
- (prop): prop is ESTree.Property => {
72
- return (
73
- `key` in prop &&
74
- `name` in prop.key &&
75
- prop.key.name === `get`
76
- )
77
- },
78
- )
79
- selectorComputation = selectorComputationProperty?.value
80
- }
81
- }
82
- if (
83
- selectorComputation?.type === `FunctionExpression` ||
84
- selectorComputation?.type === `ArrowFunctionExpression`
85
- ) {
86
- const nonDestructuredTransactorsName =
87
- selectorComputation.params[0] &&
88
- `name` in selectorComputation.params[0]
89
- ? selectorComputation.params[0].name
90
- : undefined
91
- let awaited: number | undefined
92
- let awaitNode: ESTree.AwaitExpression | undefined
93
- walk(selectorComputation, (n, depth) => {
94
- // console.log(`${`\t`.repeat(depth)}${n.type} ${n.name ?? ``}`)
95
- if (typeof awaited === `number`) {
96
- if (awaited > depth) {
97
- awaited = undefined
98
- awaitNode = undefined
99
- }
100
- }
101
- switch (n.type) {
102
- case `AwaitExpression`:
103
- awaited = depth
104
- awaitNode = n
105
- break
106
- case `CallExpression`:
107
- if (awaitNode) {
108
- let willReport = false
109
- switch (n.callee.type) {
110
- case `MemberExpression`:
111
- if (
112
- n.callee.object.type === `Identifier` &&
113
- n.callee.object.name ===
114
- nonDestructuredTransactorsName &&
115
- n.callee.property.type === `Identifier` &&
116
- n.callee.property.name === `get`
117
- ) {
118
- willReport = true
119
- }
120
- break
121
- case `Identifier`:
122
- if (n.callee.name === `get`) {
123
- willReport = true
124
- }
125
- break
126
- }
127
- if (willReport) {
128
- context.report({
129
- node: awaitNode,
130
- message: `Using await before calling the 'get' transactor is not allowed.`,
131
- })
132
- }
133
- }
134
- }
135
- })
136
- }
137
- },
138
- }
139
- },
140
- } satisfies Rule.RuleModule
@@ -1,81 +0,0 @@
1
- /* eslint-disable @typescript-eslint/switch-exhaustiveness-check */
2
- import type * as ESTree from "estree"
3
-
4
- export function walk(
5
- node: ESTree.Node,
6
- callback: (node: ESTree.Node, depth: number) => void,
7
- depth = 0,
8
- ): void {
9
- callback(node, depth)
10
-
11
- switch (node.type) {
12
- case `AwaitExpression`:
13
- walk(node.argument, callback, depth + 1)
14
- break
15
- case `FunctionExpression`:
16
- case `ArrowFunctionExpression`:
17
- for (const param of node.params) {
18
- walk(param, callback, depth + 1)
19
- }
20
- walk(node.body, callback, depth + 1)
21
- break
22
- case `BlockStatement`:
23
- for (const statement of node.body) {
24
- walk(statement, callback, depth + 1)
25
- }
26
- break
27
- case `IfStatement`:
28
- walk(node.test, callback, depth)
29
- walk(node.consequent, callback, depth)
30
- if (node.alternate) {
31
- walk(node.alternate, callback, depth)
32
- }
33
- break
34
- case `SwitchStatement`:
35
- walk(node.discriminant, callback, depth + 1)
36
- for (const caseOrDefault of node.cases) {
37
- walk(caseOrDefault, callback, depth)
38
- }
39
- break
40
- case `ReturnStatement`:
41
- if (node.argument) {
42
- walk(node.argument, callback, depth)
43
- }
44
- break
45
- case `SwitchCase`:
46
- if (node.test) {
47
- walk(node.test, callback, depth)
48
- }
49
- for (const statement of node.consequent) {
50
- walk(statement, callback, depth)
51
- }
52
- break
53
- case `VariableDeclaration`:
54
- for (const declaration of node.declarations) {
55
- walk(declaration, callback, depth)
56
- if (declaration.init) {
57
- walk(declaration.init, callback, depth)
58
- }
59
- }
60
- break
61
- case `BinaryExpression`:
62
- walk(node.left, callback, depth)
63
- walk(node.right, callback, depth)
64
- break
65
- case `ConditionalExpression`:
66
- walk(node.test, callback, depth + 1)
67
- walk(node.consequent, callback, depth + 1)
68
- walk(node.alternate, callback, depth + 1)
69
- break
70
- case `MemberExpression`:
71
- walk(node.object, callback, depth)
72
- walk(node.property, callback, depth)
73
- break
74
- case `CallExpression`:
75
- walk(node.callee, callback, depth)
76
- for (const argument of node.arguments) {
77
- walk(argument, callback, depth)
78
- }
79
- break
80
- }
81
- }
@@ -1,39 +0,0 @@
1
- import type {
2
- AtomToken,
3
- MutableAtomOptions,
4
- MutableAtomToken,
5
- RegularAtomOptions,
6
- RegularAtomToken,
7
- } from "atom.io"
8
- import type { Json } from "atom.io/json"
9
-
10
- import type { Transceiver } from "../mutable"
11
- import { createMutableAtom } from "../mutable"
12
- import type { Store } from "../store"
13
- import { createRegularAtom } from "./create-regular-atom"
14
-
15
- export function createStandaloneAtom<T>(
16
- store: Store,
17
- options: RegularAtomOptions<T>,
18
- ): RegularAtomToken<T>
19
-
20
- export function createStandaloneAtom<
21
- T extends Transceiver<any>,
22
- J extends Json.Serializable,
23
- >(store: Store, options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>
24
-
25
- export function createStandaloneAtom<T>(
26
- store: Store,
27
- options: MutableAtomOptions<any, any> | RegularAtomOptions<T>,
28
- ): AtomToken<T> {
29
- const isMutable = `mutable` in options
30
-
31
- if (isMutable) {
32
- const state = createMutableAtom(store, options, undefined)
33
- store.on.atomCreation.next(state)
34
- return state
35
- }
36
- const state = createRegularAtom(store, options, undefined)
37
- store.on.atomCreation.next(state)
38
- return state
39
- }
@@ -1,38 +0,0 @@
1
- import type {
2
- AtomFamilyToken,
3
- MutableAtomFamilyOptions,
4
- MutableAtomFamilyToken,
5
- RegularAtomFamilyOptions,
6
- RegularAtomFamilyToken,
7
- } from "atom.io"
8
- import type { Canonical, Json } from "atom.io/json"
9
-
10
- import { createMutableAtomFamily, type Transceiver } from "../mutable"
11
- import type { Store } from "../store"
12
- import { createRegularAtomFamily } from "./create-regular-atom-family"
13
-
14
- export function createAtomFamily<
15
- T extends Transceiver<any>,
16
- J extends Json.Serializable,
17
- K extends Canonical,
18
- >(
19
- store: Store,
20
- options: MutableAtomFamilyOptions<T, J, K>,
21
- ): MutableAtomFamilyToken<T, J, K>
22
- export function createAtomFamily<T, K extends Canonical>(
23
- store: Store,
24
- options: RegularAtomFamilyOptions<T, K>,
25
- ): RegularAtomFamilyToken<T, K>
26
- export function createAtomFamily<T, K extends Canonical>(
27
- store: Store,
28
- options:
29
- | MutableAtomFamilyOptions<any, any, any>
30
- | RegularAtomFamilyOptions<T, K>,
31
- ): AtomFamilyToken<any, any> {
32
- const isMutable = `mutable` in options
33
-
34
- if (isMutable) {
35
- return createMutableAtomFamily(store, options)
36
- }
37
- return createRegularAtomFamily<T, K>(store, options)
38
- }
@@ -1,55 +0,0 @@
1
- import type * as AtomIO from "atom.io"
2
- import type { Store, Transceiver } from "atom.io/internal"
3
- import { createWritablePureSelectorFamily } from "atom.io/internal"
4
-
5
- import type { Canonical, Json, JsonInterface } from "."
6
-
7
- export function selectJsonFamily<
8
- T extends Transceiver<any>,
9
- J extends Json.Serializable,
10
- K extends Canonical,
11
- >(
12
- store: Store,
13
- atomFamilyToken: AtomIO.MutableAtomFamilyToken<T, J, K>,
14
- transform: JsonInterface<T, J>,
15
- ): AtomIO.WritablePureSelectorFamilyToken<J, K>
16
- export function selectJsonFamily<
17
- T,
18
- J extends Json.Serializable,
19
- K extends Canonical,
20
- >(
21
- store: Store,
22
- atomFamilyToken: AtomIO.RegularAtomFamilyToken<T, K>,
23
- transform: JsonInterface<T, J>,
24
- ): AtomIO.WritablePureSelectorFamilyToken<J, K>
25
- export function selectJsonFamily<
26
- T,
27
- J extends Json.Serializable,
28
- K extends Canonical,
29
- >(
30
- store: Store,
31
- atomFamilyToken:
32
- | AtomIO.MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, J, K>
33
- | AtomIO.RegularAtomFamilyToken<T, K>,
34
- transform: JsonInterface<T, J>,
35
- ): AtomIO.WritablePureSelectorFamilyToken<J, K> {
36
- const jsonFamily = createWritablePureSelectorFamily<J, K>(
37
- store,
38
- {
39
- key: `${atomFamilyToken.key}:JSON`,
40
- get:
41
- (key) =>
42
- ({ get }) => {
43
- const baseState = get(atomFamilyToken, key)
44
- return transform.toJson(baseState)
45
- },
46
- set:
47
- (key) =>
48
- ({ set }, newValue) => {
49
- set(atomFamilyToken, key, transform.fromJson(newValue))
50
- },
51
- },
52
- [`mutable`, `json`],
53
- )
54
- return jsonFamily
55
- }
@@ -1,19 +0,0 @@
1
- import type * as AtomIO from "atom.io"
2
- import type { Store } from "atom.io/internal"
3
- import { createStandaloneSelector, IMPLICIT } from "atom.io/internal"
4
-
5
- import type { Json, JsonInterface } from "."
6
-
7
- export const selectJson = <T, J extends Json.Serializable>(
8
- atom: AtomIO.AtomToken<T>,
9
- transform: JsonInterface<T, J>,
10
- store: Store = IMPLICIT.STORE,
11
- ): AtomIO.WritablePureSelectorToken<J> => {
12
- return createStandaloneSelector(store, {
13
- key: `${atom.key}:JSON`,
14
- get: ({ get }) => transform.toJson(get(atom)),
15
- set: ({ set }, newValue) => {
16
- set(atom, transform.fromJson(newValue))
17
- },
18
- })
19
- }