chem-rx 0.0.23 → 0.2.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.
- package/CHANGELOG.md +26 -0
- package/README.md +145 -33
- package/dist/Atom.d.ts +88 -48
- package/dist/Atom.d.ts.map +1 -1
- package/dist/Signal.d.ts +4 -5
- package/dist/Signal.d.ts.map +1 -1
- package/dist/index.cjs.js +423 -295
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.iife.js +425 -294
- package/dist/index.mjs +423 -0
- package/dist/react.cjs.js +50 -0
- package/{src/index.ts → dist/react.d.ts} +1 -3
- package/dist/react.d.ts.map +1 -0
- package/dist/react.mjs +40 -0
- package/dist/store.d.ts +30 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/useAtom.d.ts +2 -2
- package/dist/useAtom.d.ts.map +1 -1
- package/dist/useHydrateAtoms.d.ts.map +1 -1
- package/dist/useSelectAtom.d.ts.map +1 -1
- package/package.json +34 -16
- package/.size-snapshot.json +0 -26
- package/babel.config.js +0 -24
- package/dist/index.js +0 -301
- package/dist/types.d.ts +0 -32
- package/dist/types.d.ts.map +0 -1
- package/rollup.config.js +0 -92
- package/src/Atom.ts +0 -374
- package/src/Signal.ts +0 -38
- package/src/types.ts +0 -66
- package/src/useAtom.ts +0 -20
- package/src/useHydrateAtoms.ts +0 -16
- package/src/useSelectAtom.ts +0 -25
- package/src/useSignal.ts +0 -24
- package/tests/atom.test.ts +0 -625
- package/tests/sample.ts +0 -123
- package/tsconfig.json +0 -23
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 - 2026-06-13
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Optional `equals` comparator on every atom creation path: `Atom(value, { equals })`,
|
|
8
|
+
`atom.derive(fn, { equals })`, and `atom.select(key, { equals })`. Supply a
|
|
9
|
+
content comparator to dedup notifications by data instead of identity. See
|
|
10
|
+
[Equality & change detection](./README.md#equality--change-detection).
|
|
11
|
+
- `Atom()`'s second argument now also accepts an options object
|
|
12
|
+
(`{ readOnly?, equals? }`) in addition to the legacy `readOnly` boolean.
|
|
13
|
+
- Exported `Equals<T>` and `AtomFactoryOptions<T>` types.
|
|
14
|
+
|
|
15
|
+
### Changed (breaking)
|
|
16
|
+
|
|
17
|
+
- Every atom now decides whether to notify subscribers using an equality
|
|
18
|
+
comparator that **defaults to `Object.is`**:
|
|
19
|
+
- A base atom no longer re-emits when `next()` is called with an
|
|
20
|
+
`Object.is`-equal value (previously every `next()` notified).
|
|
21
|
+
- `derive` no longer re-emits when its computed output is `Object.is`-equal
|
|
22
|
+
(previously it re-emitted on every parent update).
|
|
23
|
+
- `select` and `combine` are unchanged in practice (already `Object.is`).
|
|
24
|
+
|
|
25
|
+
Migration: pass `equals: () => false` to restore the previous always-notify
|
|
26
|
+
behavior.
|
package/README.md
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
# chem-rx
|
|
2
2
|
|
|
3
|
-
`chem-rx`
|
|
4
|
-
|
|
3
|
+
`chem-rx` provides a small atomic state management layer focused on simplicity.
|
|
4
|
+
Useable with or without React!
|
|
5
|
+
|
|
6
|
+
> **Breaking change (unreleased):** atoms now decide whether to notify
|
|
7
|
+
> subscribers using an equality comparator that **defaults to `Object.is`**.
|
|
8
|
+
> Two behaviors changed: a base atom no longer re-emits when you set an
|
|
9
|
+
> `Object.is`-equal value, and `derive` no longer re-emits when its computed
|
|
10
|
+
> output is `Object.is`-equal (it previously always re-emitted on every parent
|
|
11
|
+
> update). To restore the old always-notify behavior, pass `equals: () => false`.
|
|
12
|
+
> See [Equality & change detection](#equality--change-detection).
|
|
5
13
|
|
|
6
14
|
## Atom
|
|
7
15
|
|
|
@@ -88,6 +96,15 @@ at that key. Any time the original atom changes, your selected atom will automat
|
|
|
88
96
|
This can be especially useful for working with different parts of nested Array and Object atoms.
|
|
89
97
|
|
|
90
98
|
Atoms created with `select` are **read-only** (`ReadOnlyAtom`). This prevents you from modifying original values that the atom was created from.
|
|
99
|
+
Selected atoms are lazy: calling `value()` reads the latest parent snapshot, and subscribing to a selected atom listens to the parent only while that selected atom has active subscribers.
|
|
100
|
+
|
|
101
|
+
By default a selected atom notifies subscribers only when the selected value changes by `Object.is`. Pass `{ equals }` to dedup by content instead (see [Equality & change detection](#equality--change-detection)):
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
const stacy = students.select("stacy", {
|
|
105
|
+
equals: (a, b) => a?.nickname === b?.nickname,
|
|
106
|
+
});
|
|
107
|
+
```
|
|
91
108
|
|
|
92
109
|
```
|
|
93
110
|
const students = Atom({
|
|
@@ -130,6 +147,8 @@ change, your derived atoms will automatically update with new values.
|
|
|
130
147
|
|
|
131
148
|
Every derived atom is **read-only**. This prevents you from overriding the
|
|
132
149
|
derived output value, since it is automatically derived from another input.
|
|
150
|
+
Like selected atoms, derived atoms are lazy and only stay subscribed to their
|
|
151
|
+
inputs while they have active subscribers.
|
|
133
152
|
|
|
134
153
|
```
|
|
135
154
|
const atom$ = Atom(3);
|
|
@@ -138,7 +157,7 @@ const squared$ = atom$.derive((x) => x * x);
|
|
|
138
157
|
|
|
139
158
|
squared$.value() // "9"
|
|
140
159
|
|
|
141
|
-
atom$.
|
|
160
|
+
atom$.next(4)
|
|
142
161
|
|
|
143
162
|
squared$.value() // "16"
|
|
144
163
|
|
|
@@ -146,19 +165,36 @@ squared$.value() // "16"
|
|
|
146
165
|
squared$.set(2)
|
|
147
166
|
```
|
|
148
167
|
|
|
149
|
-
|
|
168
|
+
By default, a derived atom notifies subscribers only when its computed output changes by `Object.is`. When `deriveFn` returns a fresh object/array each time (so `Object.is` never matches), pass `{ equals }` to dedup by content (see [Equality & change detection](#equality--change-detection)):
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
const items$ = data$.derive((data) => data.items, {
|
|
172
|
+
equals: (a, b) => a.length === b.length && a.every((x, i) => x.id === b[i].id),
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
You can optionally enforce `readOnly` on an atom at creation time if needed. The
|
|
177
|
+
second argument also accepts an options object (`{ readOnly?, equals? }`):
|
|
150
178
|
|
|
151
179
|
```
|
|
152
180
|
const atom$ = Atom(3, true);
|
|
181
|
+
// equivalent:
|
|
182
|
+
const atom2$ = Atom(3, { readOnly: true });
|
|
153
183
|
|
|
154
184
|
// ERR: Property 'set' does not exist on type ReadOnlyAtom
|
|
155
185
|
atom$.set(2)
|
|
186
|
+
|
|
187
|
+
// content-based dedup on a writable atom
|
|
188
|
+
const point$ = Atom({ x: 0, y: 0 }, { equals: (a, b) => a.x === b.x && a.y === b.y });
|
|
156
189
|
```
|
|
157
190
|
|
|
158
191
|
### Combining Atoms
|
|
159
192
|
|
|
160
193
|
Multiple atoms can also be **combined** to create brand new atoms.
|
|
161
194
|
|
|
195
|
+
`combine` produces a fresh array snapshot on every input change, so it re-emits on
|
|
196
|
+
every update. To dedup by content, chain a `derive(fn, { equals })` onto it.
|
|
197
|
+
|
|
162
198
|
Here's an example of joining a set of normalized data models
|
|
163
199
|
|
|
164
200
|
```
|
|
@@ -195,8 +231,14 @@ console.log(mary$.select('pets').value())
|
|
|
195
231
|
|
|
196
232
|
### Subscribing to updates
|
|
197
233
|
|
|
198
|
-
Atoms emit values each time they
|
|
199
|
-
to act on updates
|
|
234
|
+
Atoms emit values each time they change. You can subscribe callbacks to them
|
|
235
|
+
to act on updates.
|
|
236
|
+
|
|
237
|
+
Subscribing fires your callback **immediately** with the atom's current value,
|
|
238
|
+
then again on each subsequent change. "Change" is defined by the atom's equality
|
|
239
|
+
comparator, which **defaults to `Object.is`** — so setting an `Object.is`-equal
|
|
240
|
+
value is deduped and will not re-notify (see
|
|
241
|
+
[Equality & change detection](#equality--change-detection)).
|
|
200
242
|
|
|
201
243
|
```
|
|
202
244
|
const atom$ = Atom(3);
|
|
@@ -204,13 +246,79 @@ const atom$ = Atom(3);
|
|
|
204
246
|
const subscription = atom$.subscribe(val => {
|
|
205
247
|
console.log("Received value: ", val)
|
|
206
248
|
})
|
|
249
|
+
// immediately logs "Received value: 3"
|
|
207
250
|
|
|
208
|
-
atom$.
|
|
251
|
+
atom$.next(3) // deduped: Object.is-equal, no log
|
|
252
|
+
atom$.next(4) // "Received value: 4"
|
|
209
253
|
|
|
210
254
|
// Unsubscribe to clean up
|
|
211
255
|
subscription.unsubscribe();
|
|
212
256
|
```
|
|
213
257
|
|
|
258
|
+
### Equality & change detection
|
|
259
|
+
|
|
260
|
+
Every atom notifies its subscribers only when its value **changes**, and what
|
|
261
|
+
counts as a "change" is decided by an `equals(previous, next) => boolean`
|
|
262
|
+
comparator. When `equals` returns `true`, the atom still updates `value()` but
|
|
263
|
+
does **not** ping subscribers.
|
|
264
|
+
|
|
265
|
+
The default comparator for every atom — `Atom`, `derive`, `select`, and
|
|
266
|
+
`combine` — is `Object.is`:
|
|
267
|
+
|
|
268
|
+
- For primitives (`number`, `string`, `boolean`, ...) that's value equality.
|
|
269
|
+
- For objects and arrays it's **reference identity** — a brand-new object/array
|
|
270
|
+
is always treated as "changed," even if its contents are identical.
|
|
271
|
+
|
|
272
|
+
#### Reference vs content equality
|
|
273
|
+
|
|
274
|
+
Reference identity is the right default, but it breaks down when a producer
|
|
275
|
+
rebuilds fresh objects/arrays on every update (e.g. a game loop that rebuilds
|
|
276
|
+
its whole scene snapshot each tick). Every snapshot is a new reference, so
|
|
277
|
+
`Object.is` reports "changed" every tick and subscribers fire constantly even
|
|
278
|
+
when nothing meaningful changed.
|
|
279
|
+
|
|
280
|
+
Supply a **content** comparator to fix this:
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
const tickets$ = frame$.derive(selectTickets, {
|
|
284
|
+
equals: (a, b) =>
|
|
285
|
+
a.length === b.length &&
|
|
286
|
+
a.every((t, i) => t.id === b[i].id && t.status === b[i].status),
|
|
287
|
+
});
|
|
288
|
+
// re-emits only when ticket content actually changes
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
#### Where you can pass `equals`
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
Atom(value, { equals }) // base atoms
|
|
295
|
+
parent.derive(fn, { equals }) // derived atoms
|
|
296
|
+
parent.select(key, { equals }) // selected atoms
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
To force the old "notify on every update" behavior, pass `equals: () => false`.
|
|
300
|
+
|
|
301
|
+
#### You supply the comparator
|
|
302
|
+
|
|
303
|
+
`chem-rx` intentionally ships **no** `shallowEqual`/`deepEqual` helpers. A
|
|
304
|
+
generic shallow equal won't reach into nested or rebuilt structures (the tickets
|
|
305
|
+
example above would still see new element references), and a generic deep equal
|
|
306
|
+
is a correctness trap (`NaN`, `Date`, `Map`/`Set`, cycles, ...). Write the cheap
|
|
307
|
+
field comparison your data actually needs, or stamp a revision/version number on
|
|
308
|
+
the data and compare that.
|
|
309
|
+
|
|
310
|
+
#### React and beyond
|
|
311
|
+
|
|
312
|
+
Because equality lives on the atom (not in a React hook), content dedup benefits
|
|
313
|
+
**every** subscriber — React components, effects, and other derived atoms alike,
|
|
314
|
+
not just renders. React's `useSyncExternalStore` already bails out on
|
|
315
|
+
`Object.is`-equal snapshots; an atom-level `equals` is what gives you the
|
|
316
|
+
additional **content** dedup.
|
|
317
|
+
|
|
318
|
+
> Advanced tip: a memoizing selector that returns the _previous_ reference when
|
|
319
|
+
> the content is equal restores referential stability, so all downstream
|
|
320
|
+
> consumers can dedup off plain `Object.is` after a single comparison.
|
|
321
|
+
|
|
214
322
|
### Signals
|
|
215
323
|
|
|
216
324
|
Sometimes, all you want is something to ping you when there's an update. Signals
|
|
@@ -256,6 +364,8 @@ You can selectively subscribe to Signals, and selectively ping subscribers by ID
|
|
|
256
364
|
|
|
257
365
|
## Use with React
|
|
258
366
|
|
|
367
|
+
The root package is headless. React hooks are available from `chem-rx/react`.
|
|
368
|
+
|
|
259
369
|
### useAtom
|
|
260
370
|
|
|
261
371
|
`useAtom` automatically updates with new values in your react components.
|
|
@@ -264,7 +374,8 @@ If you want to update your atoms, you can simply call the same `next`, `set`, or
|
|
|
264
374
|
of react.
|
|
265
375
|
|
|
266
376
|
```
|
|
267
|
-
import { Atom
|
|
377
|
+
import { Atom } from 'chem-rx'
|
|
378
|
+
import { useAtom } from 'chem-rx/react'
|
|
268
379
|
|
|
269
380
|
const count$ = Atom(0)
|
|
270
381
|
|
|
@@ -273,18 +384,19 @@ function Counter() {
|
|
|
273
384
|
return (
|
|
274
385
|
<h1>
|
|
275
386
|
{count}
|
|
276
|
-
<button onClick={() => count$.
|
|
387
|
+
<button onClick={() => count$.next(count$.value() + 1)}>one up</button> ...
|
|
277
388
|
```
|
|
278
389
|
|
|
279
390
|
Remember that you can mix and match for any of your needs
|
|
280
391
|
|
|
281
392
|
### useSelectAtom
|
|
282
393
|
|
|
283
|
-
With `
|
|
394
|
+
With `useSelectAtom` you can select a specific key from an atom, and still have it live
|
|
284
395
|
update in your react component.
|
|
285
396
|
|
|
286
397
|
```
|
|
287
|
-
import { Atom
|
|
398
|
+
import { Atom } from 'chem-rx'
|
|
399
|
+
import { useSelectAtom } from 'chem-rx/react'
|
|
288
400
|
|
|
289
401
|
const count$ = Atom({ inner: 0 })
|
|
290
402
|
|
|
@@ -299,13 +411,14 @@ function Counter() {
|
|
|
299
411
|
### hydrateAtoms
|
|
300
412
|
|
|
301
413
|
With SSR, your atoms will likely need to be properly hydrated to prevent
|
|
302
|
-
server/client mismatches. You can use `
|
|
414
|
+
server/client mismatches. You can use `hydrateAtoms` as a simple solution for
|
|
303
415
|
seeding your client-side Atoms with the correct data.
|
|
304
416
|
|
|
305
417
|
NOTE: **`hydrateAtoms` caches values and only runs on the initial load by default**, to prevent re-hydration when client-side only changes are made to the component.
|
|
306
418
|
|
|
307
419
|
```
|
|
308
|
-
import { Atom,
|
|
420
|
+
import { Atom, hydrateAtoms } from 'chem-rx'
|
|
421
|
+
import { useAtom } from 'chem-rx/react'
|
|
309
422
|
|
|
310
423
|
const count$ = Atom(0)
|
|
311
424
|
const CounterPage = ({ countFromServer }) => {
|
|
@@ -372,32 +485,31 @@ There are several suggested "patterns" when using Atoms:
|
|
|
372
485
|
6. Name your derived atoms as `<baseAtom>_<derivedValue>$` to easily see which
|
|
373
486
|
atoms it derives from.
|
|
374
487
|
|
|
375
|
-
## Advanced Usage
|
|
488
|
+
## Advanced Usage
|
|
376
489
|
|
|
377
|
-
Behind the scenes, `chem-rx` uses
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
common patterns used when managing front-end data.
|
|
490
|
+
Behind the scenes, `chem-rx` uses a tiny synchronous external-store primitive to
|
|
491
|
+
enable reactivity. `derive`, `select`, and `combine` cover the common state
|
|
492
|
+
composition patterns without requiring a stream library.
|
|
381
493
|
|
|
382
|
-
If you
|
|
383
|
-
|
|
384
|
-
`
|
|
385
|
-
|
|
386
|
-
You can use any rxjs operations you want with `Atom.pipe`, which wraps
|
|
387
|
-
`Observable.pipe` to return an Atom.
|
|
494
|
+
If you already have an Observable-like source, you can still create an atom from
|
|
495
|
+
it as long as it has `subscribe` and, ideally, a synchronous `getValue` or
|
|
496
|
+
`value` method for the initial snapshot.
|
|
388
497
|
|
|
389
498
|
```
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
499
|
+
const source = {
|
|
500
|
+
getValue: () => 3,
|
|
501
|
+
subscribe: (next) => {
|
|
502
|
+
next(3);
|
|
503
|
+
return { unsubscribe: () => {} };
|
|
504
|
+
},
|
|
505
|
+
};
|
|
396
506
|
|
|
397
|
-
|
|
398
|
-
console.log(squared$.value());
|
|
507
|
+
const atom$ = Atom(source);
|
|
399
508
|
```
|
|
400
509
|
|
|
401
510
|
## Why...?
|
|
402
511
|
|
|
403
|
-
|
|
512
|
+
I wanted a framework-agnostic [jotai](https://github.com/pmndrs/jotai)-like
|
|
513
|
+
solution with a simpler API. The core atom model does not need a full stream
|
|
514
|
+
library, so `chem-rx` keeps the small atom surface and leaves heavier reactive
|
|
515
|
+
tooling optional.
|
package/dist/Atom.d.ts
CHANGED
|
@@ -1,71 +1,111 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AtomObserver, AtomSource, AtomSubscription } from "./store";
|
|
2
2
|
export type AtomTuple<T> = {
|
|
3
3
|
[K in keyof T]: ReadOnlyAtom<T[K]>;
|
|
4
4
|
};
|
|
5
|
+
type SelectedValue<T, K extends keyof T> = T extends readonly (infer W)[] ? W : T[K];
|
|
6
|
+
type SelectKey<T> = keyof NonNullable<T>;
|
|
7
|
+
type SelectValue<T, K extends SelectKey<T>> = Extract<T, null | undefined> extends never ? SelectedValue<NonNullable<T>, K> : SelectedValue<NonNullable<T>, K> | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Comparator used to decide whether an atom's value has changed.
|
|
10
|
+
*
|
|
11
|
+
* An atom notifies subscribers only when `equals(previous, next)` returns
|
|
12
|
+
* `false`. The default for every atom is {@link Object.is} (value equality for
|
|
13
|
+
* primitives, reference identity for objects/arrays). Supply a content
|
|
14
|
+
* comparator to dedup by data, or `() => false` to force every update to emit.
|
|
15
|
+
*/
|
|
16
|
+
export type Equals<T> = (previousValue: T, nextValue: T) => boolean;
|
|
17
|
+
type AtomOptions<T> = {
|
|
18
|
+
equals?: Equals<T>;
|
|
19
|
+
};
|
|
20
|
+
type AtomDependency<T> = {
|
|
21
|
+
getSnapshot: (force?: boolean) => T;
|
|
22
|
+
subscribe: (onDependencyChange: () => void) => AtomSubscription | (() => void) | void;
|
|
23
|
+
};
|
|
5
24
|
export declare class ReadOnlyAtom<T> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
private _store;
|
|
26
|
+
private _subscriptions;
|
|
27
|
+
private _dependency;
|
|
28
|
+
private _dependencySubscription;
|
|
29
|
+
private _subscriberCount;
|
|
30
|
+
private _equals;
|
|
31
|
+
/**
|
|
32
|
+
* @param options.equals Comparator deciding when the value has changed.
|
|
33
|
+
* Defaults to {@link Object.is}. Subscribers are notified only when it
|
|
34
|
+
* returns `false`.
|
|
35
|
+
*/
|
|
36
|
+
constructor(_value: T | AtomSource<T>, dependency?: AtomDependency<T>, options?: AtomOptions<T>);
|
|
37
|
+
/**
|
|
38
|
+
* Create a read-only atom whose value is derived from this atom.
|
|
39
|
+
*
|
|
40
|
+
* By default the derived atom notifies subscribers only when its computed
|
|
41
|
+
* output differs by {@link Object.is}. Pass `options.equals` to dedup by
|
|
42
|
+
* content (useful when `deriveFn` returns a fresh object/array each time), or
|
|
43
|
+
* `equals: () => false` to re-emit on every parent update.
|
|
44
|
+
*/
|
|
45
|
+
derive<A>(deriveFn: (value: T, index: number) => A, options?: AtomOptions<A>): ReadOnlyAtom<A>;
|
|
46
|
+
subscribe(observer: AtomObserver<T>): AtomSubscription;
|
|
25
47
|
value(): T;
|
|
26
48
|
dispose(): void;
|
|
27
|
-
get<K extends
|
|
28
|
-
|
|
49
|
+
get<K extends SelectKey<T>>(key: K): SelectValue<T, K>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a read-only atom that tracks `key` on this atom's value.
|
|
52
|
+
*
|
|
53
|
+
* By default the selected atom notifies subscribers only when the selected
|
|
54
|
+
* value differs by {@link Object.is}. Pass `options.equals` to dedup by
|
|
55
|
+
* content instead.
|
|
56
|
+
*/
|
|
57
|
+
select<K extends SelectKey<T>>(key: K, options?: AtomOptions<SelectValue<T, K>>): ReadOnlyAtom<SelectValue<T, K>>;
|
|
58
|
+
private _refresh;
|
|
59
|
+
private _retainDependency;
|
|
60
|
+
private _releaseDependency;
|
|
61
|
+
/** @internal */
|
|
62
|
+
_next(value: T): void;
|
|
63
|
+
/** @internal */
|
|
64
|
+
_subscribe(observer: AtomObserver<T>, options?: {
|
|
65
|
+
emitImmediately?: boolean;
|
|
66
|
+
}): AtomSubscription;
|
|
67
|
+
/** @internal */
|
|
68
|
+
_addSubscription(subscription: AtomSubscription | (() => void) | void): AtomSubscription;
|
|
29
69
|
}
|
|
30
70
|
export declare class BaseAtom<T> extends ReadOnlyAtom<T> {
|
|
31
71
|
next(nextVal: T): void;
|
|
32
|
-
set(nextKey:
|
|
72
|
+
set<K extends SelectKey<T>>(nextKey: K, nextValue: NonNullable<T>[K]): void;
|
|
33
73
|
}
|
|
34
|
-
export declare class NullableBaseAtom<T> extends BaseAtom<T> {
|
|
35
|
-
constructor(_value?: T |
|
|
36
|
-
get<K extends keyof T>(key: K): (T extends (infer W)[] ? T[number] : T[K]) | undefined;
|
|
37
|
-
select<K extends keyof T>(key: K): T extends (infer W)[] ? ArrayAtom<W> : NullableBaseAtom<T[K]>;
|
|
74
|
+
export declare class NullableBaseAtom<T> extends BaseAtom<T | null | undefined> {
|
|
75
|
+
constructor(_value?: T | null | undefined | AtomSource<T | null | undefined>, options?: AtomOptions<T | null | undefined>);
|
|
38
76
|
next(nextVal: T | null | undefined): void;
|
|
39
77
|
reset(): void;
|
|
40
78
|
}
|
|
41
79
|
export declare class ArrayAtom<T> extends BaseAtom<T[]> {
|
|
42
|
-
constructor(initialValue?: T[]);
|
|
80
|
+
constructor(initialValue?: T[] | AtomSource<T[]>, options?: AtomOptions<T[]>);
|
|
43
81
|
push(nextVal: T): void;
|
|
44
82
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export declare function Atom<T
|
|
83
|
+
/**
|
|
84
|
+
* Options for the {@link Atom} factory. `readOnly` produces a
|
|
85
|
+
* {@link ReadOnlyAtom}; `equals` sets the change comparator (defaults to
|
|
86
|
+
* {@link Object.is}).
|
|
87
|
+
*/
|
|
88
|
+
export type AtomFactoryOptions<T> = AtomOptions<T> & {
|
|
89
|
+
readOnly?: boolean;
|
|
90
|
+
};
|
|
91
|
+
export declare function Atom<T>(value: T | AtomSource<T>, readOnly: true): ReadOnlyAtom<T>;
|
|
92
|
+
export declare function Atom<T>(value: T | AtomSource<T>, options: AtomFactoryOptions<T> & {
|
|
93
|
+
readOnly: true;
|
|
94
|
+
}): ReadOnlyAtom<T>;
|
|
95
|
+
export declare function Atom<T extends any[]>(value: AtomSource<T>, options?: AtomFactoryOptions<T>): ArrayAtom<T[number]>;
|
|
96
|
+
export declare function Atom<T>(value: AtomSource<T>, options?: AtomFactoryOptions<T>): BaseAtom<T>;
|
|
97
|
+
export declare function Atom<T extends any[]>(value: T, options?: AtomFactoryOptions<T>): ArrayAtom<T[number]>;
|
|
59
98
|
export declare function Atom<T extends {
|
|
60
99
|
[key: string]: T[keyof T];
|
|
61
|
-
}>(value: T): BaseAtom<T>;
|
|
100
|
+
}>(value: T, options?: AtomFactoryOptions<T>): BaseAtom<T>;
|
|
62
101
|
export declare function Atom<T extends {
|
|
63
102
|
[key: string]: T[keyof T];
|
|
64
|
-
}>(value?: T): NullableBaseAtom<T>;
|
|
65
|
-
export declare function Atom<T>(value: T): BaseAtom<T>;
|
|
66
|
-
export declare function Atom<T>(value?: T): NullableBaseAtom<T>;
|
|
67
|
-
export declare function Atom<T>(value: T
|
|
103
|
+
}>(value?: T, options?: AtomFactoryOptions<T>): NullableBaseAtom<T>;
|
|
104
|
+
export declare function Atom<T>(value: T, options?: AtomFactoryOptions<T>): BaseAtom<T>;
|
|
105
|
+
export declare function Atom<T>(value?: T, options?: AtomFactoryOptions<T>): NullableBaseAtom<T>;
|
|
106
|
+
export declare function Atom<T>(value: T | AtomSource<T>, optionsOrReadOnly?: boolean | AtomFactoryOptions<T>): ReadOnlyAtom<T> | BaseAtom<T>;
|
|
68
107
|
export declare namespace Atom {
|
|
69
|
-
var combine: <A extends readonly unknown[]>(...
|
|
108
|
+
var combine: <A extends readonly unknown[]>(...atoms: AtomTuple<A>) => ReadOnlyAtom<A>;
|
|
70
109
|
}
|
|
110
|
+
export {};
|
|
71
111
|
//# sourceMappingURL=Atom.d.ts.map
|
package/dist/Atom.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Atom.d.ts","sourceRoot":"","sources":["../src/Atom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"Atom.d.ts","sourceRoot":"","sources":["../src/Atom.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAMjB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;KACxB,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC,CAAC;AAEF,KAAK,aAAa,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACrE,CAAC,GACD,CAAC,CAAC,CAAC,CAAC,CAAC;AAET,KAAK,SAAS,CAAC,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC;AAEzC,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,IACxC,OAAO,CAAC,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,SAAS,KAAK,GACtC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAChC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,EAAE,SAAS,EA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4
|
-
private
|
|
5
|
-
constructor();
|
|
3
|
+
private _listeners;
|
|
4
|
+
private _listenersById;
|
|
6
5
|
ping(value: T, id?: string): void;
|
|
7
|
-
subscribe(callback:
|
|
6
|
+
subscribe(callback: AtomListener<T>, id?: string): AtomSubscription;
|
|
8
7
|
}
|
|
9
8
|
//# sourceMappingURL=Signal.d.ts.map
|
package/dist/Signal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../src/Signal.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../src/Signal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAEjB,qBAAa,MAAM,CAAC,CAAC,GAAG,GAAG;IACzB,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,cAAc,CAAwC;IAE9D,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM;IAa1B,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,gBAAgB;CAqBpE"}
|