atom.io 0.36.1 → 0.36.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.
@@ -6,19 +6,21 @@ import { getFamilyOfToken } from "../families/get-family-of-token"
6
6
  import { closeOperation, openOperation } from "../operation"
7
7
  import type { Store } from "../store"
8
8
  import { withdraw } from "../store"
9
+ import { resetAtomOrSelector } from "./reset-atom-or-selector"
10
+ import { RESET_STATE } from "./reset-in-store"
9
11
  import { setAtomOrSelector } from "./set-atom-or-selector"
10
12
 
11
13
  export function setIntoStore<T, New extends T>(
12
14
  store: Store,
13
15
  token: WritableToken<T>,
14
- value: New | ((oldValue: T) => New),
16
+ value: New | typeof RESET_STATE | ((oldValue: T) => New),
15
17
  ): void
16
18
 
17
19
  export function setIntoStore<T, K extends Canonical, New extends T>(
18
20
  store: Store,
19
21
  token: WritableFamilyToken<T, K>,
20
22
  key: K,
21
- value: New | ((oldValue: T) => New),
23
+ value: New | typeof RESET_STATE | ((oldValue: T) => New),
22
24
  ): void
23
25
 
24
26
  export function setIntoStore<T, New extends T>(
@@ -27,14 +29,17 @@ export function setIntoStore<T, New extends T>(
27
29
  | [
28
30
  token: WritableFamilyToken<T, Canonical>,
29
31
  key: Canonical,
30
- value: New | ((oldValue: T) => New),
32
+ value: New | typeof RESET_STATE | ((oldValue: T) => New),
33
+ ]
34
+ | [
35
+ token: WritableToken<T>,
36
+ value: New | typeof RESET_STATE | ((oldValue: T) => New),
31
37
  ]
32
- | [token: WritableToken<T>, value: New | ((oldValue: T) => New)]
33
38
  ): void {
34
39
  let token: WritableToken<T>
35
40
  let family: WritableFamilyToken<T, Canonical> | null
36
41
  let key: Canonical | null
37
- let value: New | ((oldValue: T) => New)
42
+ let value: New | typeof RESET_STATE | ((oldValue: T) => New)
38
43
  if (params.length === 2) {
39
44
  token = params[0]
40
45
  value = params[1]
@@ -51,6 +56,8 @@ export function setIntoStore<T, New extends T>(
51
56
  token = findInStore(store, family, key)
52
57
  }
53
58
 
59
+ const action = value === RESET_STATE ? `reset` : `set`
60
+
54
61
  if (`counterfeit` in token && `family` in token) {
55
62
  const subKey = token.family.subKey
56
63
  const disposal = store.disposalTraces.buffer.find(
@@ -60,7 +67,9 @@ export function setIntoStore<T, New extends T>(
60
67
  `❌`,
61
68
  token.type,
62
69
  token.key,
63
- `could not be set because it was not found in the store "${store.config.name}".`,
70
+ `could not be`,
71
+ action,
72
+ `because it was not found in the store "${store.config.name}".`,
64
73
  disposal
65
74
  ? `This state was previously disposed:\n${disposal.trace}`
66
75
  : `No previous disposal trace was found.`,
@@ -71,14 +80,16 @@ export function setIntoStore<T, New extends T>(
71
80
  const rejectionTime = openOperation(store, token)
72
81
  if (rejectionTime) {
73
82
  const unsubscribe = store.on.operationClose.subscribe(
74
- `waiting to set "${token.key}" at T-${rejectionTime}`,
83
+ `waiting to ${action} "${token.key}" at T-${rejectionTime}`,
75
84
  function waitUntilOperationCloseToSetState() {
76
85
  unsubscribe()
77
86
  store.logger.info(
78
87
  `🟢`,
79
88
  token.type,
80
89
  token.key,
81
- `resuming deferred setState from T-${rejectionTime}`,
90
+ `resuming deferred`,
91
+ action,
92
+ `from T-${rejectionTime}`,
82
93
  )
83
94
  setIntoStore(store, token, value)
84
95
  },
@@ -86,6 +97,10 @@ export function setIntoStore<T, New extends T>(
86
97
  return
87
98
  }
88
99
  const state = withdraw(store, token)
89
- setAtomOrSelector(store, state, value)
100
+ if (value === RESET_STATE) {
101
+ resetAtomOrSelector(store, state)
102
+ } else {
103
+ setAtomOrSelector(store, state, value)
104
+ }
90
105
  closeOperation(store)
91
106
  }
@@ -7,13 +7,13 @@ import type {
7
7
  TransactionUpdateHandler,
8
8
  UpdateHandler,
9
9
  } from "atom.io"
10
- import type { Fn, Store } from "atom.io/internal"
11
- import {
12
- arbitrary,
13
- subscribeToState,
14
- subscribeToTimeline,
15
- subscribeToTransaction,
16
- } from "atom.io/internal"
10
+
11
+ import { arbitrary } from "../arbitrary"
12
+ import type { Store } from "../store"
13
+ import type { Fn } from "../utility-types"
14
+ import { subscribeToState } from "./subscribe-to-state"
15
+ import { subscribeToTimeline } from "./subscribe-to-timeline"
16
+ import { subscribeToTransaction } from "./subscribe-to-transaction"
17
17
 
18
18
  export function subscribeInStore<T>(
19
19
  store: Store,
@@ -1,7 +1,7 @@
1
1
  import type { TimelineManageable, TimelineToken, TimelineUpdate } from "atom.io"
2
2
 
3
- import type { Store } from ".."
4
- import { withdraw } from ".."
3
+ import type { Store } from "../store/store"
4
+ import { withdraw } from "../store/withdraw"
5
5
 
6
6
  export const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(
7
7
  store: Store,
@@ -18,27 +18,22 @@ export type AtomIOToken =
18
18
  | TimelineToken<any>
19
19
  | TransactionToken<any>
20
20
 
21
- /**
22
- * These states cannot be set.
23
- */
24
21
  export type ReadableToken<T, K extends Canonical = any> =
25
22
  | AtomToken<T, K>
26
23
  | SelectorToken<T, K>
27
- /**
28
- * These states can be set.
29
- */
24
+
30
25
  export type WritableToken<T, K extends Canonical = any> =
31
26
  | AtomToken<T, K>
32
27
  | WritableSelectorToken<T, K>
33
28
 
34
29
  /**
35
- * States belonging to this family can be gotten from the store.
30
+ * States belonging to this family can be read from the store.
36
31
  */
37
32
  export type ReadableFamilyToken<T, K extends Canonical> =
38
33
  | AtomFamilyToken<T, K>
39
34
  | SelectorFamilyToken<T, K>
40
35
  /**
41
- * States belonging to this family can be set.
36
+ * States belonging to this family can be written directly.
42
37
  */
43
38
  export type WritableFamilyToken<T, K extends Canonical> =
44
39
  | AtomFamilyToken<T, K>