atom.io 0.4.0 → 0.5.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 (59) hide show
  1. package/README.md +38 -10
  2. package/dist/index.d.mts +598 -0
  3. package/dist/index.d.ts +52 -14
  4. package/dist/index.js +143 -28
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +142 -28
  7. package/dist/index.mjs.map +1 -1
  8. package/json/dist/index.d.mts +18 -0
  9. package/json/dist/index.d.ts +18 -0
  10. package/json/dist/index.js +51 -0
  11. package/json/dist/index.js.map +1 -0
  12. package/json/dist/index.mjs +15 -0
  13. package/json/dist/index.mjs.map +1 -0
  14. package/json/package.json +15 -0
  15. package/package.json +35 -8
  16. package/react/dist/index.d.mts +17 -0
  17. package/react-devtools/dist/index.d.mts +15 -0
  18. package/react-devtools/dist/index.js +13 -10
  19. package/react-devtools/dist/index.js.map +1 -1
  20. package/react-devtools/dist/index.mjs +10 -7
  21. package/react-devtools/dist/index.mjs.map +1 -1
  22. package/realtime/dist/index.d.mts +25 -0
  23. package/realtime/dist/index.d.ts +25 -0
  24. package/realtime/dist/index.js +168 -0
  25. package/realtime/dist/index.js.map +1 -0
  26. package/realtime/dist/index.mjs +130 -0
  27. package/realtime/dist/index.mjs.map +1 -0
  28. package/realtime/package.json +15 -0
  29. package/src/index.ts +22 -0
  30. package/src/internal/atom-internal.ts +1 -1
  31. package/src/internal/families-internal.ts +3 -3
  32. package/src/internal/get.ts +22 -12
  33. package/src/internal/selector-internal.ts +10 -0
  34. package/src/internal/set.ts +1 -1
  35. package/src/internal/store.ts +1 -1
  36. package/src/internal/subscribe-internal.ts +5 -0
  37. package/src/internal/timeline-internal.ts +13 -1
  38. package/src/internal/transaction-internal.ts +24 -9
  39. package/src/json/index.ts +1 -0
  40. package/src/json/select-json.ts +18 -0
  41. package/src/react-devtools/TokenList.tsx +13 -5
  42. package/src/react-explorer/explorer-states.ts +5 -5
  43. package/src/react-explorer/index.ts +1 -1
  44. package/src/react-explorer/space-states.ts +6 -7
  45. package/src/realtime/hook-composition/expose-family.ts +101 -0
  46. package/src/realtime/hook-composition/expose-single.ts +38 -0
  47. package/src/realtime/hook-composition/index.ts +11 -0
  48. package/src/realtime/hook-composition/receive-transaction.ts +19 -0
  49. package/src/realtime/index.ts +1 -0
  50. package/src/realtime-client/hook-composition/compose-realtime-hooks.ts +62 -0
  51. package/src/realtime-client/hook-composition/realtime-client-family-member.ts +28 -0
  52. package/src/realtime-client/hook-composition/realtime-client-family.ts +26 -0
  53. package/src/realtime-client/hook-composition/realtime-client-single.ts +24 -0
  54. package/src/realtime-client/hook-composition/realtime-client-transaction.ts +35 -0
  55. package/src/realtime-client/index.ts +1 -0
  56. package/src/selector.ts +9 -6
  57. package/src/silo.ts +45 -0
  58. package/src/subscribe.ts +13 -1
  59. package/src/transaction.ts +13 -4
