atom.io 0.19.1 → 0.19.3

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 (117) hide show
  1. package/data/dist/index.cjs +99 -79
  2. package/data/dist/index.js +3 -3
  3. package/data/package.json +1 -1
  4. package/data/src/join.ts +67 -50
  5. package/dist/{chunk-YDOGCZ53.js → chunk-ATKDGVTV.js} +29 -29
  6. package/dist/{chunk-7VCCW45K.js → chunk-CC7IF7QF.js} +4 -3
  7. package/dist/{chunk-U2IICNHQ.js → chunk-F2X4B4VY.js} +5 -1
  8. package/dist/{chunk-WX2NCOZR.js → chunk-FTONNX2R.js} +8 -8
  9. package/dist/{chunk-7ZR244C2.js → chunk-MSCJWACE.js} +92 -72
  10. package/dist/index.cjs +14 -7
  11. package/dist/index.d.ts +23 -35
  12. package/dist/index.js +15 -8
  13. package/eslint-plugin/dist/index.cjs +180 -0
  14. package/eslint-plugin/dist/index.js +171 -0
  15. package/eslint-plugin/package.json +16 -0
  16. package/eslint-plugin/src/index.ts +11 -0
  17. package/eslint-plugin/src/rules/index.ts +1 -0
  18. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +190 -0
  19. package/internal/dist/index.cjs +55 -43
  20. package/internal/dist/index.d.ts +20 -20
  21. package/internal/dist/index.js +49 -37
  22. package/internal/package.json +1 -1
  23. package/internal/src/atom/create-regular-atom.ts +7 -5
  24. package/internal/src/atom/delete-atom.ts +2 -2
  25. package/internal/src/families/create-readonly-selector-family.ts +2 -2
  26. package/internal/src/families/create-regular-atom-family.ts +1 -1
  27. package/internal/src/families/create-writable-selector-family.ts +1 -1
  28. package/internal/src/future.ts +4 -2
  29. package/internal/src/lineage.ts +1 -0
  30. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  31. package/internal/src/mutable/create-mutable-atom.ts +7 -5
  32. package/internal/src/mutable/tracker.ts +3 -3
  33. package/internal/src/mutable/transceiver.ts +2 -2
  34. package/internal/src/selector/delete-selector.ts +1 -1
  35. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  36. package/internal/src/store/deposit.ts +5 -5
  37. package/internal/src/store/store.ts +5 -5
  38. package/internal/src/store/withdraw.ts +4 -5
  39. package/internal/src/subject.ts +3 -1
  40. package/internal/src/subscribe/subscribe-to-transaction.ts +4 -4
  41. package/internal/src/timeline/add-atom-to-timeline.ts +13 -8
  42. package/internal/src/timeline/create-timeline.ts +3 -4
  43. package/internal/src/transaction/act-upon-store.ts +5 -5
  44. package/internal/src/transaction/apply-transaction.ts +4 -4
  45. package/internal/src/transaction/build-transaction.ts +9 -6
  46. package/internal/src/transaction/create-transaction.ts +10 -10
  47. package/internal/src/transaction/index.ts +3 -3
  48. package/internal/src/transaction/is-root-store.ts +2 -2
  49. package/introspection/dist/index.d.ts +3 -3
  50. package/introspection/dist/index.js +1 -1
  51. package/introspection/package.json +1 -1
  52. package/introspection/src/attach-introspection-states.ts +3 -3
  53. package/introspection/src/attach-transaction-index.ts +4 -4
  54. package/introspection/src/attach-transaction-logs.ts +8 -4
  55. package/json/dist/index.cjs +6 -2
  56. package/json/dist/index.js +7 -3
  57. package/json/package.json +1 -1
  58. package/json/src/select-json-family.ts +3 -2
  59. package/json/src/select-json.ts +3 -1
  60. package/package.json +258 -241
  61. package/react/dist/index.cjs +9 -3
  62. package/react/dist/index.js +10 -4
  63. package/react/package.json +1 -1
  64. package/react/src/use-i.ts +3 -1
  65. package/react/src/use-tl.ts +6 -2
  66. package/react-devtools/dist/index.cjs +205 -155
  67. package/react-devtools/dist/index.d.ts +3 -5
  68. package/react-devtools/dist/index.js +182 -133
  69. package/react-devtools/package.json +1 -1
  70. package/react-devtools/src/AtomIODevtools.tsx +3 -1
  71. package/react-devtools/src/Button.tsx +3 -1
  72. package/react-devtools/src/StateIndex.tsx +6 -2
  73. package/react-devtools/src/TimelineIndex.tsx +6 -2
  74. package/react-devtools/src/TransactionIndex.tsx +3 -3
  75. package/react-devtools/src/Updates.tsx +24 -13
  76. package/realtime/dist/index.cjs +1 -0
  77. package/realtime/dist/index.d.ts +2 -2
  78. package/realtime/dist/index.js +2 -1
  79. package/realtime/package.json +1 -1
  80. package/realtime/src/realtime-continuity.ts +4 -3
  81. package/realtime-client/dist/index.cjs +29 -29
  82. package/realtime-client/dist/index.d.ts +2 -2
  83. package/realtime-client/dist/index.js +2 -2
  84. package/realtime-client/package.json +1 -1
  85. package/realtime-client/src/server-action.ts +2 -2
  86. package/realtime-client/src/sync-continuity.ts +23 -23
  87. package/realtime-react/dist/index.cjs +29 -29
  88. package/realtime-react/dist/index.d.ts +2 -2
  89. package/realtime-react/dist/index.js +2 -2
  90. package/realtime-react/package.json +1 -1
  91. package/realtime-react/src/use-server-action.ts +3 -3
  92. package/realtime-server/dist/index.cjs +54 -44
  93. package/realtime-server/dist/index.d.ts +5 -5
  94. package/realtime-server/dist/index.js +35 -25
  95. package/realtime-server/package.json +1 -1
  96. package/realtime-server/src/ipc-sockets/child-socket.ts +6 -6
  97. package/realtime-server/src/ipc-sockets/custom-socket.ts +4 -8
  98. package/realtime-server/src/ipc-sockets/parent-socket.ts +13 -7
  99. package/realtime-server/src/realtime-action-receiver.ts +7 -5
  100. package/realtime-server/src/realtime-continuity-synchronizer.ts +3 -3
  101. package/realtime-server/src/realtime-state-receiver.ts +3 -1
  102. package/realtime-testing/dist/index.cjs +15 -13
  103. package/realtime-testing/dist/index.js +10 -8
  104. package/realtime-testing/package.json +1 -1
  105. package/realtime-testing/src/setup-realtime-test.tsx +6 -4
  106. package/src/atom.ts +4 -8
  107. package/src/dispose.ts +1 -0
  108. package/src/index.ts +2 -9
  109. package/src/selector.ts +4 -8
  110. package/src/silo.ts +9 -3
  111. package/src/subscribe.ts +6 -6
  112. package/src/timeline.ts +4 -4
  113. package/src/transaction.ts +24 -24
  114. package/transceivers/set-rtx/dist/index.cjs +11 -12
  115. package/transceivers/set-rtx/dist/index.js +12 -13
  116. package/transceivers/set-rtx/package.json +1 -1
  117. package/transceivers/set-rtx/src/set-rtx.ts +10 -10
