atom.io 0.3.0 → 0.3.1

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
@@ -14,19 +14,17 @@
14
14
  - [x] atom default as function
15
15
  - [x] check whether an atom is "default" (never set)
16
16
  - [x] customizable logging
17
+ - [x] subscribe to transactions
18
+ - [x] timelines
19
+ - [x] subscribe to families
17
20
 
18
21
  # atom.io
19
22
  ## upcoming features
20
- - [ ] subscribe to token creation
21
- - [ ] subscribe to transactions
22
- - [ ] timelines
23
+ - [ ] subscribe to creation of all tokens
23
24
  - [ ] resettable atoms
24
25
  - [ ] resettable selectors
25
26
  - [ ] store observation api
26
27
 
27
- ## fixes & improvements
28
- - [ ] apply and emit transactions all at once
29
-
30
28
  ## documentation
31
29
  - [ ] document atom and selector families
32
30
  - [ ] document atom and selector
package/dist/index.d.ts CHANGED
@@ -138,19 +138,16 @@ declare const markAtomAsDefault: (key: string, store?: Store) => void;
138
138
  declare const markAtomAsNotDefault: (key: string, store?: Store) => void;
139
139
  declare const isSelectorDefault: (key: string, store?: Store) => boolean;
140
140
 
141
- type Logger = Pick<Console, `error` | `info` | `warn`>;
142
- declare const LOG_LEVELS: ReadonlyArray<keyof Logger>;
143
- declare const setLogLevel: (preferredLevel: `error` | `info` | `warn` | null, store?: Store) => void;
144
- declare const useLogger: (logger: Logger, store?: Store) => void;
145
-
146
141
  type OperationProgress = {
147
142
  open: false;
148
143
  } | {
149
144
  open: true;
150
145
  done: Set<string>;
151
146
  prev: Hamt<any, string>;
147
+ time: number;
148
+ token: StateToken<any>;
152
149
  };
153
- declare const openOperation: (store: Store) => void;
150
+ declare const openOperation: (token: StateToken<any>, store: Store) => void;
154
151
  declare const closeOperation: (store: Store) => void;
155
152
  declare const isDone: (key: string, store?: Store) => boolean;
156
153
  declare const markDone: (key: string, store?: Store) => void;
@@ -170,10 +167,11 @@ type Transactors = {
170
167
  set: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void;
171
168
  };
172
169
  type ReadonlyTransactors = Pick<Transactors, `get`>;