package/src/silo.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { type timeline, getState, setState, subscribe } from "."
2
+ import type { atom, atomFamily } from "./atom"
3
+ import {
4
+ type Store,
5
+ atomFamily__INTERNAL,
6
+ atom__INTERNAL,
7
+ createStore,
8
+ selectorFamily__INTERNAL,
9
+ selector__INTERNAL,
10
+ timeline__INTERNAL,
11
+ transaction__INTERNAL,
12
+ } from "./internal"
13
+ import type { selector, selectorFamily } from "./selector"
14
+ import type { transaction } from "./transaction"
15
+
16
+ export type Silo = ReturnType<typeof silo>
17
+
18
+ export const silo = (
19
+ name: string
20
+ ): {
21
+ store: Store
22
+ atom: typeof atom
23
+ atomFamily: typeof atomFamily
24
+ selector: typeof selector
25
+ selectorFamily: typeof selectorFamily
26
+ transaction: typeof transaction
27
+ timeline: typeof timeline
28
+ getState: typeof getState
29
+ setState: typeof setState
30
+ subscribe: typeof subscribe
31
+ } => {
32
+ const store = createStore(name)
33
+ return {
34
+ store,
35
+ atom: (options) => atom__INTERNAL(options, undefined, store),
36
+ atomFamily: (options) => atomFamily__INTERNAL(options, store),
37
+ selector: (options) => selector__INTERNAL(options, undefined, store) as any,
38
+ selectorFamily: (options) => selectorFamily__INTERNAL(options, store) as any,
39
+ transaction: (options) => transaction__INTERNAL(options, store),
40
+ timeline: (options) => timeline__INTERNAL(options, store),
41
+ getState: (token) => getState(token, store),
42
+ setState: (token, newValue) => setState(token, newValue, store),
43
+ subscribe: (token, handler) => subscribe(token, handler, store),
44
+ }
45
+ }
package/src/subscribe.ts CHANGED
@@ -1,4 +1,6 @@
1
- import type { ReadonlySelectorToken, StateToken, TransactionToken, ƒn } from "."
1
+ import type { ƒn } from "~/packages/anvl/src/function"
2
+
3
+ import type { ReadonlySelectorToken, StateToken, TransactionToken } from "."
2
4
  import type { Store, TransactionUpdate } from "./internal"
3
5
  import { IMPLICIT, subscribeToRootAtoms, withdraw } from "./internal"
4
6
 
@@ -11,6 +13,11 @@ export const subscribe = <T>(
11
13
  store: Store = IMPLICIT.STORE
12
14
  ): (() => void) => {
13
15
  const state = withdraw<T>(token, store)
16
+ if (state === null) {
17
+ throw new Error(
18
+ `State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
19
+ )
20
+ }
14
21
  const subscription = state.subject.subscribe(handleUpdate)
15
22
  store.config.logger?.info(`👀 subscribe to "${state.key}"`)
16
23
  const dependencySubscriptions =
@@ -45,6 +52,11 @@ export const subscribeToTransaction = <ƒ extends ƒn>(
45
52
  store = IMPLICIT.STORE
46
53
  ): (() => void) => {
47
54
  const tx = withdraw(token, store)
55
+ if (tx === null) {
56
+ throw new Error(
57
+ `Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
58
+ )
59
+ }
48
60
  store.config.logger?.info(`👀 subscribe to transaction "${token.key}"`)
49
61
  const subscription = tx.subject.subscribe(handleUpdate)
50
62
  const unsubscribe = () => {
@@ -1,11 +1,11 @@
1
1
  import type * as Rx from "rxjs"
2
2
 
3
+ import type { ƒn } from "~/packages/anvl/src/function"
4
+
3
5
  import type { ReadonlySelectorToken, StateToken, TransactionToken } from "."
4
6
  import type { Store, TransactionUpdate } from "./internal"
5
7
  import { IMPLICIT, transaction__INTERNAL, withdraw } from "./internal"
6
8
 
7
- export type ƒn = (...parameters: any[]) => any
8
-
9
9
  export type Transactors = {
10
10
  get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S
11
11
  set: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void
@@ -33,6 +33,8 @@ export type Transaction<ƒ extends ƒn> = {
33
33
  run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>
34
34
  subject: Rx.Subject<TransactionUpdate<ƒ>>
35
35
  }
36
+ export type TransactionIO<Token extends TransactionToken<any>> =
37
+ Token extends TransactionToken<infer ƒ> ? ƒ : never
36
38
 
37
39
  export function transaction<ƒ extends ƒn>(
38
40
  options: TransactionOptions<ƒ>
@@ -42,5 +44,12 @@ export function transaction<ƒ extends ƒn>(
42
44
 
43
45
  export const runTransaction =
44
46
  <ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>
45
- (...parameters: Parameters<ƒ>): ReturnType<ƒ> =>
46
- withdraw(token, store).run(...parameters)
47
+ (...parameters: Parameters<ƒ>): ReturnType<ƒ> => {
48
+ const tx = withdraw(token, store)
49
+ if (tx) {
50
+ return tx.run(...parameters)
51
+ }
52
+ throw new Error(
53
+ `Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
54
+ )
55
+ }