@@ -76,12 +76,12 @@ export class ChildSocket<
76
76
  // console.log(`🤓`, this.unprocessedEvents.length)
77
77
  // console.log(`🤓`, ...this.unprocessedEvents.map((x) => x.length))
78
78
  const newInput = this.unprocessedEvents.shift()
79
- this.incompleteData += newInput || ``
79
+ this.incompleteData += newInput ?? ``
80
80
  try {
81
81
  if (this.incompleteData.startsWith(`error`)) {
82
82
  console.log(`❗`, this.incompleteData)
83
83
  }
84
- const parsedEvent = parseJson(this.incompleteData)
84
+ let parsedEvent = parseJson(this.incompleteData)
85
85
  this.handleEvent(...(parsedEvent as [string, ...I[keyof I]]))
86
86
  while (this.unprocessedEvents.length > 0) {
87
87
  const event = this.unprocessedEvents.shift()
@@ -89,7 +89,7 @@ export class ChildSocket<
89
89
  if (this.unprocessedEvents.length === 0) {
90
90
  this.incompleteData = event
91
91
  }
92
- const parsedEvent = parseJson(event)
92
+ parsedEvent = parseJson(event)
93
93
  this.handleEvent(...(parsedEvent as [string, ...I[keyof I]]))
94
94
  }
95
95
  }
@@ -109,15 +109,15 @@ export class ChildSocket<
109
109
  // console.log(`🤫`, this.unprocessedLogs.length)
110
110
  // console.log(`🤫`, ...this.unprocessedLogs.map((x) => x.length))
111
111
  const newInput = this.unprocessedLogs.shift()
