atom.io 0.2.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 +8 -15
- package/dist/index.d.ts +507 -4
- package/dist/index.js +924 -368
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +913 -364
- package/dist/index.mjs.map +1 -1
- package/package.json +24 -6
- package/{dist/react → react/dist}/index.d.ts +2 -5
- package/react/dist/index.js +68 -0
- package/react/dist/index.js.map +1 -0
- package/react/dist/index.mjs +44 -0
- package/react/dist/index.mjs.map +1 -0
- package/react/package.json +12 -3
- package/src/atom.ts +18 -53
- package/src/index.ts +29 -37
- package/src/internal/atom-internal.ts +50 -0
- package/src/internal/families-internal.ts +142 -0
- package/src/internal/get.ts +41 -43
- package/src/internal/index.ts +5 -17
- package/src/internal/is-default.ts +20 -4
- package/src/internal/operation.ts +111 -16
- package/src/internal/selector-internal.ts +116 -15
- package/src/internal/set.ts +31 -17
- package/src/internal/store.ts +57 -45
- package/src/internal/subscribe-internal.ts +55 -11
- package/src/internal/timeline-internal.ts +293 -0
- package/src/internal/transaction-internal.ts +157 -16
- package/src/logger.ts +46 -0
- package/src/react/index.ts +5 -6
- package/src/selector.ts +34 -104
- package/src/subscribe.ts +55 -0
- package/src/timeline.ts +29 -0
- package/src/transaction.ts +29 -36
- package/dist/index-9d9f5a05.d.ts +0 -293
- package/dist/react/index.js +0 -909
- package/dist/react/index.js.map +0 -1
- package/dist/react/index.mjs +0 -880
- package/dist/react/index.mjs.map +0 -1
package/src/selector.ts
CHANGED
|
@@ -1,132 +1,62 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as Rx from "rxjs"
|
|
1
|
+
import type * as Rx from "rxjs"
|
|
3
2
|
|
|
4
|
-
import { become } from "~/packages/anvl/src/function"
|
|
5
3
|
import type { Serializable } from "~/packages/anvl/src/json"
|
|
6
|
-
import { stringifyJson } from "~/packages/anvl/src/json"
|
|
7
4
|
|
|
8
5
|
import type { ReadonlyValueToken, SelectorToken } from "."
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import type { ReadonlyTransactors, Transactors } from "./transaction"
|
|
6
|
+
import { selectorFamily__INTERNAL, selector__INTERNAL } from "./internal"
|
|
7
|
+
import type { Read, Write } from "./transaction"
|
|
12
8
|
|
|
13
9
|
export type SelectorOptions<T> = {
|
|
14
10
|
key: string
|
|
15
|
-
get: (
|
|
16
|
-
set: (
|
|
11
|
+
get: Read<() => T>
|
|
12
|
+
set: Write<(newValue: T) => void>
|
|
17
13
|
}
|
|
18
14
|
export type ReadonlySelectorOptions<T> = Omit<SelectorOptions<T>, `set`>
|
|
19
15
|
|
|
16
|
+
export function selector<T>(options: SelectorOptions<T>): SelectorToken<T>
|
|
20
17
|
export function selector<T>(
|
|
21
|
-
options:
|
|
22
|
-
store?: Store
|
|
23
|
-
): SelectorToken<T>
|
|
24
|
-
export function selector<T>(
|
|
25
|
-
options: ReadonlySelectorOptions<T>,
|
|
26
|
-
store?: Store
|
|
18
|
+
options: ReadonlySelectorOptions<T>
|
|
27
19
|
): ReadonlyValueToken<T>
|
|
28
20
|
export function selector<T>(
|
|
29
|
-
options: ReadonlySelectorOptions<T> | SelectorOptions<T
|
|
30
|
-
store: Store = IMPLICIT.STORE
|
|
21
|
+
options: ReadonlySelectorOptions<T> | SelectorOptions<T>
|
|
31
22
|
): ReadonlyValueToken<T> | SelectorToken<T> {
|
|
32
|
-
|
|
33
|
-
throw new Error(`Key "${options.key}" already exists in the store.`)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const subject = new Rx.Subject<{ newValue: T; oldValue: T }>()
|
|
37
|
-
|
|
38
|
-
const { get, set } = registerSelector(options.key, store)
|
|
39
|
-
const getSelf = () => {
|
|
40
|
-
const value = options.get({ get })
|
|
41
|
-
store.valueMap = HAMT.set(options.key, value, store.valueMap)
|
|
42
|
-
return value
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!(`set` in options)) {
|
|
46
|
-
const readonlySelector = {
|
|
47
|
-
...options,
|
|
48
|
-
subject,
|
|
49
|
-
get: getSelf,
|
|
50
|
-
}
|
|
51
|
-
store.readonlySelectors = HAMT.set(
|
|
52
|
-
options.key,
|
|
53
|
-
readonlySelector,
|
|
54
|
-
store.readonlySelectors
|
|
55
|
-
)
|
|
56
|
-
const initialValue = getSelf()
|
|
57
|
-
store.config.logger?.info(` ✨ "${options.key}" =`, initialValue)
|
|
58
|
-
return { ...readonlySelector, type: `readonly_selector` }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const setSelf = (next: T | ((oldValue: T) => T)): void => {
|
|
62
|
-
store.config.logger?.info(` <- "${options.key}" became`, next)
|
|
63
|
-
const oldValue = getSelf()
|
|
64
|
-
const newValue = become(next)(oldValue)
|
|
65
|
-
store.valueMap = HAMT.set(options.key, newValue, store.valueMap)
|
|
66
|
-
markDone(options.key, store)
|
|
67
|
-
subject.next({ newValue, oldValue })
|
|
68
|
-
options.set({ get, set }, newValue)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const mySelector: Selector<T> = {
|
|
72
|
-
...options,
|
|
73
|
-
subject,
|
|
74
|
-
get: getSelf,
|
|
75
|
-
set: setSelf,
|
|
76
|
-
}
|
|
77
|
-
store.selectors = HAMT.set(options.key, mySelector, store.selectors)
|
|
78
|
-
const initialValue = getSelf()
|
|
79
|
-
store.config.logger?.info(` ✨ "${options.key}" =`, initialValue)
|
|
80
|
-
return { ...mySelector, type: `selector` }
|
|
23
|
+
return selector__INTERNAL(options)
|
|
81
24
|
}
|
|
82
25
|
|
|
83
26
|
export type SelectorFamilyOptions<T, K extends Serializable> = {
|
|
84
27
|
key: string
|
|
85
|
-
get: (key: K) => (
|
|
86
|
-
set: (key: K) => (
|
|
28
|
+
get: (key: K) => Read<() => T>
|
|
29
|
+
set: (key: K) => Write<(newValue: T) => void>
|
|
87
30
|
}
|
|
88
31
|
export type ReadonlySelectorFamilyOptions<T, K extends Serializable> = Omit<
|
|
89
32
|
SelectorFamilyOptions<T, K>,
|
|
90
33
|
`set`
|
|
91
34
|
>
|
|
92
35
|
|
|
36
|
+
export type SelectorFamily<T, K extends Serializable = Serializable> = ((
|
|
37
|
+
key: K
|
|
38
|
+
) => SelectorToken<T>) & {
|
|
39
|
+
key: string
|
|
40
|
+
type: `selector_family`
|
|
41
|
+
subject: Rx.Subject<SelectorToken<T>>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((
|
|
45
|
+
key: K
|
|
46
|
+
) => ReadonlyValueToken<T>) & {
|
|
47
|
+
key: string
|
|
48
|
+
type: `readonly_selector_family`
|
|
49
|
+
subject: Rx.Subject<ReadonlyValueToken<T>>
|
|
50
|
+
}
|
|
51
|
+
|
|
93
52
|
export function selectorFamily<T, K extends Serializable>(
|
|
94
|
-
options: SelectorFamilyOptions<T, K
|
|
95
|
-
|
|
96
|
-
): (key: K) => SelectorToken<T>
|
|
53
|
+
options: SelectorFamilyOptions<T, K>
|
|
54
|
+
): SelectorFamily<T, K>
|
|
97
55
|
export function selectorFamily<T, K extends Serializable>(
|
|
98
|
-
options: ReadonlySelectorFamilyOptions<T, K
|
|
99
|
-
|
|
100
|
-
): (key: K) => ReadonlyValueToken<T>
|
|
56
|
+
options: ReadonlySelectorFamilyOptions<T, K>
|
|
57
|
+
): ReadonlySelectorFamily<T, K>
|
|
101
58
|
export function selectorFamily<T, K extends Serializable>(
|
|
102
|
-
options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return (key: K): ReadonlyValueToken<T> | SelectorToken<T> => {
|
|
106
|
-
const fullKey = `${options.key}__${stringifyJson(key)}`
|
|
107
|
-
const existing =
|
|
108
|
-
store.selectors.get(fullKey) ?? store.readonlySelectors.get(fullKey)
|
|
109
|
-
if (existing) {
|
|
110
|
-
return deposit(existing)
|
|
111
|
-
}
|
|
112
|
-
const readonlySelectorOptions: ReadonlySelectorOptions<T> = {
|
|
113
|
-
key: fullKey,
|
|
114
|
-
get: options.get(key),
|
|
115
|
-
}
|
|
116
|
-
if (!(`set` in options)) {
|
|
117
|
-
return selector<T>(
|
|
118
|
-
{
|
|
119
|
-
...readonlySelectorOptions,
|
|
120
|
-
},
|
|
121
|
-
store
|
|
122
|
-
)
|
|
123
|
-
}
|
|
124
|
-
return selector<T>(
|
|
125
|
-
{
|
|
126
|
-
...readonlySelectorOptions,
|
|
127
|
-
set: options.set(key),
|
|
128
|
-
},
|
|
129
|
-
store
|
|
130
|
-
)
|
|
131
|
-
}
|
|
59
|
+
options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>
|
|
60
|
+
): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {
|
|
61
|
+
return selectorFamily__INTERNAL(options)
|
|
132
62
|
}
|
package/src/subscribe.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ReadonlyValueToken, StateToken, TransactionToken, ƒn } from "."
|
|
2
|
+
import type { Store, TransactionUpdate } from "./internal"
|
|
3
|
+
import { IMPLICIT, subscribeToRootAtoms, withdraw } from "./internal"
|
|
4
|
+
|
|
5
|
+
export type StateUpdate<T> = { newValue: T; oldValue: T }
|
|
6
|
+
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
7
|
+
|
|
8
|
+
export const subscribe = <T>(
|
|
9
|
+
token: ReadonlyValueToken<T> | StateToken<T>,
|
|
10
|
+
handleUpdate: UpdateHandler<T>,
|
|
11
|
+
store: Store = IMPLICIT.STORE
|
|
12
|
+
): (() => void) => {
|
|
13
|
+
const state = withdraw<T>(token, store)
|
|
14
|
+
const subscription = state.subject.subscribe(handleUpdate)
|
|
15
|
+
store.config.logger?.info(`👀 subscribe to "${state.key}"`)
|
|
16
|
+
const dependencySubscriptions =
|
|
17
|
+
state.type !== `atom` ? subscribeToRootAtoms(state, store) : null
|
|
18
|
+
|
|
19
|
+
const unsubscribe =
|
|
20
|
+
dependencySubscriptions === null
|
|
21
|
+
? () => {
|
|
22
|
+
store.config.logger?.info(`🙈 unsubscribe from "${state.key}"`)
|
|
23
|
+
subscription.unsubscribe()
|
|
24
|
+
}
|
|
25
|
+
: () => {
|
|
26
|
+
store.config.logger?.info(
|
|
27
|
+
`🙈 unsubscribe from "${state.key}" and its dependencies`
|
|
28
|
+
)
|
|
29
|
+
subscription.unsubscribe()
|
|
30
|
+
for (const dependencySubscription of dependencySubscriptions) {
|
|
31
|
+
dependencySubscription.unsubscribe()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return unsubscribe
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type TransactionUpdateHandler<ƒ extends ƒn> = (
|
|
39
|
+
data: TransactionUpdate<ƒ>
|
|
40
|
+
) => void
|
|
41
|
+
|
|
42
|
+
export const subscribeToTransaction = <ƒ extends ƒn>(
|
|
43
|
+
token: TransactionToken<ƒ>,
|
|
44
|
+
handleUpdate: TransactionUpdateHandler<ƒ>,
|
|
45
|
+
store = IMPLICIT.STORE
|
|
46
|
+
): (() => void) => {
|
|
47
|
+
const tx = withdraw(token, store)
|
|
48
|
+
store.config.logger?.info(`👀 subscribe to transaction "${token.key}"`)
|
|
49
|
+
const subscription = tx.subject.subscribe(handleUpdate)
|
|
50
|
+
const unsubscribe = () => {
|
|
51
|
+
store.config.logger?.info(`🙈 unsubscribe from transaction "${token.key}"`)
|
|
52
|
+
subscription.unsubscribe()
|
|
53
|
+
}
|
|
54
|
+
return unsubscribe
|
|
55
|
+
}
|
package/src/timeline.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AtomFamily, AtomToken } from "."
|
|
2
|
+
import { IMPLICIT } from "./internal"
|
|
3
|
+
import {
|
|
4
|
+
redo__INTERNAL,
|
|
5
|
+
timeline__INTERNAL,
|
|
6
|
+
undo__INTERNAL,
|
|
7
|
+
} from "./internal/timeline-internal"
|
|
8
|
+
|
|
9
|
+
export type TimelineToken = {
|
|
10
|
+
key: string
|
|
11
|
+
type: `timeline`
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type TimelineOptions = {
|
|
15
|
+
key: string
|
|
16
|
+
atoms: (AtomFamily<any> | AtomToken<any>)[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const timeline = (options: TimelineOptions): TimelineToken => {
|
|
20
|
+
return timeline__INTERNAL(options)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const redo = (token: TimelineToken): void => {
|
|
24
|
+
return redo__INTERNAL(token, IMPLICIT.STORE)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const undo = (token: TimelineToken): void => {
|
|
28
|
+
return undo__INTERNAL(token, IMPLICIT.STORE)
|
|
29
|
+
}
|
package/src/transaction.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
abortTransaction,
|
|
7
|
-
finishTransaction,
|
|
8
|
-
startTransaction,
|
|
9
|
-
} from "./internal/transaction-internal"
|
|
1
|
+
import type * as Rx from "rxjs"
|
|
2
|
+
|
|
3
|
+
import type { ReadonlyValueToken, StateToken, TransactionToken } from "."
|
|
4
|
+
import type { Store, TransactionUpdate } from "./internal"
|
|
5
|
+
import { IMPLICIT, transaction__INTERNAL, withdraw } from "./internal"
|
|
10
6
|
|
|
11
7
|
export type ƒn = (...parameters: any[]) => any
|
|
12
8
|
|
|
@@ -16,38 +12,35 @@ export type Transactors = {
|
|
|
16
12
|
}
|
|
17
13
|
export type ReadonlyTransactors = Pick<Transactors, `get`>
|
|
18
14
|
|
|
19
|
-
export type
|
|
15
|
+
export type Read<ƒ extends ƒn> = (
|
|
16
|
+
transactors: ReadonlyTransactors,
|
|
17
|
+
...parameters: Parameters<ƒ>
|
|
18
|
+
) => ReturnType<ƒ>
|
|
19
|
+
|
|
20
|
+
export type Write<ƒ extends ƒn> = (
|
|
20
21
|
transactors: Transactors,
|
|
21
22
|
...parameters: Parameters<ƒ>
|
|
22
23
|
) => ReturnType<ƒ>
|
|
23
24
|
|
|
24
25
|
export type TransactionOptions<ƒ extends ƒn> = {
|
|
25
26
|
key: string
|
|
26
|
-
do:
|
|
27
|
+
do: Write<ƒ>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type Transaction<ƒ extends ƒn> = {
|
|
31
|
+
key: string
|
|
32
|
+
type: `transaction`
|
|
33
|
+
run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>
|
|
34
|
+
subject: Rx.Subject<TransactionUpdate<ƒ>>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function transaction<ƒ extends ƒn>(
|
|
38
|
+
options: TransactionOptions<ƒ>
|
|
39
|
+
): TransactionToken<ƒ> {
|
|
40
|
+
return transaction__INTERNAL(options)
|
|
27
41
|
}
|
|
28
42
|
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
Object.assign(
|
|
34
|
-
(...parameters: Parameters<ƒ>) => {
|
|
35
|
-
startTransaction(store)
|
|
36
|
-
try {
|
|
37
|
-
const result = options.do(
|
|
38
|
-
{
|
|
39
|
-
get: (token) => getState(token, store),
|
|
40
|
-
set: (token, value) => setState(token, value, store),
|
|
41
|
-
},
|
|
42
|
-
...parameters
|
|
43
|
-
)
|
|
44
|
-
finishTransaction(store)
|
|
45
|
-
return result
|
|
46
|
-
} catch (thrown) {
|
|
47
|
-
abortTransaction(store)
|
|
48
|
-
store.config.logger?.error(`Transaction ${options.key} failed`, thrown)
|
|
49
|
-
throw thrown
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
{ key: options.key }
|
|
53
|
-
)
|
|
43
|
+
export const runTransaction =
|
|
44
|
+
<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>
|
|
45
|
+
(...parameters: Parameters<ƒ>): ReturnType<ƒ> =>
|
|
46
|
+
withdraw(token, store).run(...parameters)
|
package/dist/index-9d9f5a05.d.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
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 ƒ };
|