atom.io 0.33.19 → 0.33.21

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.33.19",
3
+ "version": "0.33.21",
4
4
  "description": "Composable and testable reactive data library.",
5
5
  "homepage": "https://atom.io.fyi",
6
6
  "sideEffects": false,
@@ -70,7 +70,7 @@
70
70
  "@types/estree": "1.0.8",
71
71
  "@types/http-proxy": "1.17.16",
72
72
  "@types/npmlog": "7.0.0",
73
- "@types/react": "19.1.8",
73
+ "@types/react": "19.1.9",
74
74
  "@types/tmp": "0.2.6",
75
75
  "@typescript-eslint/parser": "8.38.0",
76
76
  "@typescript-eslint/rule-tester": "8.38.0",
@@ -79,11 +79,11 @@
79
79
  "@vitest/ui": "3.2.4",
80
80
  "concurrently": "9.2.0",
81
81
  "drizzle-kit": "0.31.4",
82
- "drizzle-orm": "0.44.3",
82
+ "drizzle-orm": "0.44.4",
83
83
  "eslint": "9.32.0",
84
84
  "happy-dom": "18.0.1",
85
85
  "http-proxy": "1.18.1",
86
- "motion": "12.23.11",
86
+ "motion": "12.23.12",
87
87
  "npmlog": "7.0.1",
88
88
  "nyc": "17.1.0",
89
89
  "postgres": "3.4.7",
@@ -5,7 +5,7 @@ import type {
5
5
  UpdateHandler,
6
6
  } from "atom.io"
7
7
 
8
- import { type RegularAtom, setIntoStore } from ".."
8
+ import { type RegularAtom, resetInStore, setIntoStore } from ".."
9
9
  import { cacheValue } from "../caching"
10
10
  import { newest } from "../lineage"
11
11
  import type { Store } from "../store"
@@ -62,6 +62,9 @@ export function createRegularAtom<T>(
62
62
  const cleanupFunctions: (() => void)[] = []
63
63
  for (const effect of options.effects) {
64
64
  const cleanup = effect({
65
+ resetSelf: () => {
66
+ resetInStore(store, token)
67
+ },
65
68
  setSelf: (next) => {
66
69
  setIntoStore(store, token, next)
67
70
  },
@@ -33,6 +33,7 @@ export function cacheValue<T>(
33
33
  if (currentValue instanceof Future) {
34
34
  const future = currentValue
35
35
  if (value instanceof Promise) {
36
+ future.use(value)
36
37
  return future
37
38
  }
38
39
  target.valueMap.set(key, value)
@@ -8,7 +8,7 @@ import type { Json } from "atom.io/json"
8
8
  import { selectJson } from "atom.io/json"
9
9
 
10
10
  import type { MutableAtom } from ".."
11
- import { cacheValue, setIntoStore } from ".."
11
+ import { cacheValue, resetInStore, setIntoStore } from ".."
12
12
  import { newest } from "../lineage"
13
13
  import { deposit, type Store } from "../store"
14
14
  import { Subject } from "../subject"
@@ -65,6 +65,9 @@ export function createMutableAtom<
65
65
  const cleanupFunctions: (() => void)[] = []
66
66
  for (const effect of options.effects) {
67
67
  const cleanup = effect({
68
+ resetSelf: () => {
69
+ resetInStore(store, token)
70
+ },
68
71
  setSelf: (next) => {
69
72
  setIntoStore(store, token, next)
70
73
  },
@@ -1,4 +1,5 @@
1
- import { type Atom, traceAllSelectorAtoms, type WritableState } from ".."
1
+ import type { Atom, WritableState } from ".."
2
+ import { traceAllSelectorAtoms } from ".."
2
3
  import type { Store } from "../store"
3
4
  import { setAtom } from "./set-atom"
4
5
 
package/src/main/atom.ts CHANGED
@@ -40,6 +40,10 @@ export function atom(
40
40
 
41
41
  /** @public */
42
42
  export type Effectors<T> = {
43
+ /**
44
+ * Reset the value of the atom to its default
45
+ */
46
+ resetSelf: () => void
43
47
  /**
44
48
  * Set the value of the atom
45
49
  * @param next - The new value of the atom, or a setter function
@@ -31,7 +31,7 @@ export function useLoadable(
31
31
  | readonly [ReadableToken<any>, unknown]
32
32
  | readonly [ReadableToken<any>]
33
33
  ): `LOADING` | { loading: boolean; value: unknown } {
34
- let loadable: ReadableToken<any>
34
+ let state: unknown
35
35
  let fallback: unknown
36
36
 
37
37
  const [token] = params
@@ -43,7 +43,7 @@ export function useLoadable(
43
43
  case `readonly_pure_selector`:
44
44
  case `writable_held_selector`:
45
45
  case `writable_pure_selector`:
46
- loadable = useO(token)
46
+ state = useO(token)
47
47
  fallback = params[1]
48
48
  break
49
49
  case `atom_family`:
@@ -53,27 +53,32 @@ export function useLoadable(
53
53
  case `writable_held_selector_family`:
54
54
  case `writable_pure_selector_family`:
55
55
  key = params[1] as Canonical
56
- loadable = useO(token, key)
56
+ state = useO(token, key)
57
57
  fallback = params[2]
58
58
  }
59
59
 
60
+ const wrapperRef = React.useRef({ loading: false, value: null as unknown })
60
61
  const lastLoadedRef = React.useRef(
61
- fallback ?? (loadable instanceof Promise ? `LOADING` : loadable),
62
+ fallback ?? (state instanceof Promise ? `LOADING` : state),
62
63
  )
64
+
63
65
  const { current: lastLoaded } = lastLoadedRef
64
- if (loadable instanceof Promise) {
66
+ let { current: wrapper } = wrapperRef
67
+
68
+ if (state instanceof Promise) {
65
69
  if (lastLoaded === `LOADING`) {
66
70
  return `LOADING`
67
71
  }
68
- return {
69
- loading: true,
70
- value: lastLoaded,
72
+ wrapper = wrapperRef.current = { loading: true, value: lastLoaded }
73
+ } else {
74
+ lastLoadedRef.current = state
75
+ if (wrapper.loading === true) {
76
+ wrapper = wrapperRef.current = { loading: false, value: state }
77
+ } else {
78
+ wrapper.loading = false
79
+ wrapper.value = state
71
80
  }
72
81
  }
73
82
 
74
- lastLoadedRef.current = loadable
75
- return {
76
- loading: false,
77
- value: loadable,
78
- }
83
+ return wrapper
79
84
  }