173
- type Action<ƒ extends ƒn> = (transactors: Transactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
170
+ type Read<ƒ extends ƒn> = (transactors: ReadonlyTransactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
171
+ type Write<ƒ extends ƒn> = (transactors: Transactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
174
172
  type TransactionOptions<ƒ extends ƒn> = {
175
173
  key: string;
176
- do: Action<ƒ>;
174
+ do: Write<ƒ>;
177
175
  };
178
176
  type Transaction<ƒ extends ƒn> = {
179
177
  key: string;
@@ -231,8 +229,13 @@ type Timeline = {
231
229
  next: () => void;
232
230
  prev: () => void;
233
231
  };
234
- type TimelineStateUpdate = KeyedStateUpdate<unknown> & {
235
- type: `state_update`;
232
+ type TimelineAtomUpdate = KeyedStateUpdate<unknown> & {
233
+ type: `atom_update`;
234
+ };
235
+ type TimelineSelectorUpdate = {
236
+ key: string;
237
+ type: `selector_update`;
238
+ atomUpdates: TimelineAtomUpdate[];
236
239
  };
237
240
  type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
238
241
  type: `transaction_update`;
@@ -240,7 +243,7 @@ type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
240
243
  type TimelineData = {
241
244
  at: number;
242
245
  timeTraveling: boolean;
243
- history: (TimelineStateUpdate | TimelineTransactionUpdate)[];
246
+ history: (TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate)[];
244
247
  };
245
248
  declare function timeline__INTERNAL(options: TimelineOptions, store?: Store): TimelineToken;
246
249
  declare const redo__INTERNAL: (token: TimelineToken, store?: Store) => void;
@@ -276,8 +279,6 @@ declare const target: (store?: Store) => StoreCore;
276
279
  type index_Atom<T> = Atom<T>;
277
280
  declare const index_IMPLICIT: typeof IMPLICIT;
278
281
  type index_KeyedStateUpdate<T> = KeyedStateUpdate<T>;
279
- declare const index_LOG_LEVELS: typeof LOG_LEVELS;
280
- type index_Logger = Logger;
281
282
  type index_OperationProgress = OperationProgress;
282
283
  type index_ReadonlySelector<T> = ReadonlySelector<T>;
283
284
  type index_Selector<T> = Selector<T>;
@@ -285,8 +286,9 @@ type index_Store = Store;
285
286
  type index_StoreCore = StoreCore;
286
287
  declare const index_TRANSACTION_PHASES: typeof TRANSACTION_PHASES;
287
288
  type index_Timeline = Timeline;
289
+ type index_TimelineAtomUpdate = TimelineAtomUpdate;
288
290
  type index_TimelineData = TimelineData;
289
- type index_TimelineStateUpdate = TimelineStateUpdate;
291
+ type index_TimelineSelectorUpdate = TimelineSelectorUpdate;
290
292
  type index_TimelineTransactionUpdate = TimelineTransactionUpdate;
291
293
  type index_TransactionIdle = TransactionIdle;
292
294
  type index_TransactionPhase = TransactionPhase;
@@ -329,7 +331,6 @@ declare const index_registerSelector: typeof registerSelector;
329
331
  declare const index_selectorFamily__INTERNAL: typeof selectorFamily__INTERNAL;
330
332
  declare const index_selector__INTERNAL: typeof selector__INTERNAL;
331
333
  declare const index_setAtomState: typeof setAtomState;
332
- declare const index_setLogLevel: typeof setLogLevel;
333
334
  declare const index_setSelectorState: typeof setSelectorState;
334
335
  declare const index_setState__INTERNAL: typeof setState__INTERNAL;
335
336
  declare const index_storeAtom: typeof storeAtom;
@@ -345,15 +346,12 @@ declare const index_transaction__INTERNAL: typeof transaction__INTERNAL;
345
346
  declare const index_undoTransactionUpdate: typeof undoTransactionUpdate;
346
347
  declare const index_undo__INTERNAL: typeof undo__INTERNAL;
347
348
  declare const index_updateSelectorAtoms: typeof updateSelectorAtoms;
348
- declare const index_useLogger: typeof useLogger;
349
349
  declare const index_withdraw: typeof withdraw;
350
350
  declare namespace index {
351
351
  export {
352
352
  index_Atom as Atom,
353
353
  index_IMPLICIT as IMPLICIT,
354
354
  index_KeyedStateUpdate as KeyedStateUpdate,
355
- index_LOG_LEVELS as LOG_LEVELS,
356
- index_Logger as Logger,
357
355
  index_OperationProgress as OperationProgress,
358
356
  index_ReadonlySelector as ReadonlySelector,
359
357
  index_Selector as Selector,
@@ -361,8 +359,9 @@ declare namespace index {
361
359
  index_StoreCore as StoreCore,
362
360
  index_TRANSACTION_PHASES as TRANSACTION_PHASES,
363
361
  index_Timeline as Timeline,
362
+ index_TimelineAtomUpdate as TimelineAtomUpdate,
364
363
  index_TimelineData as TimelineData,
365
- index_TimelineStateUpdate as TimelineStateUpdate,
364
+ index_TimelineSelectorUpdate as TimelineSelectorUpdate,
366
365
  index_TimelineTransactionUpdate as TimelineTransactionUpdate,
367
366
  index_TransactionIdle as TransactionIdle,
368
367
  index_TransactionPhase as TransactionPhase,
@@ -405,7 +404,6 @@ declare namespace index {
405
404
  index_selectorFamily__INTERNAL as selectorFamily__INTERNAL,
406
405
  index_selector__INTERNAL as selector__INTERNAL,
407
406
  index_setAtomState as setAtomState,
408
- index_setLogLevel as setLogLevel,
409
407
  index_setSelectorState as setSelectorState,
410
408
  index_setState__INTERNAL as setState__INTERNAL,
411
409
  index_storeAtom as storeAtom,
@@ -421,23 +419,27 @@ declare namespace index {
421
419
  index_undoTransactionUpdate as undoTransactionUpdate,
422
420
  index_undo__INTERNAL as undo__INTERNAL,
423
421
  index_updateSelectorAtoms as updateSelectorAtoms,
424
- index_useLogger as useLogger,
425
422
  index_withdraw as withdraw,
426
423
  };
427
424
  }
428
425
 
426
+ type Logger = Pick<Console, `error` | `info` | `warn`>;
427
+ declare const LOG_LEVELS: ReadonlyArray<keyof Logger>;
428
+ declare const setLogLevel: (preferredLevel: `error` | `info` | `warn` | null, store?: Store) => void;
429
+ declare const useLogger: (logger: Logger, store?: Store) => void;
430
+
429
431
  type SelectorOptions<T> = {
430
432
  key: string;
431
- get: (readonlyTransactors: ReadonlyTransactors) => T;
432
- set: (transactors: Transactors, newValue: T) => void;
433
+ get: Read<() => T>;
434
+ set: Write<(newValue: T) => void>;
433
435
  };
434
436
  type ReadonlySelectorOptions<T> = Omit<SelectorOptions<T>, `set`>;
435
437
  declare function selector<T>(options: SelectorOptions<T>): SelectorToken<T>;
436
438
  declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlyValueToken<T>;
437
439
  type SelectorFamilyOptions<T, K extends Serializable> = {
438
440
  key: string;
439
- get: (key: K) => (readonlyTransactors: ReadonlyTransactors) => T;
440
- set: (key: K) => (transactors: Transactors, newValue: T) => void;
441
+ get: (key: K) => Read<() => T>;
442
+ set: (key: K) => Write<(newValue: T) => void>;
441
443
  };
442
444
  type ReadonlySelectorFamilyOptions<T, K extends Serializable> = Omit<SelectorFamilyOptions<T, K>, `set`>;
443
445
  type SelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => SelectorToken<T>) & {
@@ -453,6 +455,15 @@ type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K
453
455
  declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
454
456
  declare function selectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
455
457
 
458
+ type StateUpdate<T> = {
459
+ newValue: T;
460
+ oldValue: T;
461
+ };
462
+ type UpdateHandler<T> = (update: StateUpdate<T>) => void;
463
+ declare const subscribe: <T>(token: ReadonlyValueToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, store?: Store) => (() => void);
464
+ type TransactionUpdateHandler<ƒ extends ƒn> = (data: TransactionUpdate<ƒ>) => void;
465
+ declare const subscribeToTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, store?: Store) => (() => void);
466
+
456
467
  type TimelineToken = {
457
468
  key: string;
458
469
  type: `timeline`;
@@ -465,15 +476,6 @@ declare const timeline: (options: TimelineOptions) => TimelineToken;
465
476
  declare const redo: (token: TimelineToken) => void;
466
477
  declare const undo: (token: TimelineToken) => void;
467
478
 
468
- type StateUpdate<T> = {
469
- newValue: T;
470
- oldValue: T;
471
- };
472
- type UpdateHandler<T> = (update: StateUpdate<T>) => void;
473
- declare const subscribe: <T>(token: ReadonlyValueToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, store?: Store) => (() => void);
474
- type TransactionUpdateHandler<ƒ extends ƒn> = (data: TransactionUpdate<ƒ>) => void;
475
- declare const subscribeToTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, store?: Store) => (() => void);
476
-
477
479
  type AtomToken<_> = {
478
480
  key: string;
479
481
  type: `atom`;
@@ -502,4 +504,4 @@ declare const getState: <T>(token: ReadonlyValueToken<T> | StateToken<T>, store?
502
504
  declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store) => void;
503
505
  declare const isDefault: (token: ReadonlyValueToken<unknown> | StateToken<unknown>, store?: Store) => boolean;
504
506
 
505
- export { Action, AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlyTransactors, ReadonlyValueToken, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Serializable, StateToken, StateUpdate, TimelineOptions, TimelineToken, Transaction, TransactionOptions, TransactionToken, TransactionUpdateHandler, Transactors, UpdateHandler, index as __INTERNAL__, atom, atomFamily, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
507
+ export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, LOG_LEVELS, Logger, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlyTransactors, ReadonlyValueToken, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Serializable, StateToken, StateUpdate, TimelineOptions, TimelineToken, Transaction, TransactionOptions, TransactionToken, TransactionUpdateHandler, Transactors, UpdateHandler, Write, index as __INTERNAL__, atom, atomFamily, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };