atom.io 0.0.0 → 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/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # MVP
1
+ ## features
2
2
  - [x] atoms and selectors
3
3
  - [x] implicit store
4
4
  - [x] readonly selectors
5
5
  - [x] settable selectors
6
6
  - [x] safe recursive update propagation
7
- - [x] safely expose atoms and selectors
7
+ - [x] "tokens" safely expose atoms and selectors
8
8
  - [x] give atoms and selectors separate types with a common base
9
9
  - [x] utility function to pass logger to your store
10
10
  - [x] selector memoization
@@ -12,19 +12,38 @@
12
12
  - [x] atom effects
13
13
  - [x] transactions
14
14
 
15
- # Features
16
- - [ ] atom default as function
17
- - [ ] atom default as promise
15
+
16
+ # atom.io
17
+ ## upcoming features
18
+ - [x] "lazy mode": only propagate updates downstream to selectors with an active subscription
19
+ - [x] async effects
20
+ - [x] atom default as function
21
+ - [x] check whether an atom is "default" (never set)
22
+ - [ ] timelines
18
23
  - [ ] resettable atoms
19
24
  - [ ] resettable selectors
20
- - [ ] optional default value for atoms
21
- - [ ] optional state keys
22
25
  - [ ] subscribe to transactions
26
+ - [ ] subscribe to token creation
23
27
  - [ ] logging levels (debug, info, warn, error)
28
+ - [ ] store observation api
29
+
30
+ ## fixes & improvements
31
+ - [x] refactor selector dependencies to be asymmetrical
32
+ - [ ] tokens explicitly contain the key of their family
33
+ - [ ] apply and emit transactions all at once
34
+
35
+ ## documentation
36
+ - [ ] document atom and selector families
37
+ - [ ] document atom and selector
38
+ - [ ] document transactions
39
+
40
+ # /react
41
+ ## features
42
+ - [x] useSubject
43
+ - [x] useStore
24
44
 
