atom.io 0.24.2 → 0.24.3
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/dist/index.cjs +0 -9
- package/dist/index.d.ts +5 -6
- package/dist/index.js +1 -8
- package/internal/dist/index.cjs +8 -0
- package/internal/dist/index.d.ts +2 -0
- package/internal/dist/index.js +8 -0
- package/internal/src/get-state/get-from-store.ts +31 -2
- package/package.json +3 -3
- package/src/get-state.ts +6 -2
- package/src/molecule.ts +0 -13
- package/src/transaction.ts +3 -2
package/dist/index.cjs
CHANGED
|
@@ -81,13 +81,6 @@ function moleculeFamily(options) {
|
|
|
81
81
|
function makeMolecule(context, family, key, ...params) {
|
|
82
82
|
return Internal.makeMoleculeInStore(Internal.IMPLICIT.STORE, context, family, key, ...params);
|
|
83
83
|
}
|
|
84
|
-
function useMoleculeFromStore(token, store) {
|
|
85
|
-
const molecule = store.molecules.get(json.stringifyJson(token.key));
|
|
86
|
-
return molecule == null ? void 0 : molecule.instance;
|
|
87
|
-
}
|
|
88
|
-
function useMolecule(token) {
|
|
89
|
-
return useMoleculeFromStore(token, Internal.IMPLICIT.STORE);
|
|
90
|
-
}
|
|
91
84
|
function makeRootMolecule(key, store = Internal.IMPLICIT.STORE) {
|
|
92
85
|
const molecule = new Internal.Molecule(void 0, key);
|
|
93
86
|
store.molecules.set(json.stringifyJson(key), molecule);
|
|
@@ -196,5 +189,3 @@ exports.subscribe = subscribe;
|
|
|
196
189
|
exports.timeline = timeline;
|
|
197
190
|
exports.transaction = transaction;
|
|
198
191
|
exports.undo = undo;
|
|
199
|
-
exports.useMolecule = useMolecule;
|
|
200
|
-
exports.useMoleculeFromStore = useMoleculeFromStore;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transceiver, Subject, Store, EnvironmentData, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
2
2
|
import { Json, JsonInterface } from 'atom.io/json';
|
|
3
|
-
import { MoleculeConstructor as MoleculeConstructor$1, MoleculeToken as MoleculeToken$1, MoleculeFamilyToken as MoleculeFamilyToken$1, MoleculeParams as MoleculeParams$1, makeMolecule as makeMolecule$1, Flat as Flat$1, TransactorsWithRunAndEnv as TransactorsWithRunAndEnv$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, MoleculeCreation as MoleculeCreation$1, MoleculeDisposal as MoleculeDisposal$1 } from 'atom.io';
|
|
3
|
+
import { MoleculeConstructor as MoleculeConstructor$1, MoleculeToken as MoleculeToken$1, MoleculeFamilyToken as MoleculeFamilyToken$1, MoleculeParams as MoleculeParams$1, getState as getState$1, makeMolecule as makeMolecule$1, Flat as Flat$1, TransactorsWithRunAndEnv as TransactorsWithRunAndEnv$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, MoleculeCreation as MoleculeCreation$1, MoleculeDisposal as MoleculeDisposal$1 } from 'atom.io';
|
|
4
4
|
import { findState } from 'atom.io/ephemeral';
|
|
5
5
|
import { seekState } from 'atom.io/immortal';
|
|
6
6
|
import { JoinToken } from 'atom.io/data';
|
|
@@ -110,14 +110,14 @@ type TransactionUpdate<F extends Func> = {
|
|
|
110
110
|
output: ReturnType<F>;
|
|
111
111
|
};
|
|
112
112
|
type Transactors = Readonly<{
|
|
113
|
-
get:
|
|
113
|
+
get: typeof getState$1;
|
|
114
114
|
set: <S, New extends S>(state: WritableToken<S>, newValue: New | ((oldValue: S) => New)) => void;
|
|
115
115
|
find: typeof findState;
|
|
116
116
|
seek: typeof seekState;
|
|
117
117
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
|
|
118
118
|
}>;
|
|
119
119
|
type TransactorsWithRunAndEnv = Readonly<{
|
|
120
|
-
get:
|
|
120
|
+
get: typeof getState$1;
|
|
121
121
|
set: <S, New extends S>(state: WritableToken<S>, newValue: New | ((oldValue: S) => New)) => void;
|
|
122
122
|
find: typeof findState;
|
|
123
123
|
seek: typeof seekState;
|
|
@@ -237,8 +237,6 @@ type MoleculeToken<M extends MoleculeConstructor> = {
|
|
|
237
237
|
};
|
|
238
238
|
declare function moleculeFamily<M extends MoleculeConstructor>(options: MoleculeFamilyOptions<M>): MoleculeFamilyToken<M>;
|
|
239
239
|
declare function makeMolecule<M extends MoleculeConstructor>(context: MoleculeToken<any> | MoleculeToken<any>[], family: MoleculeFamilyToken<M>, key: MoleculeKey<M>, ...params: MoleculeParams<M>): MoleculeToken<M>;
|
|
240
|
-
declare function useMoleculeFromStore<M extends MoleculeConstructor>(token: MoleculeToken<M>, store: Store): InstanceType<M> | undefined;
|
|
241
|
-
declare function useMolecule<M extends MoleculeConstructor>(token: MoleculeToken<M>): InstanceType<M> | undefined;
|
|
242
240
|
type MoleculeType<T extends MoleculeFamilyToken<any>> = T extends MoleculeFamilyToken<infer M> ? M : T extends MoleculeToken<infer M> ? M : never;
|
|
243
241
|
type MoleculeKey<M extends MoleculeConstructor> = InstanceType<M>[`key`];
|
|
244
242
|
type MK<M extends MoleculeConstructor> = MoleculeKey<M>;
|
|
@@ -247,6 +245,7 @@ declare function makeRootMolecule(key: string, store?: Store): MoleculeToken<Obj
|
|
|
247
245
|
declare function disposeState(token: MoleculeToken<any> | ReadableToken<any>): void;
|
|
248
246
|
|
|
249
247
|
declare function getState<T>(token: ReadableToken<T>): T;
|
|
248
|
+
declare function getState<M extends MoleculeConstructor>(token: MoleculeToken<M>): InstanceType<M> | undefined;
|
|
250
249
|
|
|
251
250
|
declare const LoggerIconDictionary: {
|
|
252
251
|
readonly "\u231B": "Timeline event fully captured";
|
|
@@ -427,4 +426,4 @@ type FamilyMetadata = {
|
|
|
427
426
|
subKey: string;
|
|
428
427
|
};
|
|
429
428
|
|
|
430
|
-
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Effectors, type FamilyMetadata, type Flat, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MK, type MoleculeConstructor, type MoleculeCreation, type MoleculeDisposal, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeKey, type MoleculeParams, type MoleculeToken, type MoleculeTransactors, type MoleculeType, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateCreation, type StateDisposal, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo
|
|
429
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Effectors, type FamilyMetadata, type Flat, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MK, type MoleculeConstructor, type MoleculeCreation, type MoleculeDisposal, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeKey, type MoleculeParams, type MoleculeToken, type MoleculeTransactors, type MoleculeType, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateCreation, type StateDisposal, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
package/dist/index.js
CHANGED
|
@@ -60,13 +60,6 @@ function moleculeFamily(options) {
|
|
|
60
60
|
function makeMolecule(context, family, key, ...params) {
|
|
61
61
|
return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params);
|
|
62
62
|
}
|
|
63
|
-
function useMoleculeFromStore(token, store) {
|
|
64
|
-
const molecule = store.molecules.get(stringifyJson(token.key));
|
|
65
|
-
return molecule == null ? void 0 : molecule.instance;
|
|
66
|
-
}
|
|
67
|
-
function useMolecule(token) {
|
|
68
|
-
return useMoleculeFromStore(token, IMPLICIT.STORE);
|
|
69
|
-
}
|
|
70
63
|
function makeRootMolecule(key, store = IMPLICIT.STORE) {
|
|
71
64
|
const molecule = new Molecule(void 0, key);
|
|
72
65
|
store.molecules.set(stringifyJson(key), molecule);
|
|
@@ -152,4 +145,4 @@ function belongsTo(family, unknownToken) {
|
|
|
152
145
|
return family.key === ((_a = unknownToken.family) == null ? void 0 : _a.key);
|
|
153
146
|
}
|
|
154
147
|
|
|
155
|
-
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo
|
|
148
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
package/internal/dist/index.cjs
CHANGED
|
@@ -1062,6 +1062,14 @@ function getEnvironmentData(store) {
|
|
|
1062
1062
|
|
|
1063
1063
|
// internal/src/get-state/get-from-store.ts
|
|
1064
1064
|
function getFromStore(token, store) {
|
|
1065
|
+
if (token.type === `molecule`) {
|
|
1066
|
+
try {
|
|
1067
|
+
const molecule = withdraw(token, store);
|
|
1068
|
+
return molecule.instance;
|
|
1069
|
+
} catch (_) {
|
|
1070
|
+
return void 0;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1065
1073
|
const state = withdraw(token, store);
|
|
1066
1074
|
return readOrComputeValue(state, store);
|
|
1067
1075
|
}
|
package/internal/dist/index.d.ts
CHANGED
|
@@ -432,6 +432,8 @@ type EnvironmentData = {
|
|
|
432
432
|
declare function getEnvironmentData(store: Store): EnvironmentData;
|
|
433
433
|
|
|
434
434
|
declare function getFromStore<T>(token: ReadableToken<T>, store: Store): T;
|
|
435
|
+
declare function getFromStore<M extends MoleculeConstructor>(token: MoleculeToken<M>, store: Store): InstanceType<M> | undefined;
|
|
436
|
+
declare function getFromStore<T, M extends MoleculeConstructor, Token extends MoleculeToken<M> | ReadableToken<T>>(token: Token, store: Store): InstanceType<M> | T | undefined;
|
|
435
437
|
|
|
436
438
|
declare const readOrComputeValue: <T>(state: ReadableState<T>, target: Store) => T;
|
|
437
439
|
|
package/internal/dist/index.js
CHANGED
|
@@ -784,6 +784,14 @@ function getEnvironmentData(store) {
|
|
|
784
784
|
|
|
785
785
|
// internal/src/get-state/get-from-store.ts
|
|
786
786
|
function getFromStore(token, store) {
|
|
787
|
+
if (token.type === `molecule`) {
|
|
788
|
+
try {
|
|
789
|
+
const molecule = withdraw(token, store);
|
|
790
|
+
return molecule.instance;
|
|
791
|
+
} catch (_) {
|
|
792
|
+
return void 0;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
787
795
|
const state = withdraw(token, store);
|
|
788
796
|
return readOrComputeValue(state, store);
|
|
789
797
|
}
|
|
@@ -1,10 +1,39 @@
|
|
|
1
|
-
import type { ReadableToken } from "atom.io"
|
|
1
|
+
import type { MoleculeConstructor, MoleculeToken, ReadableToken } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Store } from "../store"
|
|
4
4
|
import { withdraw } from "../store"
|
|
5
5
|
import { readOrComputeValue } from "./read-or-compute-value"
|
|
6
6
|
|
|
7
|
-
export function getFromStore<T>(token: ReadableToken<T>, store: Store): T
|
|
7
|
+
export function getFromStore<T>(token: ReadableToken<T>, store: Store): T
|
|
8
|
+
export function getFromStore<M extends MoleculeConstructor>(
|
|
9
|
+
token: MoleculeToken<M>,
|
|
10
|
+
store: Store,
|
|
11
|
+
): InstanceType<M> | undefined
|
|
12
|
+
export function getFromStore<
|
|
13
|
+
T,
|
|
14
|
+
M extends MoleculeConstructor,
|
|
15
|
+
Token extends MoleculeToken<M> | ReadableToken<T>,
|
|
16
|
+
>(token: Token, store: Store): InstanceType<M> | T | undefined
|
|
17
|
+
export function getFromStore<
|
|
18
|
+
Token extends MoleculeToken<any> | ReadableToken<any>,
|
|
19
|
+
>(
|
|
20
|
+
token: Token,
|
|
21
|
+
store: Store,
|
|
22
|
+
):
|
|
23
|
+
| (Token extends MoleculeToken<infer M>
|
|
24
|
+
? InstanceType<M>
|
|
25
|
+
: Token extends ReadableToken<infer T>
|
|
26
|
+
? T
|
|
27
|
+
: never)
|
|
28
|
+
| undefined {
|
|
29
|
+
if (token.type === `molecule`) {
|
|
30
|
+
try {
|
|
31
|
+
const molecule = withdraw(token, store)
|
|
32
|
+
return molecule.instance
|
|
33
|
+
} catch (_) {
|
|
34
|
+
return undefined
|
|
35
|
+
}
|
|
36
|
+
}
|
|
8
37
|
const state = withdraw(token, store)
|
|
9
38
|
return readOrComputeValue(state, store)
|
|
10
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "atom.io",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.3",
|
|
4
4
|
"description": "Composable and testable reactive data library.",
|
|
5
5
|
"homepage": "https://atom.io.fyi",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"drizzle-orm": "0.30.10",
|
|
66
66
|
"eslint": "npm:eslint@8.57.0",
|
|
67
67
|
"eslint-v9": "npm:eslint@9.3.0",
|
|
68
|
-
"framer-motion": "11.2.
|
|
69
|
-
"happy-dom": "14.11.
|
|
68
|
+
"framer-motion": "11.2.9",
|
|
69
|
+
"happy-dom": "14.11.4",
|
|
70
70
|
"http-proxy": "1.18.1",
|
|
71
71
|
"npmlog": "7.0.1",
|
|
72
72
|
"postgres": "3.4.4",
|
package/src/get-state.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import * as Internal from "atom.io/internal"
|
|
2
2
|
|
|
3
|
-
import type { ReadableToken } from "."
|
|
3
|
+
import type { MoleculeConstructor, MoleculeToken, ReadableToken } from "."
|
|
4
4
|
|
|
5
|
-
export function getState<T>(token: ReadableToken<T>): T
|
|
5
|
+
export function getState<T>(token: ReadableToken<T>): T
|
|
6
|
+
export function getState<M extends MoleculeConstructor>(
|
|
7
|
+
token: MoleculeToken<M>,
|
|
8
|
+
): InstanceType<M> | undefined
|
|
9
|
+
export function getState(token: MoleculeToken<any> | ReadableToken<any>): any {
|
|
6
10
|
return Internal.getFromStore(token, Internal.IMPLICIT.STORE)
|
|
7
11
|
}
|
package/src/molecule.ts
CHANGED
|
@@ -100,19 +100,6 @@ export function makeMolecule<M extends MoleculeConstructor>(
|
|
|
100
100
|
return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
export function useMoleculeFromStore<M extends MoleculeConstructor>(
|
|
104
|
-
token: MoleculeToken<M>,
|
|
105
|
-
store: Store,
|
|
106
|
-
): InstanceType<M> | undefined {
|
|
107
|
-
const molecule = store.molecules.get(stringifyJson(token.key))
|
|
108
|
-
return molecule?.instance
|
|
109
|
-
}
|
|
110
|
-
export function useMolecule<M extends MoleculeConstructor>(
|
|
111
|
-
token: MoleculeToken<M>,
|
|
112
|
-
): InstanceType<M> | undefined {
|
|
113
|
-
return useMoleculeFromStore(token, IMPLICIT.STORE)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
103
|
export type MoleculeType<T extends MoleculeFamilyToken<any>> =
|
|
117
104
|
T extends MoleculeFamilyToken<infer M>
|
|
118
105
|
? M
|
package/src/transaction.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
getState,
|
|
2
3
|
makeMolecule,
|
|
3
4
|
MoleculeConstructor,
|
|
4
5
|
MoleculeFamilyToken,
|
|
@@ -78,7 +79,7 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
export type Transactors = Readonly<{
|
|
81
|
-
get:
|
|
82
|
+
get: typeof getState
|
|
82
83
|
set: <S, New extends S>(
|
|
83
84
|
state: WritableToken<S>,
|
|
84
85
|
newValue: New | ((oldValue: S) => New),
|
|
@@ -90,7 +91,7 @@ export type Transactors = Readonly<{
|
|
|
90
91
|
) => WritableSelectorToken<J>
|
|
91
92
|
}>
|
|
92
93
|
export type TransactorsWithRunAndEnv = Readonly<{
|
|
93
|
-
get:
|
|
94
|
+
get: typeof getState
|
|
94
95
|
set: <S, New extends S>(
|
|
95
96
|
state: WritableToken<S>,
|
|
96
97
|
newValue: New | ((oldValue: S) => New),
|