atom.io 0.1.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,4 +1,4 @@
1
- ## MVP
1
+ ## features
2
2
  - [x] atoms and selectors
3
3
  - [x] implicit store
4
4
  - [x] readonly selectors
@@ -12,25 +12,25 @@
12
12
  - [x] atom effects
13
13
  - [x] transactions
14
14
 
15
+
15
16
  # atom.io
16
- ## features
17
- - [ ] atom default as function
18
- - [ ] async effects
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
19
23
  - [ ] resettable atoms
20
24
  - [ ] resettable selectors
21
25
  - [ ] subscribe to transactions
22
26
  - [ ] subscribe to token creation
23
27
  - [ ] logging levels (debug, info, warn, error)
24
28
  - [ ] store observation api
25
- - [ ] "lazy mode": only propagate updates downstream to selectors with an active subscription
26
- - [ ] optional default value for atoms
27
- - [ ] optional state keys
29
+
28
30
  ## fixes & improvements
29
- - [ ] refactor selector dependencies to be asymmetrical
30
- just include the id of the leader in the relation between the leader and the follower
31
- this will permit us to rebuild the dependency graph on every update
31
+ - [x] refactor selector dependencies to be asymmetrical
32
+ - [ ] tokens explicitly contain the key of their family
32
33
  - [ ] apply and emit transactions all at once
33
- - [ ] trampoline for recursive propagation
34
34
 
35
35
  ## documentation
36
36
  - [ ] document atom and selector families
@@ -46,10 +46,14 @@ declare class Join<CONTENT extends JsonObj | null = null> implements RelationDat
46
46
 
47
47
  interface Store {
48
48
  valueMap: Hamt<any, string>;
49
- selectorGraph: Join;
49
+ selectorGraph: Join<{
50
+ source: string;
51
+ }>;
52
+ selectorAtoms: Join;
53
+ atoms: Hamt<Atom<any>, string>;
54
+ atomsAreDefault: Hamt<boolean, string>;
50
55
  selectors: Hamt<Selector<any>, string>;
51
56
  readonlySelectors: Hamt<ReadonlySelector<any>, string>;
52
- atoms: Hamt<Atom<any>, string>;
53
57
  operation: {
54
58
  open: false;
55
59
  } | {
@@ -78,6 +82,7 @@ declare const clearStore: (store?: Store) => void;
78
82
 
79
83
  declare const getCachedState: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
80
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>;
81
86
  declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>;
82
87
  declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>;
83
88
  declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T>;
@@ -90,16 +95,44 @@ declare function deposit<T>(state: ReadonlySelector<T>): ReadonlyValueToken<T>;
90
95
  declare function deposit<T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>): ReadonlyValueToken<T> | StateToken<T>;
91
96
  declare const getState__INTERNAL: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
92
97
 
93
- declare const propagateDown: <T>(state: Atom<T> | Selector<T>, store?: Store) => void;
98
+ declare const evictDownStream: <T>(state: Atom<T>, store?: Store) => void;
94
99
  declare const setAtomState: <T>(atom: Atom<T>, next: T | ((oldValue: T) => T), store?: Store) => void;
95
100
  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;
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;
97
130
 
98
131
  declare const startAction: (store: Store) => void;
99
132
  declare const finishAction: (store: Store) => void;
100
133
  declare const isDone: (key: string, store?: Store) => boolean;
101
134
  declare const markDone: (key: string, store?: Store) => void;
102
- declare const recall: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
135
+ declare const recallState: <T>(state: Atom<T> | Selector<T> | ReadonlySelector<T>, store?: Store) => T;
103
136
 
104
137
  declare const finishTransaction: (store: Store) => void;
105
138
  declare const startTransaction: (store: Store) => void;
@@ -134,20 +167,29 @@ declare const index_clearStore: typeof clearStore;
134
167
  declare const index_configure: typeof configure;
135
168
  declare const index_createStore: typeof createStore;
136
169
  declare const index_deposit: typeof deposit;
170
+ declare const index_evictDownStream: typeof evictDownStream;
137
171
  declare const index_finishAction: typeof finishAction;
138
172
  declare const index_finishTransaction: typeof finishTransaction;
139
173
  declare const index_getCachedState: typeof getCachedState;
140
174
  declare const index_getSelectorState: typeof getSelectorState;
141
175
  declare const index_getState__INTERNAL: typeof getState__INTERNAL;
176
+ declare const index_isAtomDefault: typeof isAtomDefault;
142
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;
143
181
  declare const index_markDone: typeof markDone;
144
- declare const index_propagateDown: typeof propagateDown;
145
- declare const index_recall: typeof recall;
182
+ declare const index_recallState: typeof recallState;
183
+ declare const index_registerSelector: typeof registerSelector;
146
184
  declare const index_setAtomState: typeof setAtomState;
147
185
  declare const index_setSelectorState: typeof setSelectorState;
148
186
  declare const index_setState__INTERNAL: typeof setState__INTERNAL;
149
187
  declare const index_startAction: typeof startAction;
150
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;
151
193
  declare const index_withdraw: typeof withdraw;
152
194
  declare namespace index {
153
195
  export {
@@ -161,20 +203,29 @@ declare namespace index {
161
203
  index_configure as configure,
162
204
  index_createStore as createStore,
163
205
  index_deposit as deposit,
206
+ index_evictDownStream as evictDownStream,
164
207
  index_finishAction as finishAction,
165
208
  index_finishTransaction as finishTransaction,
166
209
  index_getCachedState as getCachedState,
167
210
  index_getSelectorState as getSelectorState,
168
211
  index_getState__INTERNAL as getState__INTERNAL,
212
+ index_isAtomDefault as isAtomDefault,
169
213
  index_isDone as isDone,
214
+ index_isSelectorDefault as isSelectorDefault,
215
+ index_lookup as lookup,
216
+ index_lookupSelectorSources as lookupSelectorSources,
170
217
  index_markDone as markDone,
171
- index_propagateDown as propagateDown,
172
- index_recall as recall,
218
+ index_recallState as recallState,
219
+ index_registerSelector as registerSelector,
173
220
  index_setAtomState as setAtomState,
174
221
  index_setSelectorState as setSelectorState,
175
222
  index_setState__INTERNAL as setState__INTERNAL,
176
223
  index_startAction as startAction,
177
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,
178
229
  index_withdraw as withdraw,
179
230
  };
180
231
  }
@@ -189,7 +240,7 @@ type Effectors<T> = {
189
240
  type AtomEffect<T> = (tools: Effectors<T>) => void;
190
241
  type AtomOptions<T> = {
191
242
  key: string;
192
- default: T;
243
+ default: T | (() => T);
193
244
  effects?: AtomEffect<T>[];
194
245
  };
195
246
  declare const atom: <T>(options: AtomOptions<T>, store?: Store) => AtomToken<T>;
@@ -200,21 +251,6 @@ type AtomFamilyOptions<T, K extends Serializable> = {
200
251
  };
201
252
  declare const atomFamily: <T, K extends Serializable>(options: AtomFamilyOptions<T, K>, store?: Store) => (key: K) => AtomToken<T>;
202
253
 
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
254
  type SelectorOptions<T> = {
219
255
  key: string;
220
256
  get: (readonlyTransactors: ReadonlyTransactors) => T;
@@ -231,7 +267,6 @@ type SelectorFamilyOptions<T, K extends Serializable> = {
231
267
  type ReadonlySelectorFamilyOptions<T, K extends Serializable> = Omit<SelectorFamilyOptions<T, K>, `set`>;
232
268
  declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>, store?: Store): (key: K) => SelectorToken<T>;
233
269
  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
270
 
236
271
  type AtomToken<_> = {
237
272
  key: string;
@@ -247,11 +282,12 @@ type ReadonlyValueToken<_> = {
247
282
  type: `readonly_selector`;
248
283
  };
249
284
  declare const getState: <T>(token: ReadonlyValueToken<T> | StateToken<T>, store?: Store) => T;
250
- declare const setState: <T, New extends T>(state: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store) => void;
251
- type Observe<T> = (change: {
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: {
252
288
  newValue: T;
253
289
  oldValue: T;
254
290
  }) => void;
255
- declare const subscribe: <T>(token: ReadonlyValueToken<T> | StateToken<T>, observe: Observe<T>, store?: Store) => (() => void);
291
+ declare const subscribe: <T>(token: ReadonlyValueToken<T> | StateToken<T>, observe: ObserveState<T>, store?: Store) => (() => void);
256
292
 
257
- export { AtomToken as A, Effectors as E, Observe as O, ReadonlyValueToken as R, Store as S, Transactors as T, StateToken as a, SelectorToken as b, configure as c, subscribe as d, AtomEffect as e, AtomOptions as f, getState as g, atom as h, index as i, AtomFamilyOptions as j, atomFamily as k, SelectorOptions as l, ReadonlySelectorOptions as m, selector as n, SelectorFamilyOptions as o, ReadonlySelectorFamilyOptions as p, selectorFamily as q, registerSelector as r, setState as s, ReadonlyTransactors as t, Action as u, TransactionOptions as v, transaction as w, ƒn as ƒ };
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,4 +1,4 @@
1
- export { u as Action, e as AtomEffect, j as AtomFamilyOptions, f as AtomOptions, A as AtomToken, E as Effectors, O as Observe, p as ReadonlySelectorFamilyOptions, m as ReadonlySelectorOptions, t as ReadonlyTransactors, R as ReadonlyValueToken, o as SelectorFamilyOptions, l as SelectorOptions, b as SelectorToken, a as StateToken, v as TransactionOptions, T as Transactors, i as __INTERNAL__, h as atom, k as atomFamily, c as configure, g as getState, r as registerSelector, n as selector, q as selectorFamily, s as setState, d as subscribe, w as transaction, ƒ as ƒn } from './index-3b5d305c.js';
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
2
  import 'rxjs';
3
3
  import 'hamt_plus';
4
4
  import 'fp-ts/Refinement';