25
- # Performance Enhancements
26
- - [ ] refactor selector dependencies to be asymmetrical
27
- this would permit us to rebuild the dependency graph on every update,
28
- meaning more efficient memoization
29
- - [ ] only propagate updates downstream to selectors with an active subscription
30
- - [ ] trampoline for recursive propagation
45
+ # /effects
46
+ ## features
47
+ - [ ] localStorage and sessionStorage effects
48
+ - [ ] socket.io server effect
49
+ - [ ] socket.io client effect
@@ -0,0 +1,293 @@
1
+ import * as Rx from 'rxjs';
2
+ import { Hamt } from 'hamt_plus';
3
+ import { Refinement } from 'fp-ts/Refinement';
4
+
5
+ type Primitive = boolean | number | string | null;
6
+ type Serializable = Primitive | Readonly<{
7
+ [key: string]: Serializable;
8
+ }> | ReadonlyArray<Serializable>;
9
+ type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
10
+ type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
11
+ type Json = JsonArr | JsonObj | Primitive;
12
+
13
+ type Identified = {
14
+ id: string;
15
+ };
16
+
17
+ declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
18
+ type RelationType = (typeof RELATION_TYPES)[number];
19
+ type RelationData<CONTENT extends JsonObj | null = null> = {
20
+ contents: JsonObj<string, CONTENT>;
21
+ relations: JsonObj<string, string[]>;
22
+ relationType: RelationType;
23
+ };
24
+
25
+ type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
26
+ type NullSafeRest<MaybeArg> = MaybeArg extends null ? [] | [undefined] : [MaybeArg];
27
+
28
+ declare class Join<CONTENT extends JsonObj | null = null> implements RelationData<CONTENT> {
29
+ readonly relationType: `1:1` | `1:n` | `n:n`;
30
+ readonly relations: Record<string, string[]>;
31
+ readonly contents: Record<string, CONTENT>;
32
+ constructor(json?: Partial<RelationData<CONTENT>>);
33
+ toJSON(): RelationData<CONTENT>;
34
+ static fromJSON<CONTENT extends JsonObj | null = null>(json: Json, isContent?: Refinement<unknown, CONTENT>): Join<CONTENT>;
35
+ getRelatedId(id: string): string | undefined;
36
+ getRelatedIds(id: string): string[];
37
+ getContent(idA: string, idB: string): CONTENT | undefined;
38
+ getRelationEntries(id: string): [string, CONTENT][];
39
+ getRelationRecord(id: string): Record<string, CONTENT>;
40
+ getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
41
+ getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
42
+ setRelations(id: string, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT>;
43
+ set(idA: string, idB: string, ...rest: NullSafeRest<CONTENT>): Join<CONTENT>;
44
+ remove(idA: string, idB?: string): Join<CONTENT>;
45
+ }
46
+
47
+ interface Store {
48
+ valueMap: Hamt<any, string>;
49
+ selectorGraph: Join<{
50
+ source: string;
51
+ }>;
52
+ selectorAtoms: Join;
53
+ atoms: Hamt<Atom<any>, string>;
54
+ atomsAreDefault: Hamt<boolean, string>;
55
+ selectors: Hamt<Selector<any>, string>;
56
+ readonlySelectors: Hamt<ReadonlySelector<any>, string>;
57
+ operation: {
58
+ open: false;
59
+ } | {
60
+ open: true;
61
+ done: Set<string>;
62
+ prev: Hamt<any, string>;
63
+ };
64
+ transaction: {
65
+ open: false;
66
+ } | {
67
+ open: true;
68
+ prev: Pick<Store, `atoms` | `readonlySelectors` | `selectorGraph` | `selectors` | `valueMap`>;
69
+ };
70
+ config: {
71
+ name: string;
72
+ logger: Pick<Console, `error` | `info` | `warn`> | null;
73
+ };
74
+ }
75
+ declare const createStore: (name: string) => Store;
76
+ declare const IMPLICIT: {
77
+ STORE_INTERNAL: Store | undefined;
78
+ readonly STORE: Store;
79
+ };
80
+ declare const configure: (config: Partial<Store[`config`]>, store?: Store) => void;
81
+ declare const clearStore: (store?: Store) => void;
82
+
83
+ declare const getCachedState: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
84
+ declare const getSelectorState: <T>(selector: Selector<T> | ReadonlySelector<T>) => T;
85
+ declare function lookup(key: string, store: Store): AtomToken<unknown> | ReadonlyValueToken<unknown> | SelectorToken<unknown>;
86
+ declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>;
87
+ declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>;
88
+ declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T>;
89
+ declare function withdraw<T>(token: ReadonlyValueToken<T>, store: Store): ReadonlySelector<T>;
90
+ declare function withdraw<T>(token: ReadonlyValueToken<T> | StateToken<T>, store: Store): Atom<T> | ReadonlySelector<T> | Selector<T>;
91
+ declare function deposit<T>(state: Atom<T>): AtomToken<T>;
92
+ declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
93
+ declare function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>;
94
+ declare function deposit<T>(state: ReadonlySelector<T>): ReadonlyValueToken<T>;
95
+ declare function deposit<T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>): ReadonlyValueToken<T> | StateToken<T>;
96
+ declare const getState__INTERNAL: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
97
+
98
+ declare const evictDownStream: <T>(state: Atom<T>, store?: Store) => void;
99
+ declare const setAtomState: <T>(atom: Atom<T>, next: T | ((oldValue: T) => T), store?: Store) => void;
100
+ declare const setSelectorState: <T>(selector: Selector<T>, next: T | ((oldValue: T) => T), store?: Store) => void;
101
+ declare const setState__INTERNAL: <T>(state: Atom<T> | Selector<T>, value: T | ((oldValue: T) => T), store?: Store) => void;
102
+
103
+ declare const isAtomDefault: (key: string, store?: Store) => boolean;
104
+ declare const isSelectorDefault: (key: string, store?: Store) => boolean;
105
+
106
+ type ƒn = (...parameters: any[]) => any;
107
+ type Transactors = {
108
+ get: <S>(state: ReadonlyValueToken<S> | StateToken<S>) => S;
109
+ set: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void;
110
+ };
111
+ type ReadonlyTransactors = Pick<Transactors, `get`>;
112
+ type Action<ƒ extends ƒn> = (transactors: Transactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
113
+ type TransactionOptions<ƒ extends ƒn> = {
114
+ key: string;
115
+ do: Action<ƒ>;
116
+ };
117
+ declare const transaction: <ƒ extends ƒn>(options: TransactionOptions<ƒ>, store?: Store) => ((...parameters: Parameters<ƒ>) => ReturnType<ƒ>) & {
118
+ key: string;
119
+ };
120
+
121
+ declare const lookupSelectorSources: (key: string, store: Store) => (AtomToken<unknown> | ReadonlyValueToken<unknown> | SelectorToken<unknown>)[];
122
+ declare const traceSelectorAtoms: (selectorKey: string, dependency: ReadonlyValueToken<unknown> | StateToken<unknown>, store: Store) => AtomToken<unknown>[];
123
+ declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) => AtomToken<unknown>[];
124
+ declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlyValueToken<unknown> | StateToken<unknown>, store: Store) => void;
125
+ declare const registerSelector: (selectorKey: string, store?: Store) => Transactors;
126
+
127
+ declare const subscribeToRootAtoms: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => {
128
+ unsubscribe: () => void;
129
+ }[] | null;
130
+
131
+ declare const startAction: (store: Store) => void;
132
+ declare const finishAction: (store: Store) => void;
133
+ declare const isDone: (key: string, store?: Store) => boolean;
134
+ declare const markDone: (key: string, store?: Store) => void;
135
+ declare const recallState: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
136
+
137
+ declare const finishTransaction: (store: Store) => void;
138
+ declare const startTransaction: (store: Store) => void;
139
+ declare const abortTransaction: (store: Store) => void;
140
+
141
+ type Atom<T> = {
142
+ key: string;
143
+ subject: Rx.Subject<{
144
+ newValue: T;
145
+ oldValue: T;
146
+ }>;
147
+ default: T;
148
+ };
149
+ type Selector<T> = {
150
+ key: string;
151
+ subject: Rx.Subject<{
152
+ newValue: T;
153
+ oldValue: T;
154
+ }>;
155
+ get: () => T;
156
+ set: (newValue: T | ((oldValue: T) => T)) => void;
157
+ };
158
+ type ReadonlySelector<T> = Omit<Selector<T>, `set`>;
159
+
160
+ type index_Atom<T> = Atom<T>;
161
+ declare const index_IMPLICIT: typeof IMPLICIT;
162
+ type index_ReadonlySelector<T> = ReadonlySelector<T>;
163
+ type index_Selector<T> = Selector<T>;
164
+ type index_Store = Store;
165
+ declare const index_abortTransaction: typeof abortTransaction;
166
+ declare const index_clearStore: typeof clearStore;
167
+ declare const index_configure: typeof configure;
168
+ declare const index_createStore: typeof createStore;
169
+ declare const index_deposit: typeof deposit;
170
+ declare const index_evictDownStream: typeof evictDownStream;
171
+ declare const index_finishAction: typeof finishAction;
172
+ declare const index_finishTransaction: typeof finishTransaction;
173
+ declare const index_getCachedState: typeof getCachedState;
174
+ declare const index_getSelectorState: typeof getSelectorState;
175
+ declare const index_getState__INTERNAL: typeof getState__INTERNAL;
176
+ declare const index_isAtomDefault: typeof isAtomDefault;
177
+ declare const index_isDone: typeof isDone;
178
+ declare const index_isSelectorDefault: typeof isSelectorDefault;
179
+ declare const index_lookup: typeof lookup;
180
+ declare const index_lookupSelectorSources: typeof lookupSelectorSources;
181
+ declare const index_markDone: typeof markDone;
182
+ declare const index_recallState: typeof recallState;
183
+ declare const index_registerSelector: typeof registerSelector;
184
+ declare const index_setAtomState: typeof setAtomState;
185
+ declare const index_setSelectorState: typeof setSelectorState;
186
+ declare const index_setState__INTERNAL: typeof setState__INTERNAL;
187
+ declare const index_startAction: typeof startAction;
188
+ declare const index_startTransaction: typeof startTransaction;
189
+ declare const index_subscribeToRootAtoms: typeof subscribeToRootAtoms;
190
+ declare const index_traceAllSelectorAtoms: typeof traceAllSelectorAtoms;
191
+ declare const index_traceSelectorAtoms: typeof traceSelectorAtoms;
192
+ declare const index_updateSelectorAtoms: typeof updateSelectorAtoms;
193
+ declare const index_withdraw: typeof withdraw;
194
+ declare namespace index {
195
+ export {
196
+ index_Atom as Atom,
197
+ index_IMPLICIT as IMPLICIT,
198
+ index_ReadonlySelector as ReadonlySelector,
199
+ index_Selector as Selector,
200
+ index_Store as Store,
201
+ index_abortTransaction as abortTransaction,
202
+ index_clearStore as clearStore,
203
+ index_configure as configure,
204
+ index_createStore as createStore,
205
+ index_deposit as deposit,
206
+ index_evictDownStream as evictDownStream,
207
+ index_finishAction as finishAction,
208
+ index_finishTransaction as finishTransaction,
209
+ index_getCachedState as getCachedState,
210
+ index_getSelectorState as getSelectorState,
211
+ index_getState__INTERNAL as getState__INTERNAL,
212
+ index_isAtomDefault as isAtomDefault,
213
+ index_isDone as isDone,
214
+ index_isSelectorDefault as isSelectorDefault,
215
+ index_lookup as lookup,
216
+ index_lookupSelectorSources as lookupSelectorSources,
217
+ index_markDone as markDone,
218
+ index_recallState as recallState,
219
+ index_registerSelector as registerSelector,
220
+ index_setAtomState as setAtomState,
221
+ index_setSelectorState as setSelectorState,
222
+ index_setState__INTERNAL as setState__INTERNAL,
223
+ index_startAction as startAction,
224
+ index_startTransaction as startTransaction,
225
+ index_subscribeToRootAtoms as subscribeToRootAtoms,
226
+ index_traceAllSelectorAtoms as traceAllSelectorAtoms,
227
+ index_traceSelectorAtoms as traceSelectorAtoms,
228
+ index_updateSelectorAtoms as updateSelectorAtoms,
229
+ index_withdraw as withdraw,
230
+ };
231
+ }
232
+
233
+ type Effectors<T> = {
234
+ setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
235
+ onSet: (callback: (options: {
236
+ newValue: T;
237
+ oldValue: T;
238
+ }) => void) => void;
239
+ };
240
+ type AtomEffect<T> = (tools: Effectors<T>) => void;
241
+ type AtomOptions<T> = {
242
+ key: string;
243
+ default: T | (() => T);
244
+ effects?: AtomEffect<T>[];
245
+ };
246
+ declare const atom: <T>(options: AtomOptions<T>, store?: Store) => AtomToken<T>;
247
+ type AtomFamilyOptions<T, K extends Serializable> = {
248
+ key: string;
249
+ default: T | ((key: K) => T);
250
+ effects?: (key: K) => AtomEffect<T>[];
251
+ };
252
+ declare const atomFamily: <T, K extends Serializable>(options: AtomFamilyOptions<T, K>, store?: Store) => (key: K) => AtomToken<T>;
253
+
254
+ type SelectorOptions<T> = {
255
+ key: string;
256
+ get: (readonlyTransactors: ReadonlyTransactors) => T;
257
+ set: (transactors: Transactors, newValue: T) => void;
258
+ };
259
+ type ReadonlySelectorOptions<T> = Omit<SelectorOptions<T>, `set`>;
260
+ declare function selector<T>(options: SelectorOptions<T>, store?: Store): SelectorToken<T>;
261
+ declare function selector<T>(options: ReadonlySelectorOptions<T>, store?: Store): ReadonlyValueToken<T>;
262
+ type SelectorFamilyOptions<T, K extends Serializable> = {
263
+ key: string;
264
+ get: (key: K) => (readonlyTransactors: ReadonlyTransactors) => T;
265
+ set: (key: K) => (transactors: Transactors, newValue: T) => void;
266
+ };
267
+ type ReadonlySelectorFamilyOptions<T, K extends Serializable> = Omit<SelectorFamilyOptions<T, K>, `set`>;
268
+ declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>, store?: Store): (key: K) => SelectorToken<T>;
269
+ declare function selectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store?: Store): (key: K) => ReadonlyValueToken<T>;
270
+
271
+ type AtomToken<_> = {
272
+ key: string;
273
+ type: `atom`;
274
+ };
275
+ type SelectorToken<_> = {
276
+ key: string;
277
+ type: `selector`;
278
+ };
279
+ type StateToken<T> = AtomToken<T> | SelectorToken<T>;
280
+ type ReadonlyValueToken<_> = {
281
+ key: string;
282
+ type: `readonly_selector`;
283
+ };
284
+ declare const getState: <T>(token: ReadonlyValueToken<T> | StateToken<T>, store?: Store) => T;
285
+ declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store) => void;
286
+ declare const isDefault: (token: ReadonlyValueToken<unknown> | StateToken<unknown>, store?: Store) => boolean;
287
+ type ObserveState<T> = (change: {
288
+ newValue: T;
289
+ oldValue: T;
290
+ }) => void;
291
+ declare const subscribe: <T>(token: ReadonlyValueToken<T> | StateToken<T>, observe: ObserveState<T>, store?: Store) => (() => void);
292
+
293
+ export { AtomToken as A, Effectors as E, ObserveState as O, ReadonlyValueToken as R, Store as S, Transactors as T, StateToken as a, SelectorToken as b, configure as c, isDefault as d, subscribe as e, AtomEffect as f, getState as g, AtomOptions as h, index as i, atom as j, AtomFamilyOptions as k, atomFamily as l, SelectorOptions as m, ReadonlySelectorOptions as n, selector as o, SelectorFamilyOptions as p, ReadonlySelectorFamilyOptions as q, selectorFamily as r, setState as s, ReadonlyTransactors as t, Action as u, TransactionOptions as v, transaction as w, ƒn as ƒ };
package/dist/index.d.ts CHANGED
@@ -1,257 +1,4 @@
1
- import * as Rx from 'rxjs';
2
- import { Hamt } from 'hamt_plus';
3
- import { Refinement } from 'fp-ts/Refinement';
4
-
5
- type Primitive = boolean | number | string | null;
6
- type Serializable = Primitive | Readonly<{
7
- [key: string]: Serializable;
8
- }> | ReadonlyArray<Serializable>;
9
- type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
10
- type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
11
- type Json = JsonArr | JsonObj | Primitive;
12
-
13
- type Identified = {
14
- id: string;
15
- };
16
-
17
- declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
18
- type RelationType = (typeof RELATION_TYPES)[number];
19
- type RelationData<CONTENT extends JsonObj | null = null> = {
20
- contents: JsonObj<string, CONTENT>;
21
- relations: JsonObj<string, string[]>;
22
- relationType: RelationType;
23
- };
24
-
25
- type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
26
- type NullSafeRest<MaybeArg> = MaybeArg extends null ? [] | [undefined] : [MaybeArg];
27
-
28
- declare class Join<CONTENT extends JsonObj | null = null> implements RelationData<CONTENT> {
29
- readonly relationType: `1:1` | `1:n` | `n:n`;
30
- readonly relations: Record<string, string[]>;
31
- readonly contents: Record<string, CONTENT>;
32
- constructor(json?: Partial<RelationData<CONTENT>>);
33
- toJSON(): RelationData<CONTENT>;
34
- static fromJSON<CONTENT extends JsonObj | null = null>(json: Json, isContent?: Refinement<unknown, CONTENT>): Join<CONTENT>;
35
- getRelatedId(id: string): string | undefined;
36
- getRelatedIds(id: string): string[];
37
- getContent(idA: string, idB: string): CONTENT | undefined;
38
- getRelationEntries(id: string): [string, CONTENT][];
39
- getRelationRecord(id: string): Record<string, CONTENT>;
40
- getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
41
- getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
42
- setRelations(id: string, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT>;
43
- set(idA: string, idB: string, ...rest: NullSafeRest<CONTENT>): Join<CONTENT>;
44
- remove(idA: string, idB?: string): Join<CONTENT>;
45
- }
46
-
47
- interface Store {
48
- valueMap: Hamt<any, string>;
49
- selectorGraph: Join;
50
- selectors: Hamt<Selector<any>, string>;
51
- readonlySelectors: Hamt<ReadonlySelector<any>, string>;
52
- atoms: Hamt<Atom<any>, string>;
53
- operation: {
54
- open: false;
55
- } | {
56
- open: true;
57
- done: Set<string>;
58
- prev: Hamt<any, string>;
59
- };
60
- transaction: {
61
- open: false;
62
- } | {
63
- open: true;
64
- prev: Pick<Store, `atoms` | `readonlySelectors` | `selectorGraph` | `selectors` | `valueMap`>;
65
- };
66
- config: {
67
- name: string;
68
- logger: Pick<Console, `error` | `info` | `warn`> | null;
69
- };
70
- }
71
- declare const createStore: (name: string) => Store;
72
- declare const IMPLICIT: {
73
- STORE_INTERNAL: Store | undefined;
74
- readonly STORE: Store;
75
- };
76
- declare const configure: (config: Partial<Store[`config`]>, store?: Store) => void;
77
- declare const clearStore: (store?: Store) => void;
78
-
79
- declare const getCachedState: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
80
- declare const getSelectorState: <T>(selector: Selector<T> | ReadonlySelector<T>) => T;
81
- declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>;
82
- declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>;
83
- declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T>;
84
- declare function withdraw<T>(token: ReadonlyValueToken<T>, store: Store): ReadonlySelector<T>;
85
- declare function withdraw<T>(token: ReadonlyValueToken<T> | StateToken<T>, store: Store): Atom<T> | ReadonlySelector<T> | Selector<T>;
86
- declare function deposit<T>(state: Atom<T>): AtomToken<T>;
87
- declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
88
- declare function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>;
89
- declare function deposit<T>(state: ReadonlySelector<T>): ReadonlyValueToken<T>;
90
- declare function deposit<T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>): ReadonlyValueToken<T> | StateToken<T>;
91
- declare const getState__INTERNAL: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
92
-
93
- declare const propagateChanges: <T>(state: Atom<T> | Selector<T>, store?: Store) => void;
94
- declare const setAtomState: <T>(atom: Atom<T>, next: T | ((oldValue: T) => T), store?: Store) => void;
95
- declare const setSelectorState: <T>(selector: Selector<T>, next: T | ((oldValue: T) => T), store?: Store) => void;
96
- declare const setState__INTERNAL: <T>(token: StateToken<T>, value: T | ((oldValue: T) => T), store?: Store) => void;
97
-
98
- declare const finishAction: (store: Store) => void;
99
- declare const startAction: (store: Store) => void;
100
- declare const isDone: (key: string, store?: Store) => boolean;
101
- declare const markDone: (key: string, store?: Store) => void;
102
- declare const recall: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
103
-
104
- declare const finishTransaction: (store: Store) => void;
105
- declare const startTransaction: (store: Store) => void;
106
- declare const abortTransaction: (store: Store) => void;
107
-
108
- type Atom<T> = {
109
- key: string;
110
- subject: Rx.Subject<{
111
- newValue: T;
112
- oldValue: T;
113
- }>;
114
- default: T;
115
- };
116
- type Selector<T> = {
117
- key: string;
118
- subject: Rx.Subject<{
119
- newValue: T;
120
- oldValue: T;
121
- }>;
122
- get: () => T;
123
- set: (newValue: T | ((oldValue: T) => T)) => void;
124
- };
125
- type ReadonlySelector<T> = Omit<Selector<T>, `set`>;
126
-
127
- type index_Atom<T> = Atom<T>;
128
- declare const index_IMPLICIT: typeof IMPLICIT;
129
- type index_ReadonlySelector<T> = ReadonlySelector<T>;
130
- type index_Selector<T> = Selector<T>;
131
- type index_Store = Store;
132
- declare const index_abortTransaction: typeof abortTransaction;
133
- declare const index_clearStore: typeof clearStore;
134
- declare const index_configure: typeof configure;
135
- declare const index_createStore: typeof createStore;
136
- declare const index_deposit: typeof deposit;
137
- declare const index_finishAction: typeof finishAction;
138
- declare const index_finishTransaction: typeof finishTransaction;
139
- declare const index_getCachedState: typeof getCachedState;
140
- declare const index_getSelectorState: typeof getSelectorState;
141
- declare const index_getState__INTERNAL: typeof getState__INTERNAL;
142
- declare const index_isDone: typeof isDone;
143
- declare const index_markDone: typeof markDone;
144
- declare const index_propagateChanges: typeof propagateChanges;
145
- declare const index_recall: typeof recall;
146
- declare const index_setAtomState: typeof setAtomState;
147
- declare const index_setSelectorState: typeof setSelectorState;
148
- declare const index_setState__INTERNAL: typeof setState__INTERNAL;
149
- declare const index_startAction: typeof startAction;
150
- declare const index_startTransaction: typeof startTransaction;
151
- declare const index_withdraw: typeof withdraw;
152
- declare namespace index {
153
- export {
154
- index_Atom as Atom,
155
- index_IMPLICIT as IMPLICIT,
156
- index_ReadonlySelector as ReadonlySelector,
157
- index_Selector as Selector,
158
- index_Store as Store,
159
- index_abortTransaction as abortTransaction,
160
- index_clearStore as clearStore,
161
- index_configure as configure,
162
- index_createStore as createStore,
163
- index_deposit as deposit,
164
- index_finishAction as finishAction,
165
- index_finishTransaction as finishTransaction,
166
- index_getCachedState as getCachedState,
167
- index_getSelectorState as getSelectorState,
168
- index_getState__INTERNAL as getState__INTERNAL,
169
- index_isDone as isDone,
170
- index_markDone as markDone,
171
- index_propagateChanges as propagateChanges,
172
- index_recall as recall,
173
- index_setAtomState as setAtomState,
174
- index_setSelectorState as setSelectorState,
175
- index_setState__INTERNAL as setState__INTERNAL,
176
- index_startAction as startAction,
177
- index_startTransaction as startTransaction,
178
- index_withdraw as withdraw,
179
- };
180
- }
181
-
182
- type Effectors<T> = {
183
- setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
184
- onSet: (callback: (options: {
185
- newValue: T;
186
- oldValue: T;
187
- }) => void) => void;
188
- };
189
- type AtomEffect<T> = (tools: Effectors<T>) => void;
190
- type AtomOptions<T> = {
191
- key: string;
192
- default: T;
193
- effects?: AtomEffect<T>[];
194
- };
195
- declare const atom: <T>(options: AtomOptions<T>, store?: Store) => AtomToken<T>;
196
- type AtomFamilyOptions<T, K extends Serializable> = {
197
- key: string;
198
- default: T | ((key: K) => T);
199
- effects?: (key: K) => AtomEffect<T>[];
200
- };
201
- declare const atomFamily: <T, K extends Serializable>(options: AtomFamilyOptions<T, K>, store?: Store) => (key: K) => AtomToken<T>;
202
-
203
- type ƒn = (...parameters: any[]) => any;
204
- type Transactors = {
205
- get: <S>(state: ReadonlyValueToken<S> | StateToken<S>) => S;
206
- set: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void;
207
- };
208
- type ReadonlyTransactors = Pick<Transactors, `get`>;
209
- type Action<ƒ extends ƒn> = (transactors: Transactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
210
- type TransactionOptions<ƒ extends ƒn> = {
211
- key: string;
212
- do: Action<ƒ>;
213
- };
214
- declare const transaction: <ƒ extends ƒn>(options: TransactionOptions<ƒ>, store?: Store) => ((...parameters: Parameters<ƒ>) => ReturnType<ƒ>) & {
215
- key: string;
216
- };
217
-
218
- type SelectorOptions<T> = {
219
- key: string;
220
- get: (readonlyTransactors: ReadonlyTransactors) => T;
221
- set: (transactors: Transactors, newValue: T) => void;
222
- };
223
- type ReadonlySelectorOptions<T> = Omit<SelectorOptions<T>, `set`>;
224
- declare function selector<T>(options: SelectorOptions<T>, store?: Store): SelectorToken<T>;
225
- declare function selector<T>(options: ReadonlySelectorOptions<T>, store?: Store): ReadonlyValueToken<T>;
226
- type SelectorFamilyOptions<T, K extends Serializable> = {
227
- key: string;
228
- get: (key: K) => (readonlyTransactors: ReadonlyTransactors) => T;
229
- set: (key: K) => (transactors: Transactors, newValue: T) => void;
230
- };
231
- type ReadonlySelectorFamilyOptions<T, K extends Serializable> = Omit<SelectorFamilyOptions<T, K>, `set`>;
232
- declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>, store?: Store): (key: K) => SelectorToken<T>;
233
- declare function selectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store?: Store): (key: K) => ReadonlyValueToken<T>;
234
- declare const registerSelector: (selectorKey: string, store?: Store) => Transactors;
235
-
236
- interface AtomToken<_> {
237
- key: string;
238
- type: `atom`;
239
- }
240
- interface SelectorToken<_> {
241
- key: string;
242
- type: `selector`;
243
- }
244
- type StateToken<T> = AtomToken<T> | SelectorToken<T>;
245
- interface ReadonlyValueToken<_> {
246
- key: string;
247
- type: `readonly_selector`;
248
- }
249
- declare const getState: <T>(token: ReadonlyValueToken<T> | StateToken<T>, store?: Store) => T;
250
- declare const setState: <State, Value extends State>(state: StateToken<State>, value: Value | ((oldValue: State) => Value), store?: Store) => void;
251
- type Observe<T> = (change: {
252
- newValue: T;
253
- oldValue: T;
254
- }) => void;
255
- declare const subscribe: <T>(token: ReadonlyValueToken<T> | StateToken<T>, observe: Observe<T>, store?: Store) => (() => void);
256
-
257
- export { Action, AtomEffect, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, Observe, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlyTransactors, ReadonlyValueToken, SelectorFamilyOptions, SelectorOptions, SelectorToken, StateToken, TransactionOptions, Transactors, index as __INTERNAL__, atom, atomFamily, configure, getState, registerSelector, selector, selectorFamily, setState, subscribe, transaction, ƒn };
1
+ export { u as Action, f as AtomEffect, k as AtomFamilyOptions, h as AtomOptions, A as AtomToken, E as Effectors, O as ObserveState, q as ReadonlySelectorFamilyOptions, n as ReadonlySelectorOptions, t as ReadonlyTransactors, R as ReadonlyValueToken, p as SelectorFamilyOptions, m as SelectorOptions, b as SelectorToken, a as StateToken, v as TransactionOptions, T as Transactors, i as __INTERNAL__, j as atom, l as atomFamily, c as configure, g as getState, d as isDefault, o as selector, r as selectorFamily, s as setState, e as subscribe, w as transaction, ƒ as ƒn } from './index-9d9f5a05.js';
2
+ import 'rxjs';
3
+ import 'hamt_plus';
4
+ import 'fp-ts/Refinement';