atom.io 0.40.0 → 0.40.1

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 (82) hide show
  1. package/dist/internal/index.d.ts +67 -62
  2. package/dist/internal/index.d.ts.map +1 -1
  3. package/dist/internal/index.js +81 -93
  4. package/dist/internal/index.js.map +1 -1
  5. package/dist/introspection/index.d.ts +2 -2
  6. package/dist/introspection/index.d.ts.map +1 -1
  7. package/dist/introspection/index.js.map +1 -1
  8. package/dist/main/index.d.ts +14 -11
  9. package/dist/main/index.d.ts.map +1 -1
  10. package/dist/main/index.js +16 -13
  11. package/dist/main/index.js.map +1 -1
  12. package/dist/react/index.d.ts +3 -3
  13. package/dist/react/index.d.ts.map +1 -1
  14. package/dist/react/index.js.map +1 -1
  15. package/dist/react-devtools/index.js +1 -1
  16. package/dist/react-devtools/index.js.map +1 -1
  17. package/dist/realtime-client/index.d.ts +3 -3
  18. package/dist/realtime-client/index.d.ts.map +1 -1
  19. package/dist/realtime-client/index.js +3 -4
  20. package/dist/realtime-client/index.js.map +1 -1
  21. package/dist/realtime-server/index.d.ts +2 -2
  22. package/dist/realtime-server/index.d.ts.map +1 -1
  23. package/package.json +2 -2
  24. package/src/internal/atom/create-regular-atom.ts +3 -2
  25. package/src/internal/atom/dispose-atom.ts +6 -6
  26. package/src/internal/families/create-readonly-held-selector-family.ts +3 -4
  27. package/src/internal/families/create-readonly-pure-selector-family.ts +4 -9
  28. package/src/internal/families/create-regular-atom-family.ts +3 -4
  29. package/src/internal/families/create-selector-family.ts +6 -6
  30. package/src/internal/families/create-writable-held-selector-family.ts +2 -2
  31. package/src/internal/families/create-writable-pure-selector-family.ts +3 -7
  32. package/src/internal/families/dispose-from-store.ts +9 -2
  33. package/src/internal/get-state/get-from-store.ts +10 -3
  34. package/src/internal/index.ts +8 -8
  35. package/src/internal/install-into-store.ts +2 -1
  36. package/src/internal/join/create-join.ts +2 -2
  37. package/src/internal/join/find-relations-in-store.ts +2 -2
  38. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  39. package/src/internal/join/get-join.ts +5 -2
  40. package/src/internal/join/join-internal.ts +15 -20
  41. package/src/internal/lineage.ts +12 -1
  42. package/src/internal/molecule.ts +64 -36
  43. package/src/internal/mutable/create-mutable-atom-family.ts +4 -4
  44. package/src/internal/mutable/create-mutable-atom.ts +2 -2
  45. package/src/internal/mutable/tracker-family.ts +3 -3
  46. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  47. package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
  48. package/src/internal/selector/create-writable-held-selector.ts +2 -2
  49. package/src/internal/selector/create-writable-pure-selector.ts +2 -2
  50. package/src/internal/set-state/become.ts +1 -3
  51. package/src/internal/set-state/dispatch-state-update.ts +1 -1
  52. package/src/internal/set-state/reset-in-store.ts +11 -13
  53. package/src/internal/set-state/set-into-store.ts +27 -3
  54. package/src/internal/store/store.ts +14 -12
  55. package/src/internal/timeline/create-timeline.ts +6 -5
  56. package/src/internal/timeline/time-travel.ts +4 -3
  57. package/src/internal/transaction/abort-transaction.ts +3 -15
  58. package/src/internal/transaction/act-upon-store.ts +1 -5
  59. package/src/internal/transaction/apply-transaction.ts +3 -15
  60. package/src/internal/transaction/assign-transaction-to-continuity.ts +2 -7
  61. package/src/internal/transaction/build-transaction.ts +2 -3
  62. package/src/internal/transaction/create-transaction.ts +5 -6
  63. package/src/internal/transaction/get-epoch-number.ts +1 -7
  64. package/src/internal/transaction/set-epoch-number.ts +4 -12
  65. package/src/introspection/attach-introspection-states.ts +4 -2
  66. package/src/introspection/attach-timeline-family.ts +2 -2
  67. package/src/introspection/attach-transaction-logs.ts +2 -2
  68. package/src/introspection/attach-type-selectors.ts +2 -2
  69. package/src/main/dispose-state.ts +1 -5
  70. package/src/main/events.ts +1 -3
  71. package/src/main/get-state.ts +3 -6
  72. package/src/main/realm.ts +36 -12
  73. package/src/main/reset-state.ts +1 -5
  74. package/src/main/set-state.ts +4 -11
  75. package/src/main/silo.ts +4 -3
  76. package/src/react/store-context.tsx +3 -3
  77. package/src/react-devtools/Button.tsx +3 -2
  78. package/src/react-devtools/TimelineIndex.tsx +0 -2
  79. package/src/react-devtools/store.ts +2 -2
  80. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +4 -8
  81. package/src/realtime-client/sync-continuity.ts +2 -2
  82. package/src/realtime-server/index.ts +2 -2