112
- this.incompleteLog += newInput || ``
112
+ this.incompleteLog += newInput ?? ``
113
113
  try {
114
- const parsedLog = parseJson(this.incompleteLog)
114
+ let parsedLog = parseJson(this.incompleteLog)
115
115
  // console.log(`🤫`, parsedLog)
116
116
  this.handleLog(parsedLog)
117
117
  while (this.unprocessedLogs.length > 0) {
118
118
  this.incompleteLog = this.unprocessedLogs.shift() ?? ``
119
119
  if (this.incompleteLog) {
120
- const parsedLog = parseJson(this.incompleteLog)
120
+ parsedLog = parseJson(this.incompleteLog)
121
121
  this.handleLog(parsedLog)
122
122
  }
123
123
  }
@@ -49,7 +49,7 @@ export class CustomSocket<I extends Events, O extends Events> implements Socket
49
49
  public on<Event extends keyof I>(
50
50
  event: Event,
51
51
  listener: (...args: I[Event]) => void,
52
- ): CustomSocket<I, O> {
52
+ ): this {
53
53
  const listeners = this.listeners.get(event)
54
54
  if (listeners) {
55
55
  listeners.add(listener)
@@ -59,9 +59,7 @@ export class CustomSocket<I extends Events, O extends Events> implements Socket
59
59
  return this
60
60
  }
61
61
 
62
- public onAny(
63
- listener: (event: string, ...args: Json.Array) => void,
64
- ): CustomSocket<I, O> {
62
+ public onAny(listener: (event: string, ...args: Json.Array) => void): this {
65
63
  this.globalListeners.add(listener)
66
64
  return this
67
65
  }
@@ -69,7 +67,7 @@ export class CustomSocket<I extends Events, O extends Events> implements Socket
69
67
  public off<Event extends keyof I>(
70
68
  event: Event,
71
69
  listener?: (...args: I[Event]) => void,
72
- ): CustomSocket<I, O> {
70
+ ): this {
73
71
  const listeners = this.listeners.get(event)
74
72
  if (listeners) {
75
73
  if (listener) {
@@ -81,9 +79,7 @@ export class CustomSocket<I extends Events, O extends Events> implements Socket
81
79
  return this
82
80
  }
83
81
 
84
- public offAny(
85
- listener: (event: string, ...args: Json.Array) => void,
86
- ): CustomSocket<I, O> {
82
+ public offAny(listener: (event: string, ...args: Json.Array) => void): this {
87
83
  this.globalListeners.delete(listener)
88
84
  return this
89
85
  }
@@ -70,9 +70,15 @@ export class ParentSocket<
70
70
  )
71
71
  }
72
72
  public logger = {
73
- info: (...args: any[]): void => this.log(`i`, ...args),
74
- warn: (...args: any[]): void => this.log(`w`, ...args),
75
- error: (...args: any[]): void => this.log(`e`, ...args),
73
+ info: (...args: any[]): void => {
74
+ this.log(`i`, ...args)
75
+ },
76
+ warn: (...args: any[]): void => {
77
+ this.log(`w`, ...args)
78
+ },
79
+ error: (...args: any[]): void => {
80
+ this.log(`e`, ...args)
81
+ },
76
82
  }
77
83
 
78
84
  public constructor() {
@@ -93,12 +99,12 @@ export class ParentSocket<
93
99
  const chunk = buffer.toString()
94
100
  this.unprocessedEvents.push(...chunk.split(`\x03`))
95
101
  const newInput = this.unprocessedEvents.shift()
96
- this.incompleteData += newInput || ``
102
+ this.incompleteData += newInput ?? ``
97
103
 
98
104
  try {
99
- const parsedEvent = parseJson(this.incompleteData)
100
- this.logger.info(`🎰`, `received`, parsedEvent)
101
- this.handleEvent(...(parsedEvent as [string, ...I[keyof I]]))
105
+ const parsedData = parseJson(this.incompleteData)
106
+ this.logger.info(`🎰`, `received`, parsedData)
107
+ this.handleEvent(...(parsedData as [string, ...I[keyof I]]))
102
108
  while (this.unprocessedEvents.length > 0) {
103
109
  const event = this.unprocessedEvents.shift()
104
110
  if (event) {
@@ -9,17 +9,17 @@ export function realtimeActionReceiver({
9
9
  socket,
10
10
  store = IMPLICIT.STORE,
11
11
  }: ServerConfig) {
12
- return function actionReceiver extends JsonIO>(
13
- tx: AtomIO.TransactionToken<ƒ>,
12
+ return function actionReceiver<F extends JsonIO>(
13
+ tx: AtomIO.TransactionToken<F>,
14
14
  ): () => void {
15
15
  const fillTransactionRequest = (
16
- update: Pick<AtomIO.TransactionUpdate<ƒ>, `id` | `params`>,
16
+ update: Pick<AtomIO.TransactionUpdate<F>, `id` | `params`>,
17
17
  ) => {
18
18
  const performanceKey = `tx-run:${tx.key}:${update.id}`
19
19
  const performanceKeyStart = `${performanceKey}:start`
20
20
  const performanceKeyEnd = `${performanceKey}:end`
21
21
  performance.mark(performanceKeyStart)
22
- actUponStore<ƒ>(tx, update.id, store)(...update.params)
22
+ actUponStore<F>(tx, update.id, store)(...update.params)
23
23
  performance.mark(performanceKeyEnd)
24
24
  const metric = performance.measure(
25
25
  performanceKey,
@@ -30,6 +30,8 @@ export function realtimeActionReceiver({
30
30
  }
31
31
  socket.on(`tx-run:${tx.key}`, fillTransactionRequest)
32
32
 
33
- return () => socket.off(`tx-run:${tx.key}`, fillTransactionRequest)
33
+ return () => {
34
+ socket.off(`tx-run:${tx.key}`, fillTransactionRequest)
35
+ }
34
36
  }
35
37
  }
@@ -91,7 +91,7 @@ export function realtimeContinuitySynchronizer({
91
91
  const unsubscribeFunctions: (() => void)[] = []
92
92
 
93
93
  const revealPerspectives = (): (() => void) => {
94
- const unsubscribeFunctions: (() => void)[] = []
94
+ const unsubFns: (() => void)[] = []
95
95
  for (const perspective of continuity.perspectives) {
96
96
  const { viewAtoms } = perspective
97
97
  const userViewState = findInStore(viewAtoms, userKey, store)
@@ -128,10 +128,10 @@ export function realtimeContinuitySynchronizer({
128
128
  `sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`,
129
129
  store,
130
130
  )
131
- unsubscribeFunctions.push(unsubscribe)
131
+ unsubFns.push(unsubscribe)
132
132
  }
133
133
  return () => {
134
- for (const unsubscribe of unsubscribeFunctions) unsubscribe()
134
+ for (const unsubscribe of unsubFns) unsubscribe()
135
135
  }
136
136
  }
137
137
  const unsubscribeFromPerspectives = revealPerspectives()
@@ -12,7 +12,9 @@ export function realtimeStateReceiver({
12
12
  return function stateReceiver<J extends Json.Serializable>(
13
13
  token: WritableToken<J>,
14
14
  ): () => void {
15
- const publish = (newValue: J) => setIntoStore(token, newValue, store)
15
+ const publish = (newValue: J) => {
16
+ setIntoStore(token, newValue, store)
17
+ }
16
18
 
17
19
  const fillPubUnclaim = () => {
18
20
  socket.off(`pub:${token.key}`, publish)
@@ -74,29 +74,29 @@ function getJoinMap(store) {
74
74
  function getJoin(token, store) {
75
75
  var _a;
76
76
  const joinMap = getJoinMap(store);
77
- let join = joinMap.get(token.key);
78
- if (join === void 0) {
77
+ let myJoin = joinMap.get(token.key);
78
+ if (myJoin === void 0) {
79
79
  const rootJoinMap = getJoinMap(internal.IMPLICIT.STORE);
80
- join = (_a = rootJoinMap.get(token.key)) == null ? void 0 : _a.in(store);
81
- if (join === void 0) {
80
+ myJoin = (_a = rootJoinMap.get(token.key)) == null ? void 0 : _a.in(store);
81
+ if (myJoin === void 0) {
82
82
  throw new Error(
83
83
  `Join "${token.key}" not found in store "${store.config.name}"`
84
84
  );
85
85
  }
86
- joinMap.set(token.key, join);
86
+ joinMap.set(token.key, myJoin);
87
87
  }
88
- return join;
88
+ return myJoin;
89
89
  }
90
90
  function editRelationsInStore(token, change, store) {
91
- const join = getJoin(token, store);
91
+ const myJoin = getJoin(token, store);
92
92
  const target = internal.newest(store);
93
93
  if (internal.isChildStore(target)) {
94
94
  const { transactors } = target.transactionMeta;
95
- join.transact(transactors, ({ relations }) => {
95
+ myJoin.transact(transactors, ({ relations }) => {
96
96
  change(relations);
97
97
  });
98
98
  } else {
99
- change(join.relations);
99
+ change(myJoin.relations);
100
100
  }
101
101
  }
102
102
 
@@ -213,7 +213,9 @@ var setupRealtimeTestClient = (options, name, port) => {
213
213
  container: document.querySelector(`#app`)
214
214
  }
215
215
  );
216
- const prettyPrint = () => console.log(react.prettyDOM(renderResult.container));
216
+ const prettyPrint = () => {
217
+ console.log(react.prettyDOM(renderResult.container));
218
+ };
217
219
  const dispose2 = () => {
218
220
  renderResult.unmount();
219
221
  socket.disconnect();
@@ -245,13 +247,13 @@ var singleClient = (options) => {
245
247
  var multiClient = (options) => {
246
248
  const server = setupRealtimeTestServer(options);
247
249
  const clients = recordToEntries(options.clients).reduce(
248
- (clients2, [name, client]) => {
249
- clients2[name] = setupRealtimeTestClient(
250
+ (clientRecord, [name, client]) => {
251
+ clientRecord[name] = setupRealtimeTestClient(
250
252
  __spreadProps(__spreadValues({}, options), { client }),
251
253
  name,
252
254
  server.port
253
255
  );
254
- return clients2;
256
+ return clientRecord;
255
257
  },
256
258
  {}
257
259
  );
@@ -1,9 +1,9 @@
1
1
  import { myUsernameState } from '../../dist/chunk-O47EQUM6.js';
2
- import { editRelationsInStore } from '../../dist/chunk-7ZR244C2.js';
3
- import '../../dist/chunk-WX2NCOZR.js';
4
- import { recordToEntries } from '../../dist/chunk-7VCCW45K.js';
2
+ import { editRelationsInStore } from '../../dist/chunk-MSCJWACE.js';
3
+ import '../../dist/chunk-FTONNX2R.js';
4
+ import { recordToEntries } from '../../dist/chunk-CC7IF7QF.js';
5
5
  import '../../dist/chunk-BWWVY5O5.js';
6
- import { __spreadProps, __spreadValues } from '../../dist/chunk-U2IICNHQ.js';
6
+ import { __spreadProps, __spreadValues } from '../../dist/chunk-F2X4B4VY.js';
7
7
  import * as http from 'http';
8
8
  import { render, prettyDOM } from '@testing-library/react';
9
9
  import * as AtomIO from 'atom.io';
@@ -90,7 +90,9 @@ var setupRealtimeTestClient = (options, name, port) => {
90
90
  container: document.querySelector(`#app`)
91
91
  }
92
92
  );
93
- const prettyPrint = () => console.log(prettyDOM(renderResult.container));
93
+ const prettyPrint = () => {
94
+ console.log(prettyDOM(renderResult.container));
95
+ };
94
96
  const dispose = () => {
95
97
  renderResult.unmount();
96
98
  socket.disconnect();
@@ -122,13 +124,13 @@ var singleClient = (options) => {
122
124
  var multiClient = (options) => {
123
125
  const server = setupRealtimeTestServer(options);
124
126
  const clients = recordToEntries(options.clients).reduce(
125
- (clients2, [name, client]) => {
126
- clients2[name] = setupRealtimeTestClient(
127
+ (clientRecord, [name, client]) => {
128
+ clientRecord[name] = setupRealtimeTestClient(
127
129
  __spreadProps(__spreadValues({}, options), { client }),
128
130
  name,
129
131
  server.port
130
132
  );
131
- return clients2;
133
+ return clientRecord;
132
134
  },
133
135
  {}
134
136
  );
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "private": true,
5
5
  "main": "dist/index.cjs",
6
- "module": "dist/index.mjs",
6
+ "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
@@ -159,7 +159,9 @@ export const setupRealtimeTestClient = (
159
159
  },
160
160
  )
161
161
 
162
- const prettyPrint = () => console.log(prettyDOM(renderResult.container))
162
+ const prettyPrint = () => {
163
+ console.log(prettyDOM(renderResult.container))
164
+ }
163
165
 
164
166
  const dispose = () => {
165
167
  renderResult.unmount()
@@ -200,13 +202,13 @@ export const multiClient = <ClientNames extends string>(
200
202
  ): RealtimeTestAPI__MultiClient<ClientNames> => {
201
203
  const server = setupRealtimeTestServer(options)
202
204
  const clients = recordToEntries(options.clients).reduce(
203
- (clients, [name, client]) => {
204
- clients[name] = setupRealtimeTestClient(
205
+ (clientRecord, [name, client]) => {
206
+ clientRecord[name] = setupRealtimeTestClient(
205
207
  { ...options, client },
206
208
  name,
207
209
  server.port,
208
210
  )
209
- return clients
211
+ return clientRecord
210
212
  },
211
213
  {} as Record<ClientNames, RealtimeTestClientBuilder>,
212
214
  )
package/src/atom.ts CHANGED
@@ -57,10 +57,8 @@ export type RegularAtomFamilyTokenWithCall<
57
57
  K extends Json.Serializable,
58
58
  > =
59
59
  & RegularAtomFamilyToken<T, K>
60
- & {
61
- /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
62
- (key: K): RegularAtomToken<T>
63
- }
60
+ & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
61
+ ((key: K) => RegularAtomToken<T>)
64
62
  // biome-ignore format: intersection
65
63
  export type RegularAtomFamily<T, K extends Json.Serializable> =
66
64
  & RegularAtomFamilyToken<T, K>
@@ -102,10 +100,8 @@ export type MutableAtomFamilyTokenWithCall<
102
100
  K extends Json.Serializable,
103
101
  > =
104
102
  & MutableAtomFamilyToken<T, J, K>
105
- & {
106
- /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
107
- (key: K): MutableAtomToken<T, J>
108
- }
103
+ & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
104
+ ((key: K) => MutableAtomToken<T, J>)
109
105
  // biome-ignore format: intersection
110
106
  export type MutableAtomFamily<
111
107
  T extends Transceiver<any>,
package/src/dispose.ts CHANGED
@@ -8,6 +8,7 @@ export function dispose(
8
8
  ): void {
9
9
  switch (token.type) {
10
10
  case `atom`:
11
+ case `mutable_atom`:
11
12
  Internal.deleteAtom(token, store)
12
13
  break
13
14
  case `selector`:
package/src/index.ts CHANGED
@@ -1,14 +1,7 @@
1
1
  import type { Transceiver } from "atom.io/internal"
2
2
  import type { Json } from "atom.io/json"
3
+ import type { AtomFamily, AtomFamilyToken } from "./atom"
3
4
  import type {
4
- AtomFamily,
5
- AtomFamilyToken,
6
- RegularAtomFamily,
7
- RegularAtomFamilyToken,
8
- } from "./atom"
9
- import type {
10
- ReadonlySelectorFamily,
11
- ReadonlySelectorFamilyToken,
12
5
  SelectorFamily,
13
6
  SelectorFamilyToken,
14
7
  WritableSelectorFamily,
@@ -28,7 +21,7 @@ export * from "./timeline"
28
21
  export * from "./transaction"
29
22
  export * from "./validators"
30
23
 
31
- export type ƒn = (...parameters: any[]) => any
24
+ export type Func = (...parameters: any[]) => any
32
25
 
33
26
  export type RegularAtomToken<T> = {
34
27
  key: string
package/src/selector.ts CHANGED
@@ -53,10 +53,8 @@ export type WritableSelectorFamilyTokenWithCall<
53
53
  K extends Json.Serializable,
54
54
  > =
55
55
  & WritableSelectorFamilyToken<T, K>
56
- & {
57
- /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
58
- (key: K): WritableSelectorToken<T>
59
- }
56
+ & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
57
+ ((key: K) => WritableSelectorToken<T>)
60
58
  // biome-ignore format: intersection
61
59
  export type WritableSelectorFamily<T, K extends Json.Serializable> =
62
60
  & WritableSelectorFamilyToken<T, K>
@@ -78,10 +76,8 @@ export type ReadonlySelectorFamilyTokenWithCall<
78
76
  K extends Json.Serializable,
79
77
  > =
80
78
  & ReadonlySelectorFamilyToken<T, K>
81
- & {
82
- /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
83
- (key: K): ReadonlySelectorToken<T>
84
- }
79
+ & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
80
+ ((key: K) => ReadonlySelectorToken<T>)
85
81
  // biome-ignore format: intersection
86
82
  export type ReadonlySelectorFamily<T, K extends Json.Serializable> =
87
83
  & ((key: K) => ReadonlySelectorToken<T>)
package/src/silo.ts CHANGED
@@ -85,9 +85,15 @@ export class Silo {
85
85
  this.timeline = (options) => createTimeline(options, s)
86
86
  this.findState = (token, key) => findInStore(token, key, s) as any
87
87
  this.getState = (token) => getFromStore(token, s)
88
- this.setState = (token, newValue) => setIntoStore(token, newValue, s)
88
+ this.setState = (token, newValue) => {
89
+ setIntoStore(token, newValue, s)
90
+ }
89
91
  this.subscribe = (token, handler, key) => subscribe(token, handler, key, s)
90
- this.undo = (token) => timeTravel(`undo`, token, s)
91
- this.redo = (token) => timeTravel(`redo`, token, s)
92
+ this.undo = (token) => {
93
+ timeTravel(`undo`, token, s)
94
+ }
95
+ this.redo = (token) => {
96
+ timeTravel(`redo`, token, s)
97
+ }
92
98
  }
93
99
  }
package/src/subscribe.ts CHANGED
@@ -15,7 +15,7 @@ import type {
15
15
  TimelineUpdate,
16
16
  TransactionToken,
17
17
  TransactionUpdate,
18
- ƒn,
18
+ Func,
19
19
  } from "."
20
20
 
21
21
  export type StateUpdate<T> = { newValue: T; oldValue: T }
@@ -25,8 +25,8 @@ export type KeyedStateUpdate<T> = StateUpdate<T> & {
25
25
  }
26
26
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
27
27
 
28
- export type TransactionUpdateHandler extends ƒn> = (
29
- data: TransactionUpdate<ƒ>,
28
+ export type TransactionUpdateHandler<F extends Func> = (
29
+ data: TransactionUpdate<F>,
30
30
  ) => void
31
31
 
32
32
  export function subscribe<T>(
@@ -35,9 +35,9 @@ export function subscribe<T>(
35
35
  key?: string,
36
36
  store?: Store,
37
37
  ): () => void
38
- export function subscribe extends ƒn>(
39
- token: TransactionToken<ƒ>,
40
- handleUpdate: TransactionUpdateHandler<ƒ>,
38
+ export function subscribe<F extends Func>(
39
+ token: TransactionToken<F>,
40
+ handleUpdate: TransactionUpdateHandler<F>,
41
41
  key?: string,
42
42
  store?: Store,
43
43
  ): () => void
package/src/timeline.ts CHANGED
@@ -36,10 +36,10 @@ export const timeline = <ManagedAtom extends TimelineManageable>(
36
36
  return createTimeline(options, IMPLICIT.STORE)
37
37
  }
38
38
 
39
- export const redo = (timeline: TimelineToken<any>): void => {
40
- timeTravel(`redo`, timeline, IMPLICIT.STORE)
39
+ export const redo = (tl: TimelineToken<any>): void => {
40
+ timeTravel(`redo`, tl, IMPLICIT.STORE)
41
41
  }
42
42
 
43
- export const undo = (timeline: TimelineToken<any>): void => {
44
- timeTravel(`undo`, timeline, IMPLICIT.STORE)
43
+ export const undo = (tl: TimelineToken<any>): void => {
44
+ timeTravel(`undo`, tl, IMPLICIT.STORE)
45
45
  }
@@ -11,10 +11,10 @@ import type {
11
11
  ReadonlySelectorToken,
12
12
  WritableToken,
13
13
  findState,
14
- ƒn,
14
+ Func,
15
15
  } from "."
16
16
 
17
- export type TransactionToken<F> = {
17
+ export type TransactionToken<F extends Func> = {
18
18
  key: string
19
19
  type: `transaction`
20
20
  __F?: F
@@ -22,15 +22,15 @@ export type TransactionToken<F> = {
22
22
 
23
23
  export type TransactionUpdateContent =
24
24
  | KeyedStateUpdate<unknown>
25
- | TransactionUpdate<ƒn>
25
+ | TransactionUpdate<Func>
26
26
 
27
- export type TransactionUpdate extends ƒn> = {
27
+ export type TransactionUpdate<F extends Func> = {
28
28
  key: string
29
29
  id: string
30
30
  epoch: number
31
31
  updates: TransactionUpdateContent[]
32
- params: Parameters<ƒ>
33
- output: ReturnType<ƒ>
32
+ params: Parameters<F>
33
+ output: ReturnType<F>
34
34
  }
35
35
 
36
36
  export type Transactors = Readonly<{
@@ -53,38 +53,38 @@ export type TransactorsWithRunAndEnv = Readonly<{
53
53
  }>
54
54
  export type ReadonlyTransactors = Pick<Transactors, `find` | `get`>
55
55
 
56
- export type Read extends ƒn> = (
56
+ export type Read<F extends Func> = (
57
57
  transactors: ReadonlyTransactors,
58
- ...parameters: Parameters<ƒ>
59
- ) => ReturnType<ƒ>
58
+ ...parameters: Parameters<F>
59
+ ) => ReturnType<F>
60
60
 
61
- export type Write extends ƒn> = (
61
+ export type Write<F extends Func> = (
62
62
  transactors: Transactors,
63
- ...parameters: Parameters<ƒ>
64
- ) => ReturnType<ƒ>
63
+ ...parameters: Parameters<F>
64
+ ) => ReturnType<F>
65
65
 
66
- export type Transact extends ƒn> = (
66
+ export type Transact<F extends Func> = (
67
67
  transactors: TransactorsWithRunAndEnv,
68
- ...parameters: Parameters<ƒ>
69
- ) => ReturnType<ƒ>
68
+ ...parameters: Parameters<F>
69
+ ) => ReturnType<F>
70
70
 
71
- export type TransactionOptions extends ƒn> = {
71
+ export type TransactionOptions<F extends Func> = {
72
72
  key: string
73
- do: Transact<ƒ>
73
+ do: Transact<F>
74
74
  }
75
75
 
76
76
  export type TransactionIO<Token extends TransactionToken<any>> =
77
- Token extends TransactionToken<infer ƒ> ? ƒ : never
77
+ Token extends TransactionToken<infer F> ? F : never
78
78
 
79
- export function transaction extends ƒn>(
80
- options: TransactionOptions<ƒ>,
81
- ): TransactionToken<ƒ> {
79
+ export function transaction<F extends Func>(
80
+ options: TransactionOptions<F>,
81
+ ): TransactionToken<F> {
82
82
  return createTransaction(options, IMPLICIT.STORE)
83
83
  }
84
84
 
85
- export function runTransaction extends ƒn>(
86
- token: TransactionToken<ƒ>,
85
+ export function runTransaction<F extends Func>(
86
+ token: TransactionToken<F>,
87
87
  id = arbitrary(),
88
- ): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {
88
+ ): (...parameters: Parameters<F>) => ReturnType<F> {
89
89
  return actUponStore(token, id, IMPLICIT.STORE)
90
90
  }
@@ -87,7 +87,7 @@ var SetRTX = class _SetRTX extends Set {
87
87
  this.emit(`tx:${this.transactionUpdates.join(`;`)}`);
88
88
  }
89
89
  } catch (thrown) {
90
- console.error(`Failed to apply transaction to SetRTX: ${thrown}`);
90
+ console.error(`Failed to apply transaction to SetRTX:`, thrown);
91
91
  throw thrown;
92
92
  } finally {
93
93
  unsubscribe();
@@ -100,10 +100,9 @@ var SetRTX = class _SetRTX extends Set {
100
100
  return this.subject.subscribe(key, fn);
101
101
  }
102
102
  subscribe(key, fn) {
103
- return this.subject.subscribe(
104
- key,
105
- (update) => fn(`${this.cacheUpdateNumber}=${update}`)
106
- );
103
+ return this.subject.subscribe(key, (update) => {
104
+ fn(`${this.cacheUpdateNumber}=${update}`);
105
+ });
107
106
  }
108
107
  emit(update) {
109
108
  this.subject.next(update);
@@ -123,8 +122,8 @@ var SetRTX = class _SetRTX extends Set {
123
122
  this.delete(json.parseJson(value));
124
123
  break;
125
124
  case `tx`:
126
- for (const update2 of value.split(`;`)) {
127
- this.doStep(update2);
125
+ for (const subUpdate of value.split(`;`)) {
126
+ this.doStep(subUpdate);
128
127
  }
129
128
  }
130
129
  }
@@ -158,12 +157,12 @@ var SetRTX = class _SetRTX extends Set {
158
157
  let done = false;
159
158
  while (!done) {
160
159
  this.cacheIdx %= this.cacheLimit;
161
- const update2 = this.cache[this.cacheIdx];
160
+ const u = this.cache[this.cacheIdx];
162
161
  this.cacheIdx--;
163
- if (!update2) {
162
+ if (!u) {
164
163
  return `OUT_OF_RANGE`;
165
164
  }
166
- this.undo(update2);
165
+ this.undo(u);
167
166
  done = this.cacheIdx === eventIdx - 1;
168
167
  }
169
168
  const innerUpdate = update.substring(breakpoint + 1);
@@ -187,8 +186,8 @@ var SetRTX = class _SetRTX extends Set {
187
186
  break;
188
187
  case `clear`: {
189
188
  const values = JSON.parse(value);
190
- for (const value2 of values)
191
- this.add(value2);
189
+ for (const v of values)
190
+ this.add(v);
192
191
  break;
193
192
  }
194
193
  case `tx`: {