@@ -21,6 +21,7 @@ import { newest } from "../lineage"
21
21
  import { getUpdateToken } from "../mutable"
22
22
  import { deposit, type Store, withdraw } from "../store"
23
23
  import { Subject } from "../subject"
24
+ import type { RootStore } from "../transaction"
24
25
  import { isChildStore } from "../transaction"
25
26
 
26
27
  export type Timeline<ManagedAtom extends TimelineManageable> = {
@@ -31,13 +32,13 @@ export type Timeline<ManagedAtom extends TimelineManageable> = {
31
32
  history: TimelineEvent<ManagedAtom>[]
32
33
  selectorTime: number | null
33
34
  transactionKey: string | null
34
- install: (store: Store) => void
35
+ install: (store: RootStore) => void
35
36
  subject: Subject<TimelineEvent<ManagedAtom> | `redo` | `undo`>
36
37
  subscriptions: Map<string, () => void>
37
38
  }
38
39
 
39
40
  export function createTimeline<ManagedAtom extends TimelineManageable>(
40
- store: Store,
41
+ store: RootStore,
41
42
  options: TimelineOptions<ManagedAtom>,
42
43
  data?: Timeline<ManagedAtom>,
43
44
  ): TimelineToken<ManagedAtom> {
@@ -191,7 +192,7 @@ function addAtomToTimeline(
191
192
  tl.selectorTime = null
192
193
 
193
194
  const atomUpdate: AtomUpdateEvent<any> & TimelineEvent<any> = {
194
- write: true,
195
+ checkpoint: true,
195
196
  type: `atom_update`,
196
197
  token: deposit(atom),
197
198
  update,
@@ -267,7 +268,7 @@ function joinTransaction(
267
268
 
268
269
  const timelineTransactionUpdate: TimelineEvent<any> &
269
270
  TransactionOutcomeEvent<TransactionToken<any>> = {
270
- write: true,
271
+ checkpoint: true,
271
272
  ...transactionUpdate,
272
273
  subEvents: subEventsFiltered,
273
274
  }
@@ -291,7 +292,7 @@ function buildSelectorUpdate(
291
292
  if (currentSelectorTime !== tl.selectorTime) {
292
293
  const selectorUpdate: TimelineEvent<any> & TimelineSelectorUpdateEvent<any> =
293
294
  (latestUpdate = {
294
- write: true,
295
+ checkpoint: true,
295
296
  type: `selector_update`,
296
297
  timestamp: currentSelectorTime,
297
298
  token: currentSelectorToken,
@@ -52,7 +52,10 @@ export const timeTravel = (
52
52
  switch (action) {
53
53
  case `undo`:
54
54
  --nextIndex
55
- while (nextIndex !== 0 && timelineData.history[nextIndex].write !== true) {
55
+ while (
56
+ nextIndex !== 0 &&
57
+ timelineData.history[nextIndex].checkpoint !== true
58
+ ) {
56
59
  --nextIndex
57
60
  }
58
61
  events = timelineData.history.slice(nextIndex, timelineData.at).reverse()
@@ -88,8 +91,6 @@ export const timeTravel = (
88
91
  ingestDisposalEvent(store, event, applying)
89
92
  break
90
93
  }
91
- case `molecule_creation`:
92
- case `molecule_disposal`:
93
94
  }
94
95
  }
95
96
 
@@ -1,19 +1,7 @@
1
- import { newest } from "../lineage"
2
- import type { Store } from "../store"
3
- import { isChildStore } from "./is-root-store"
1
+ import type { ChildStore } from "./is-root-store"
4
2
 
5
- export const abortTransaction = (store: Store): void => {
6
- const target = newest(store)
7
- if (!isChildStore(target)) {
8
- store.logger.warn(
9
- `🐞`,
10
- `transaction`,
11
- `???`,
12
- `abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`,
13
- )
14
- return
15
- }
16
- store.logger.info(
3
+ export const abortTransaction = (target: ChildStore): void => {
4
+ target.logger.info(
17
5
  `🪂`,
18
6
  `transaction`,
19
7
  target.transactionMeta.update.token.key,
@@ -1,6 +1,5 @@
1
1
  import type { TransactionToken } from "atom.io"
2
2
 
3
- import { NotFoundError } from "../not-found-error"
4
3
  import type { Store } from "../store"
5
4
  import { withdraw } from "../store"
6
5
  import type { Fn } from "../utility-types"
@@ -12,9 +11,6 @@ export function actUponStore<F extends Fn>(
12
11
  ): (...parameters: Parameters<F>) => ReturnType<F> {
13
12
  return (...parameters: Parameters<F>): ReturnType<F> => {
14
13
  const tx = withdraw(store, token)
15
- if (tx) {
16
- return tx.run(parameters, id)
17
- }
18
- throw new NotFoundError(token, store)
14
+ return tx.run(parameters, id)
19
15
  }
20
16
  }
@@ -1,30 +1,18 @@
1
1
  import { ingestTransactionOutcomeEvent } from "../events"
2
2
  import { newest } from "../lineage"
3
- import type { Store } from "../store"
4
3
  import { withdraw } from "../store"
5
4
  import type { Fn } from "../utility-types"
5
+ import type { ChildStore } from "./is-root-store"
6
6
  import { isChildStore, isRootStore } from "./is-root-store"
7
7
  import { setEpochNumberOfAction } from "./set-epoch-number"
8
8
 
9
9
  export function applyTransaction<F extends Fn>(
10
- store: Store,
10
+ store: ChildStore,
11
11
  output: ReturnType<F>,
12
12
  ): void {
13
13
  const child = newest(store)
14
14
  const { parent } = child
15
- if (
16
- parent === null ||
17
- !isChildStore(child) ||
18
- child.transactionMeta?.phase !== `building`
19
- ) {
20
- store.logger.warn(
21
- `🐞`,
22
- `transaction`,
23
- `???`,
24
- `applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`,
25
- )
26
- return
27
- }
15
+
28
16
  child.transactionMeta.phase = `applying`
29
17
  child.transactionMeta.update.output = output
30
18
  parent.child = null
@@ -1,15 +1,10 @@
1
- import type { Store } from "../store"
2
- import { isRootStore } from "./is-root-store"
1
+ import type { RootStore } from "./is-root-store"
3
2
 
4
3
  export function assignTransactionToContinuity(
5
- store: Store,
4
+ store: RootStore,
6
5
  continuityKey: string,
7
6
  transactionKey: string,
8
7
  ): void {
9
- const isRoot = isRootStore(store)
10
- if (!isRoot) {
11
- return
12
- }
13
8
  const { epoch, actionContinuities } = store.transactionMeta
14
9
  actionContinuities.set(continuityKey, transactionKey)
15
10
  if (!epoch.has(continuityKey)) {
@@ -15,19 +15,18 @@ import { newest } from "../lineage"
15
15
  import { getJsonToken } from "../mutable"
16
16
  import { MapOverlay } from "../overlays/map-overlay"
17
17
  import { resetInStore, setIntoStore } from "../set-state"
18
- import type { Store } from "../store"
19
18
  import type { Fn } from "../utility-types"
20
19
  import type { TransactionProgress } from "."
21
20
  import { actUponStore, getEpochNumberOfAction } from "."
22
21
  import type { ChildStore, RootStore } from "./is-root-store"
23
22
 
24
23
  export const buildTransaction = (
25
- store: Store,
24
+ store: RootStore,
26
25
  token: TransactionToken<any>,
27
26
  params: any[],
28
27
  id: string,
29
28
  ): ChildStore => {
30
- const parent = newest(store) as ChildStore | RootStore
29
+ const parent = newest(store)
31
30
  const childBase: Omit<ChildStore, `transactionMeta`> = {
32
31
  parent,
33
32
  child: null,
@@ -5,24 +5,24 @@ import type {
5
5
  } from "atom.io"
6
6
 
7
7
  import { newest } from "../lineage"
8
- import type { Store } from "../store"
9
8
  import { deposit } from "../store"
10
9
  import { Subject } from "../subject"
11
10
  import type { Fn } from "../utility-types"
12
11
  import { abortTransaction } from "./abort-transaction"
13
12
  import { applyTransaction } from "./apply-transaction"
14
13
  import { buildTransaction } from "./build-transaction"
14
+ import type { RootStore } from "./is-root-store"
15
15
 
16
16
  export type Transaction<F extends Fn> = {
17
17
  key: string
18
18
  type: `transaction`
19
- install: (store: Store) => void
19
+ install: (store: RootStore) => void
20
20
  subject: Subject<TransactionOutcomeEvent<TransactionToken<F>>>
21
21
  run: (parameters: Parameters<F>, id?: string) => ReturnType<F>
22
22
  }
23
23
 
24
24
  export function createTransaction<F extends Fn>(
25
- store: Store,
25
+ store: RootStore,
26
26
  options: TransactionOptions<F>,
27
27
  ): TransactionToken<F> {
28
28
  const { key } = options
@@ -32,10 +32,9 @@ export function createTransaction<F extends Fn>(
32
32
  type: `transaction`,
33
33
  run: (params: Parameters<F>, id: string) => {
34
34
  const token = deposit(newTransaction)
35
- const childStore = buildTransaction(store, token, params, id)
35
+ const target = buildTransaction(store, token, params, id)
36
36
  try {
37
- const target = newest(store)
38
- const { toolkit } = childStore.transactionMeta
37
+ const { toolkit } = target.transactionMeta
39
38
  const output = options.do(toolkit, ...params)
40
39
  applyTransaction<F>(target, output)
41
40
  return output
@@ -1,6 +1,4 @@
1
- import type { Store } from "../store"
2
1
  import type { RootStore } from "./is-root-store"
3
- import { isRootStore } from "./is-root-store"
4
2
 
5
3
  export function getContinuityKey(
6
4
  store: RootStore,
@@ -21,13 +19,9 @@ export function getEpochNumberOfContinuity(
21
19
  }
22
20
 
23
21
  export function getEpochNumberOfAction(
24
- store: Store,
22
+ store: RootStore,
25
23
  transactionKey: string,
26
24
  ): number | undefined {
27
- const isRoot = isRootStore(store)
28
- if (!isRoot) {
29
- return undefined
30
- }
31
25
  const continuityKey = getContinuityKey(store, transactionKey)
32
26
  if (continuityKey === undefined) {
33
27
  return undefined
@@ -1,27 +1,19 @@
1
- import type { Store } from "../store"
2
1
  import { getContinuityKey } from "./get-epoch-number"
3
- import { isRootStore } from "./is-root-store"
2
+ import type { RootStore } from "./is-root-store"
4
3
 
5
4
  export function setEpochNumberOfContinuity(
6
- store: Store,
5
+ store: RootStore,
7
6
  continuityKey: string,
8
7
  newEpoch: number,
9
8
  ): void {
10
- const isRoot = isRootStore(store)
11
- if (isRoot && continuityKey) {
12
- store.transactionMeta.epoch.set(continuityKey, newEpoch)
13
- }
9
+ store.transactionMeta.epoch.set(continuityKey, newEpoch)
14
10
  }
15
11
 
16
12
  export function setEpochNumberOfAction(
17
- store: Store,
13
+ store: RootStore,
18
14
  transactionKey: string,
19
15
  newEpoch: number,
20
16
  ): void {
21
- const isRoot = isRootStore(store)
22
- if (!isRoot) {
23
- return
24
- }
25
17
  const continuityKey = getContinuityKey(store, transactionKey)
26
18
 
27
19
  if (continuityKey !== undefined) {
@@ -6,7 +6,7 @@ import type {
6
6
  TransactionOutcomeEvent,
7
7
  TransactionToken,
8
8
  } from "atom.io"
9
- import type { Fn, Store, Timeline } from "atom.io/internal"
9
+ import type { Fn, RootStore, Store, Timeline } from "atom.io/internal"
10
10
 
11
11
  import { type AtomTokenIndex, attachAtomIndex } from "./attach-atom-index"
12
12
  import type { SelectorTokenIndex } from "./attach-selector-index"
@@ -30,7 +30,9 @@ export type IntrospectionStates = {
30
30
  typeSelectors: ReadonlyPureSelectorFamilyToken<Loadable<string>, string>
31
31
  }
32
32
 
33
- export const attachIntrospectionStates = (store: Store): IntrospectionStates => {
33
+ export const attachIntrospectionStates = (
34
+ store: RootStore,
35
+ ): IntrospectionStates => {
34
36
  return {
35
37
  atomIndex: attachAtomIndex(store),
36
38
  selectorIndex: attachSelectorIndex(store),
@@ -1,5 +1,5 @@
1
1
  import type { ReadonlyPureSelectorFamilyToken } from "atom.io"
2
- import type { Store, Timeline } from "atom.io/internal"
2
+ import type { RootStore, Timeline } from "atom.io/internal"
3
3
  import {
4
4
  createRegularAtomFamily,
5
5
  createSelectorFamily,
@@ -7,7 +7,7 @@ import {
7
7
  } from "atom.io/internal"
8
8
 
9
9
  export const attachTimelineFamily = (
10
- store: Store,
10
+ store: RootStore,
11
11
  ): ReadonlyPureSelectorFamilyToken<Timeline<any>, string> => {
12
12
  const findTimelineLogState__INTERNAL = createRegularAtomFamily<
13
13
  Timeline<any>,
@@ -3,11 +3,11 @@ import type {
3
3
  TransactionOutcomeEvent,
4
4
  TransactionToken,
5
5
  } from "atom.io"
6
- import type { Store } from "atom.io/internal"
6
+ import type { RootStore } from "atom.io/internal"
7
7
  import { createRegularAtomFamily, createSelectorFamily } from "atom.io/internal"
8
8
 
9
9
  export const attachTransactionLogs = (
10
- store: Store,
10
+ store: RootStore,
11
11
  ): ReadonlyPureSelectorFamilyToken<
12
12
  TransactionOutcomeEvent<TransactionToken<any>>[],
13
13
  string
@@ -1,11 +1,11 @@
1
1
  import type { Loadable, ReadonlyPureSelectorFamilyToken } from "atom.io"
2
- import type { Store } from "atom.io/internal"
2
+ import type { RootStore } from "atom.io/internal"
3
3
  import { createReadonlyPureSelectorFamily } from "atom.io/internal"
4
4
 
5
5
  import { discoverType } from "./refinery"
6
6
 
7
7
  export const attachTypeSelectors = (
8
- store: Store,
8
+ store: RootStore,
9
9
  ): ReadonlyPureSelectorFamilyToken<Loadable<string>, string> => {
10
10
  const typeSelectors = createReadonlyPureSelectorFamily<
11
11
  Loadable<string>,
@@ -30,9 +30,5 @@ export function disposeState(
30
30
  | [token: ReadableFamilyToken<any, any>, key: Canonical]
31
31
  | [token: ReadableToken<any>]
32
32
  ): void {
33
- if (params.length === 2) {
34
- disposeFromStore(IMPLICIT.STORE, ...params)
35
- } else {
36
- disposeFromStore(IMPLICIT.STORE, ...params)
37
- }
33
+ disposeFromStore(IMPLICIT.STORE, ...params)
38
34
  }
@@ -114,11 +114,9 @@ export type TransactionOutcomeEvent<T extends TransactionToken<any>> = {
114
114
  }
115
115
 
116
116
  export type TimelineEvent<ManagedAtom extends TimelineManageable> = {
117
- write?: true
117
+ checkpoint?: true
118
118
  } & (
119
119
  | AtomUpdateEvent<AtomOnly<ManagedAtom>>
120
- | MoleculeCreationEvent
121
- | MoleculeDisposalEvent
122
120
  | StateCreationEvent<AtomOnly<ManagedAtom>>
123
121
  | StateDisposalEvent<AtomOnly<ManagedAtom>>
124
122
  | TimelineSelectorUpdateEvent<ManagedAtom>
@@ -25,13 +25,10 @@ export function getState<T, K extends Canonical, Key extends K>(
25
25
  key: Key,
26
26
  ): ViewOf<T>
27
27
 
28
- export function getState(
28
+ export function getState<T, K extends Canonical, Key extends K>(
29
29
  ...params:
30
- | [token: ReadableFamilyToken<any, any>, key: Canonical]
31
- | [token: ReadableToken<any>]
30
+ | [token: ReadableFamilyToken<T, K>, key: Key]
31
+ | [token: ReadableToken<T>]
32
32
  ): any {
33
- if (params.length === 2) {
34
- return getFromStore(IMPLICIT.STORE, ...params)
35
- }
36
33
  return getFromStore(IMPLICIT.STORE, ...params)
37
34
  }
package/src/main/realm.ts CHANGED
@@ -1,24 +1,39 @@
1
- import type { Each, Store } from "atom.io/internal"
1
+ import type { Each, RootStore } from "atom.io/internal"
2
2
  import {
3
+ actUponStore,
3
4
  allocateIntoStore,
5
+ arbitrary,
4
6
  claimWithinStore,
5
- deallocateFromStore,
7
+ createClaimTX,
8
+ createDeallocateTX,
6
9
  fuseWithinStore,
7
10
  IMPLICIT,
8
11
  makeRootMoleculeInStore,
9
12
  } from "atom.io/internal"
10
13
  import type { Canonical } from "atom.io/json"
11
14
 
15
+ import type { TransactionToken } from "./tokens"
16
+
12
17
  export const $claim: unique symbol = Symbol.for(`claim`)
13
18
  export type Claim<K extends Canonical> = K & { [$claim]?: true }
14
19
 
15
20
  export class Realm<H extends Hierarchy> {
16
- public store: Store
21
+ public store: RootStore
22
+ public deallocateTX: TransactionToken<(claim: Claim<Vassal<H>>) => void>
23
+ public claimTX: TransactionToken<
24
+ <V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(
25
+ newProvenance: A,
26
+ claim: Claim<V>,
27
+ exclusive?: `exclusive`,
28
+ ) => void
29
+ >
17
30
  /**
18
31
  * @param store - The store to which the realm will be attached
19
32
  */
20
- public constructor(store: Store = IMPLICIT.STORE) {
33
+ public constructor(store: RootStore = IMPLICIT.STORE) {
21
34
  this.store = store
35
+ this.deallocateTX = createDeallocateTX(store)
36
+ this.claimTX = createClaimTX(store)
22
37
  makeRootMoleculeInStore(`root`, store)
23
38
  }
24
39
  /**
@@ -66,7 +81,7 @@ export class Realm<H extends Hierarchy> {
66
81
  * @param claim - The subject to be deallocated
67
82
  */
68
83
  public deallocate<V extends Vassal<H>>(claim: Claim<V>): void {
69
- deallocateFromStore<H, V>(this.store, claim)
84
+ actUponStore(this.store, this.deallocateTX, arbitrary())(claim)
70
85
  }
71
86
  /**
72
87
  * Transfer a subject of the realm from one owner to another
@@ -79,21 +94,30 @@ export class Realm<H extends Hierarchy> {
79
94
  public claim<
80
95
  V extends Exclude<Vassal<H>, CompoundTypedKey>,
81
96
  A extends Above<V, H>,
82
- >(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V> {
83
- return claimWithinStore<H, V, A>(this.store, newProvenance, claim, exclusive)
97
+ >(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): void {
98
+ actUponStore(this.store, this.claimTX, arbitrary())(
99
+ newProvenance,
100
+ claim,
101
+ exclusive,
102
+ )
84
103
  }
85
104
  }
86
105
 
87
106
  export class Anarchy {
88
- public store: Store
89
- public realm: Realm<any>
107
+ public store: RootStore
108
+ public deallocateTX: TransactionToken<(key: Canonical) => void>
109
+ public claimTX: TransactionToken<
110
+ (newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`) => void
111
+ >
90
112
 
91
113
  /**
92
114
  * @param store - The store to which the anarchy-realm will be attached
93
115
  */
94
- public constructor(store: Store = IMPLICIT.STORE) {
116
+ public constructor(store: RootStore = IMPLICIT.STORE) {
95
117
  this.store = store
96
- this.realm = new Realm(store)
118
+ this.deallocateTX = createDeallocateTX(store)
119
+ this.claimTX = createClaimTX(store)
120
+ makeRootMoleculeInStore(`root`, store)
97
121
  }
98
122
  /**
99
123
  * Declare a new entity
@@ -118,7 +142,7 @@ export class Anarchy {
118
142
  * @param key - The entity to be deallocated
119
143
  */
120
144
  public deallocate(key: Canonical): void {
121
- deallocateFromStore<any, any>(this.store, key)
145
+ actUponStore(this.store, this.deallocateTX, arbitrary())(key)
122
146
  }
123
147
  /**
124
148
  * Transfer an entity from one owner to another
@@ -25,9 +25,5 @@ export function resetState(
25
25
  | [token: WritableFamilyToken<any, Canonical>, key: Canonical]
26
26
  | [token: WritableToken<any>]
27
27
  ): void {
28
- if (params.length === 2) {
29
- resetInStore(IMPLICIT.STORE, ...params)
30
- } else {
31
- resetInStore(IMPLICIT.STORE, ...params)
32
- }
28
+ resetInStore(IMPLICIT.STORE, ...params)
33
29
  }
@@ -35,18 +35,11 @@ export function setState<T, K extends Canonical, New extends T, Key extends K>(
35
35
  key: Key,
36
36
  value: New | Setter<T, New>,
37
37
  ): void
38
- export function setState<T, New extends T>(
38
+
39
+ export function setState<T, K extends Canonical, New extends T, Key extends K>(
39
40
  ...params:
40
- | [
41
- token: WritableFamilyToken<T, Canonical>,
42
- key: Canonical,
43
- value: New | Setter<T, New>,
44
- ]
41
+ | [token: WritableFamilyToken<T, K>, key: Key, value: New | Setter<T, New>]
45
42
  | [token: WritableToken<T>, value: New | Setter<T, New>]
46
43
  ): void {
47
- if (params.length === 2) {
48
- setIntoStore(IMPLICIT.STORE, ...params)
49
- } else {
50
- setIntoStore(IMPLICIT.STORE, ...params)
51
- }
44
+ setIntoStore(IMPLICIT.STORE, ...params)
52
45
  }
package/src/main/silo.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { findState } from "atom.io"
2
+ import type { RootStore } from "atom.io/internal"
2
3
  import {
3
4
  actUponStore,
4
5
  arbitrary,
@@ -38,7 +39,7 @@ import type { selector, selectorFamily } from "./selector"
38
39
  import type { runTransaction, transaction } from "./transaction"
39
40
 
40
41
  export class Silo {
41
- public store: Store
42
+ public store: RootStore
42
43
  public atom: typeof atom
43
44
  public mutableAtom: typeof mutableAtom
44
45
  public atomFamily: typeof atomFamily
@@ -56,10 +57,10 @@ export class Silo {
56
57
  public undo: typeof undo
57
58
  public redo: typeof redo
58
59
  public runTransaction: typeof runTransaction
59
- public install: (tokens: AtomIOToken[], store?: Store) => void
60
+ public install: (tokens: AtomIOToken[], store?: RootStore) => void
60
61
 
61
62
  public constructor(config: Store[`config`], fromStore: Store | null = null) {
62
- const s = (this.store = new Store(config, fromStore))
63
+ const s = (this.store = new Store(config, fromStore) as RootStore)
63
64
  this.atom = ((options: Parameters<typeof atom>[0]) =>
64
65
  createRegularAtom(s, options, undefined)) as typeof atom
65
66
  this.mutableAtom = ((options: Parameters<typeof mutableAtom>[0]) =>
@@ -1,14 +1,14 @@
1
- import type { Store } from "atom.io/internal"
1
+ import type { RootStore } from "atom.io/internal"
2
2
  import { IMPLICIT } from "atom.io/internal"
3
3
  import * as React from "react"
4
4
 
5
- export const StoreContext: React.Context<Store> = React.createContext(
5
+ export const StoreContext: React.Context<RootStore> = React.createContext(
6
6
  IMPLICIT.STORE,
7
7
  )
8
8
 
9
9
  export const StoreProvider: React.FC<{
10
10
  children: React.ReactNode
11
- store?: Store
11
+ store?: RootStore
12
12
  }> = ({ children, store = IMPLICIT.STORE }) => (
13
13
  <StoreContext.Provider value={store}>{children}</StoreContext.Provider>
14
14
  )
@@ -1,9 +1,10 @@
1
- import type { Modify } from "atom.io/internal"
2
1
  import type { FC } from "react"
3
2
 
4
3
  export const OpenClose: FC<{
5
4
  isOpen: boolean
6
- setIsOpen?: ((next: Modify<boolean> | boolean) => void) | undefined
5
+ setIsOpen?:
6
+ | ((next: boolean | ((prev: boolean) => boolean)) => void)
7
+ | undefined
7
8
  onShiftClick?: (
8
9
  event: React.MouseEvent<HTMLButtonElement, MouseEvent>,
9
10
  ) => boolean
@@ -64,8 +64,6 @@ export const TimelineLog: FC<{
64
64
  {isOpen ? (
65
65
  <main>
66
66
  {timeline.history.map((update, index) =>
67
- update.type !== `molecule_creation` &&
68
- update.type !== `molecule_disposal` &&
69
67
  update.type !== `state_creation` &&
70
68
  update.type !== `state_disposal` ? (
71
69
  <Fragment key={update.token.key + index + timeline.at}>
@@ -5,11 +5,11 @@ import type {
5
5
  SelectorToken,
6
6
  TransactionToken,
7
7
  } from "atom.io"
8
+ import type { RootStore, Store } from "atom.io/internal"
8
9
  import {
9
10
  createRegularAtom,
10
11
  createRegularAtomFamily,
11
12
  createTransaction,
12
- type Store,
13
13
  } from "atom.io/internal"
14
14
  import type {
15
15
  IntrospectionStates,
@@ -34,7 +34,7 @@ export type DevtoolsStates = {
34
34
  }
35
35
 
36
36
  export function attachDevtoolsStates(
37
- store: Store,
37
+ store: RootStore,
38
38
  hideByDefault = false,
39
39
  ): DevtoolsStates & IntrospectionStates & { store: Store } {
40
40
  const introspectionStates = attachIntrospectionStates(store)
@@ -1,10 +1,9 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Fn, Store } from "atom.io/internal"
2
+ import type { Fn, RootStore } from "atom.io/internal"
3
3
  import {
4
4
  actUponStore,
5
5
  getEpochNumberOfContinuity,
6
6
  ingestTransactionOutcomeEvent,
7
- isRootStore,
8
7
  setEpochNumberOfContinuity,
9
8
  setIntoStore,
10
9
  } from "atom.io/internal"
@@ -16,7 +15,7 @@ import type { Socket } from "atom.io/realtime-server"
16
15
 
17
16
  export const useRegisterAndAttemptConfirmedUpdate =
18
17
  (
19
- store: Store,
18
+ store: RootStore,
20
19
  continuityKey: string,
21
20
  socket: Socket,
22
21
  optimisticUpdates: AtomIO.TransactionOutcomeEvent<
@@ -187,11 +186,8 @@ export const useRegisterAndAttemptConfirmedUpdate =
187
186
  continuityKey,
188
187
  `has no optimistic updates to deal with`,
189
188
  )
190
- const isRoot = isRootStore(store)
191
189
  let continuityEpoch: number | undefined
192
- if (isRoot) {
193
- continuityEpoch = getEpochNumberOfContinuity(store, continuityKey)
194
- }
190
+ continuityEpoch = getEpochNumberOfContinuity(store, continuityKey)
195
191
 
196
192
  if (continuityEpoch === confirmed.epoch - 1) {
197
193
  store.logger.info(
@@ -203,7 +199,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
203
199
  ingestTransactionOutcomeEvent(store, confirmed, `newValue`)
204
200
  socket.emit(`ack:${continuityKey}`, confirmed.epoch)
205
201
  setEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)
206
- } else if (isRoot && continuityEpoch !== undefined) {
202
+ } else if (continuityEpoch !== undefined) {
207
203
  store.logger.info(
208
204
  `🧑‍⚖️`,
209
205
  `continuity`,