atom.io 0.6.7 → 0.6.9
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.d.mts +241 -263
- package/dist/index.d.ts +241 -263
- package/dist/index.js +28 -1911
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1871
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +121 -176
- package/introspection/dist/index.d.ts +121 -176
- package/introspection/dist/index.js +6 -346
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +5 -324
- package/introspection/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +37 -8
- package/json/dist/index.d.ts +37 -8
- package/json/dist/index.js +31 -48
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +6 -14
- package/json/dist/index.mjs.map +1 -1
- package/package.json +30 -14
- package/react/dist/index.js +34 -83
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +7 -43
- package/react/dist/index.mjs.map +1 -1
- package/react-devtools/dist/index.css +1 -42
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +128 -193
- package/react-devtools/dist/index.d.ts +128 -193
- package/react-devtools/dist/index.js +56 -4154
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +19 -4117
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime/dist/index.d.mts +7 -11
- package/realtime/dist/index.d.ts +7 -11
- package/realtime/dist/index.js +26 -185
- package/realtime/dist/index.js.map +1 -1
- package/realtime/dist/index.mjs +4 -149
- package/realtime/dist/index.mjs.map +1 -1
- package/realtime-react/dist/index.d.mts +12 -16
- package/realtime-react/dist/index.d.ts +12 -16
- package/realtime-react/dist/index.js +41 -214
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +9 -169
- package/realtime-react/dist/index.mjs.map +1 -1
- package/src/atom.ts +7 -6
- package/src/index.ts +12 -9
- package/src/logger.ts +5 -5
- package/src/selector.ts +16 -14
- package/src/silo.ts +36 -39
- package/src/subscribe.ts +25 -20
- package/src/timeline.ts +9 -4
- package/src/transaction.ts +3 -4
- package/src/internal/atom-internal.ts +0 -54
- package/src/internal/families-internal.ts +0 -141
- package/src/internal/get.ts +0 -129
- package/src/internal/index.ts +0 -15
- package/src/internal/is-default.ts +0 -35
- package/src/internal/operation.ts +0 -139
- package/src/internal/selector/create-read-write-selector.ts +0 -66
- package/src/internal/selector/create-readonly-selector.ts +0 -46
- package/src/internal/selector/index.ts +0 -4
- package/src/internal/selector/lookup-selector-sources.ts +0 -16
- package/src/internal/selector/register-selector.ts +0 -57
- package/src/internal/selector/trace-selector-atoms.ts +0 -43
- package/src/internal/selector/update-selector-atoms.ts +0 -33
- package/src/internal/selector-internal.ts +0 -58
- package/src/internal/set.ts +0 -99
- package/src/internal/store.ts +0 -151
- package/src/internal/subject.ts +0 -24
- package/src/internal/subscribe-internal.ts +0 -88
- package/src/internal/time-travel-internal.ts +0 -91
- package/src/internal/timeline/add-atom-to-timeline.ts +0 -168
- package/src/internal/timeline/index.ts +0 -1
- package/src/internal/timeline-internal.ts +0 -107
- package/src/internal/transaction/abort-transaction.ts +0 -12
- package/src/internal/transaction/apply-transaction.ts +0 -57
- package/src/internal/transaction/build-transaction.ts +0 -33
- package/src/internal/transaction/index.ts +0 -25
- package/src/internal/transaction/redo-transaction.ts +0 -23
- package/src/internal/transaction/undo-transaction.ts +0 -23
- package/src/internal/transaction-internal.ts +0 -61
- package/src/introspection/attach-atom-index.ts +0 -73
- package/src/introspection/attach-introspection-states.ts +0 -42
- package/src/introspection/attach-selector-index.ts +0 -77
- package/src/introspection/attach-timeline-family.ts +0 -59
- package/src/introspection/attach-timeline-index.ts +0 -36
- package/src/introspection/attach-transaction-index.ts +0 -38
- package/src/introspection/attach-transaction-logs.ts +0 -40
- package/src/introspection/index.ts +0 -20
- package/src/json/index.ts +0 -1
- package/src/json/select-json.ts +0 -18
- package/src/react/index.ts +0 -2
- package/src/react/store-context.tsx +0 -13
- package/src/react/store-hooks.ts +0 -47
- package/src/react-devtools/AtomIODevtools.tsx +0 -107
- package/src/react-devtools/Button.tsx +0 -24
- package/src/react-devtools/StateEditor.tsx +0 -70
- package/src/react-devtools/StateIndex.tsx +0 -153
- package/src/react-devtools/TimelineIndex.tsx +0 -92
- package/src/react-devtools/TransactionIndex.tsx +0 -70
- package/src/react-devtools/Updates.tsx +0 -145
- package/src/react-devtools/devtools.scss +0 -311
- package/src/react-devtools/index.ts +0 -72
- package/src/react-explorer/AtomIOExplorer.tsx +0 -218
- package/src/react-explorer/explorer-effects.ts +0 -20
- package/src/react-explorer/explorer-states.ts +0 -217
- package/src/react-explorer/index.ts +0 -23
- package/src/react-explorer/space-states.ts +0 -72
- package/src/react-explorer/view-states.ts +0 -41
- package/src/realtime/README.md +0 -33
- package/src/realtime/hook-composition/expose-family.ts +0 -101
- package/src/realtime/hook-composition/expose-single.ts +0 -38
- package/src/realtime/hook-composition/expose-timeline.ts +0 -60
- package/src/realtime/hook-composition/index.ts +0 -12
- package/src/realtime/hook-composition/receive-state.ts +0 -29
- package/src/realtime/hook-composition/receive-transaction.ts +0 -18
- package/src/realtime/index.ts +0 -1
- package/src/realtime-react/index.ts +0 -3
- package/src/realtime-react/realtime-context.tsx +0 -30
- package/src/realtime-react/realtime-hooks.ts +0 -39
- package/src/realtime-react/realtime-state.ts +0 -10
- package/src/realtime-react/use-pull-family-member.ts +0 -26
- package/src/realtime-react/use-pull-family.ts +0 -24
- package/src/realtime-react/use-pull.ts +0 -22
- package/src/realtime-react/use-push.ts +0 -25
- package/src/realtime-react/use-server-action.ts +0 -33
- package/src/realtime-testing/index.ts +0 -1
- package/src/realtime-testing/setup-realtime-test.tsx +0 -159
- package/src/web-effects/index.ts +0 -1
- package/src/web-effects/storage.ts +0 -30
package/src/index.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { capitalize } from "~/packages/anvl/src/string/capitalize"
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
IMPLICIT,
|
|
5
3
|
closeOperation,
|
|
6
|
-
openOperation,
|
|
7
4
|
getState__INTERNAL,
|
|
8
|
-
setState__INTERNAL,
|
|
9
5
|
isAtomDefault,
|
|
10
6
|
isSelectorDefault,
|
|
7
|
+
openOperation,
|
|
8
|
+
setState__INTERNAL,
|
|
11
9
|
withdraw,
|
|
12
|
-
} from "
|
|
13
|
-
import * as __INTERNAL__ from "
|
|
14
|
-
import type { Store } from "
|
|
10
|
+
} from "atom.io/internal"
|
|
11
|
+
import * as __INTERNAL__ from "atom.io/internal"
|
|
12
|
+
import type { Store } from "atom.io/internal"
|
|
13
|
+
|
|
14
|
+
import type { ƒn } from "~/packages/anvl/src/function"
|
|
15
|
+
import { capitalize } from "~/packages/anvl/src/string/capitalize"
|
|
16
|
+
|
|
17
|
+
export { ƒn }
|
|
15
18
|
|
|
16
19
|
export * from "./atom"
|
|
17
20
|
export * from "./logger"
|
|
@@ -21,8 +24,8 @@ export * from "./subscribe"
|
|
|
21
24
|
export * from "./timeline"
|
|
22
25
|
export * from "./transaction"
|
|
23
26
|
export { __INTERNAL__ }
|
|
24
|
-
export type { Store } from "
|
|
25
|
-
export type {
|
|
27
|
+
export type { Store } from "atom.io/internal"
|
|
28
|
+
export type { Json } from "atom.io/json"
|
|
26
29
|
|
|
27
30
|
export type AtomToken<_> = {
|
|
28
31
|
key: string
|
package/src/logger.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMPLICIT } from "atom.io/internal"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
2
3
|
|
|
3
|
-
import
|
|
4
|
-
import { IMPLICIT } from "./internal/store"
|
|
4
|
+
import { doNothing } from "~/packages/anvl/src/function"
|
|
5
5
|
|
|
6
6
|
export type Logger = Pick<Console, `error` | `info` | `warn`>
|
|
7
7
|
export const LOG_LEVELS: ReadonlyArray<keyof Logger> = [
|
|
@@ -21,10 +21,10 @@ export const setLogLevel = (
|
|
|
21
21
|
store.config.logger = { ...console }
|
|
22
22
|
LOG_LEVELS.forEach((logLevel) => {
|
|
23
23
|
if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
|
|
24
|
-
//
|
|
24
|
+
// biome-ignore lint/style/noNonNullAssertion: we just set it
|
|
25
25
|
store.config.logger![logLevel] = doNothing
|
|
26
26
|
} else {
|
|
27
|
-
//
|
|
27
|
+
// biome-ignore lint/style/noNonNullAssertion: we just set it
|
|
28
28
|
store.config.logger![logLevel] = logger__INTERNAL[logLevel]
|
|
29
29
|
}
|
|
30
30
|
})
|
package/src/selector.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Subject } from "atom.io/internal"
|
|
2
|
+
import { selectorFamily__INTERNAL, selector__INTERNAL } from "atom.io/internal"
|
|
3
|
+
import type { Json } from "atom.io/json"
|
|
2
4
|
|
|
3
5
|
import type { ReadonlySelectorToken, SelectorToken } from "."
|
|
4
|
-
import type { Subject } from "./internal"
|
|
5
|
-
import { selectorFamily__INTERNAL, selector__INTERNAL } from "./internal"
|
|
6
6
|
import type { Read, Write } from "./transaction"
|
|
7
7
|
|
|
8
8
|
export type SelectorOptions<T> = {
|
|
@@ -25,39 +25,41 @@ export function selector<T>(
|
|
|
25
25
|
return selector__INTERNAL(options)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export type SelectorFamilyOptions<T, K extends Serializable> = {
|
|
28
|
+
export type SelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
29
29
|
key: string
|
|
30
30
|
get: (key: K) => Read<() => T>
|
|
31
31
|
set: (key: K) => Write<(newValue: T) => void>
|
|
32
32
|
}
|
|
33
|
-
export type ReadonlySelectorFamilyOptions<T, K extends Serializable> = {
|
|
33
|
+
export type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {
|
|
34
34
|
key: string
|
|
35
35
|
get: (key: K) => Read<() => T>
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export type SelectorFamily<
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
export type SelectorFamily<
|
|
39
|
+
T,
|
|
40
|
+
K extends Json.Serializable = Json.Serializable,
|
|
41
|
+
> = ((key: K) => SelectorToken<T>) & {
|
|
41
42
|
key: string
|
|
42
43
|
type: `selector_family`
|
|
43
44
|
subject: Subject<SelectorToken<T>>
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export type ReadonlySelectorFamily<
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
export type ReadonlySelectorFamily<
|
|
48
|
+
T,
|
|
49
|
+
K extends Json.Serializable = Json.Serializable,
|
|
50
|
+
> = ((key: K) => ReadonlySelectorToken<T>) & {
|
|
49
51
|
key: string
|
|
50
52
|
type: `readonly_selector_family`
|
|
51
53
|
subject: Subject<ReadonlySelectorToken<T>>
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
export function selectorFamily<T, K extends Serializable>(
|
|
56
|
+
export function selectorFamily<T, K extends Json.Serializable>(
|
|
55
57
|
options: SelectorFamilyOptions<T, K>,
|
|
56
58
|
): SelectorFamily<T, K>
|
|
57
|
-
export function selectorFamily<T, K extends Serializable>(
|
|
59
|
+
export function selectorFamily<T, K extends Json.Serializable>(
|
|
58
60
|
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
59
61
|
): ReadonlySelectorFamily<T, K>
|
|
60
|
-
export function selectorFamily<T, K extends Serializable>(
|
|
62
|
+
export function selectorFamily<T, K extends Json.Serializable>(
|
|
61
63
|
options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,
|
|
62
64
|
): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {
|
|
63
65
|
return selectorFamily__INTERNAL(options)
|
package/src/silo.ts
CHANGED
|
@@ -1,53 +1,50 @@
|
|
|
1
|
-
import type { redo, timeline, undo } from "."
|
|
2
|
-
import { getState, setState, subscribe } from "."
|
|
3
|
-
import type { atom, atomFamily } from "./atom"
|
|
4
|
-
import type { Store } from "./internal"
|
|
5
1
|
import {
|
|
2
|
+
Store,
|
|
6
3
|
atomFamily__INTERNAL,
|
|
7
4
|
atom__INTERNAL,
|
|
8
|
-
createStore,
|
|
9
5
|
redo__INTERNAL,
|
|
10
6
|
selectorFamily__INTERNAL,
|
|
11
7
|
selector__INTERNAL,
|
|
12
8
|
timeline__INTERNAL,
|
|
13
9
|
transaction__INTERNAL,
|
|
14
10
|
undo__INTERNAL,
|
|
15
|
-
} from "
|
|
11
|
+
} from "atom.io/internal"
|
|
12
|
+
|
|
13
|
+
import type { redo, timeline, undo } from "."
|
|
14
|
+
import { getState, setState, subscribe } from "."
|
|
15
|
+
import type { atom, atomFamily } from "./atom"
|
|
16
16
|
import type { selector, selectorFamily } from "./selector"
|
|
17
17
|
import type { transaction } from "./transaction"
|
|
18
18
|
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
subscribe: (token, handler) => subscribe(token, handler, store),
|
|
50
|
-
undo: (token) => undo__INTERNAL(token, store),
|
|
51
|
-
redo: (token) => redo__INTERNAL(token, store),
|
|
19
|
+
export class Silo {
|
|
20
|
+
public store: Store
|
|
21
|
+
public atom: typeof atom
|
|
22
|
+
public atomFamily: typeof atomFamily
|
|
23
|
+
public selector: typeof selector
|
|
24
|
+
public selectorFamily: typeof selectorFamily
|
|
25
|
+
public transaction: typeof transaction
|
|
26
|
+
public timeline: typeof timeline
|
|
27
|
+
public getState: typeof getState
|
|
28
|
+
public setState: typeof setState
|
|
29
|
+
public subscribe: typeof subscribe
|
|
30
|
+
public undo: typeof undo
|
|
31
|
+
public redo: typeof redo
|
|
32
|
+
public constructor(name: string, fromStore: Store | null = null) {
|
|
33
|
+
const store = new Store(name, fromStore)
|
|
34
|
+
this.store = store
|
|
35
|
+
this.atom = (options) => atom__INTERNAL(options, undefined, store)
|
|
36
|
+
this.atomFamily = (options) => atomFamily__INTERNAL(options, store)
|
|
37
|
+
this.selector = (options) =>
|
|
38
|
+
selector__INTERNAL(options, undefined, store) as any
|
|
39
|
+
this.selectorFamily = (options) =>
|
|
40
|
+
selectorFamily__INTERNAL(options, store) as any
|
|
41
|
+
this.transaction = (options) => transaction__INTERNAL(options, store)
|
|
42
|
+
this.timeline = (options) => timeline__INTERNAL(options, store)
|
|
43
|
+
this.getState = (token) => getState(token, store)
|
|
44
|
+
this.setState = (token, newValue) => setState(token, newValue, store)
|
|
45
|
+
;(this.subscribe = (token, handler, key) =>
|
|
46
|
+
subscribe(token, handler, key, store)),
|
|
47
|
+
(this.undo = (token) => undo__INTERNAL(token, store))
|
|
48
|
+
this.redo = (token) => redo__INTERNAL(token, store)
|
|
52
49
|
}
|
|
53
50
|
}
|
package/src/subscribe.ts
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Store } from "atom.io/internal"
|
|
2
|
+
import { IMPLICIT, subscribeToRootAtoms, withdraw } from "atom.io/internal"
|
|
2
3
|
|
|
3
4
|
import type {
|
|
5
|
+
FamilyMetadata,
|
|
4
6
|
ReadonlySelectorToken,
|
|
5
7
|
StateToken,
|
|
6
8
|
TimelineToken,
|
|
7
9
|
TimelineUpdate,
|
|
8
10
|
TransactionToken,
|
|
9
11
|
TransactionUpdate,
|
|
12
|
+
ƒn,
|
|
10
13
|
} from "."
|
|
11
|
-
import type { Store } from "./internal"
|
|
12
|
-
import { IMPLICIT, subscribeToRootAtoms, withdraw } from "./internal"
|
|
13
14
|
|
|
14
15
|
export type StateUpdate<T> = { newValue: T; oldValue: T }
|
|
15
|
-
export type KeyedStateUpdate<T> = StateUpdate<T> & {
|
|
16
|
+
export type KeyedStateUpdate<T> = StateUpdate<T> & {
|
|
17
|
+
key: string
|
|
18
|
+
family?: FamilyMetadata
|
|
19
|
+
}
|
|
16
20
|
export type UpdateHandler<T> = (update: StateUpdate<T>) => void
|
|
17
21
|
|
|
18
22
|
export const subscribe = <T>(
|
|
19
23
|
token: ReadonlySelectorToken<T> | StateToken<T>,
|
|
20
24
|
handleUpdate: UpdateHandler<T>,
|
|
25
|
+
key: string = Math.random().toString(36).slice(2),
|
|
21
26
|
store: Store = IMPLICIT.STORE,
|
|
22
27
|
): (() => void) => {
|
|
23
28
|
const state = withdraw<T>(token, store)
|
|
@@ -26,24 +31,24 @@ export const subscribe = <T>(
|
|
|
26
31
|
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`,
|
|
27
32
|
)
|
|
28
33
|
}
|
|
29
|
-
const
|
|
34
|
+
const unsubFunction = state.subject.subscribe(key, handleUpdate)
|
|
30
35
|
store.config.logger?.info(`👀 subscribe to "${state.key}"`)
|
|
31
|
-
const
|
|
36
|
+
const dependencyUnsubFunctions =
|
|
32
37
|
state.type !== `atom` ? subscribeToRootAtoms(state, store) : null
|
|
33
38
|
|
|
34
39
|
const unsubscribe =
|
|
35
|
-
|
|
40
|
+
dependencyUnsubFunctions === null
|
|
36
41
|
? () => {
|
|
37
42
|
store.config.logger?.info(`🙈 unsubscribe from "${state.key}"`)
|
|
38
|
-
|
|
43
|
+
unsubFunction()
|
|
39
44
|
}
|
|
40
45
|
: () => {
|
|
41
46
|
store.config.logger?.info(
|
|
42
47
|
`🙈 unsubscribe from "${state.key}" and its dependencies`,
|
|
43
48
|
)
|
|
44
|
-
|
|
45
|
-
for (const
|
|
46
|
-
|
|
49
|
+
unsubFunction()
|
|
50
|
+
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
51
|
+
unsubFromDependency()
|
|
47
52
|
}
|
|
48
53
|
}
|
|
49
54
|
|
|
@@ -57,6 +62,7 @@ export type TransactionUpdateHandler<ƒ extends ƒn> = (
|
|
|
57
62
|
export const subscribeToTransaction = <ƒ extends ƒn>(
|
|
58
63
|
token: TransactionToken<ƒ>,
|
|
59
64
|
handleUpdate: TransactionUpdateHandler<ƒ>,
|
|
65
|
+
key: string = Math.random().toString(36).slice(2),
|
|
60
66
|
store = IMPLICIT.STORE,
|
|
61
67
|
): (() => void) => {
|
|
62
68
|
const tx = withdraw(token, store)
|
|
@@ -66,17 +72,17 @@ export const subscribeToTransaction = <ƒ extends ƒn>(
|
|
|
66
72
|
)
|
|
67
73
|
}
|
|
68
74
|
store.config.logger?.info(`👀 subscribe to transaction "${token.key}"`)
|
|
69
|
-
const
|
|
70
|
-
|
|
75
|
+
const unsubscribe = tx.subject.subscribe(key, handleUpdate)
|
|
76
|
+
return () => {
|
|
71
77
|
store.config.logger?.info(`🙈 unsubscribe from transaction "${token.key}"`)
|
|
72
|
-
|
|
78
|
+
unsubscribe()
|
|
73
79
|
}
|
|
74
|
-
return unsubscribe
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
export const subscribeToTimeline = (
|
|
78
83
|
token: TimelineToken,
|
|
79
|
-
handleUpdate: (update: TimelineUpdate) => void,
|
|
84
|
+
handleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,
|
|
85
|
+
key: string = Math.random().toString(36).slice(2),
|
|
80
86
|
store = IMPLICIT.STORE,
|
|
81
87
|
): (() => void) => {
|
|
82
88
|
const tl = withdraw(token, store)
|
|
@@ -86,10 +92,9 @@ export const subscribeToTimeline = (
|
|
|
86
92
|
)
|
|
87
93
|
}
|
|
88
94
|
store.config.logger?.info(`👀 subscribe to timeline "${token.key}"`)
|
|
89
|
-
const
|
|
90
|
-
|
|
95
|
+
const unsubscribe = tl.subject.subscribe(key, handleUpdate)
|
|
96
|
+
return () => {
|
|
91
97
|
store.config.logger?.info(`🙈 unsubscribe from timeline "${token.key}"`)
|
|
92
|
-
|
|
98
|
+
unsubscribe()
|
|
93
99
|
}
|
|
94
|
-
return unsubscribe
|
|
95
100
|
}
|
package/src/timeline.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import type { AtomFamily, AtomToken } from "."
|
|
2
1
|
import type {
|
|
3
2
|
TimelineAtomUpdate,
|
|
4
3
|
TimelineSelectorUpdate,
|
|
5
4
|
TimelineTransactionUpdate,
|
|
6
|
-
} from "
|
|
7
|
-
import { IMPLICIT } from "
|
|
8
|
-
import {
|
|
5
|
+
} from "atom.io/internal"
|
|
6
|
+
import { IMPLICIT } from "atom.io/internal"
|
|
7
|
+
import {
|
|
8
|
+
redo__INTERNAL,
|
|
9
|
+
timeline__INTERNAL,
|
|
10
|
+
undo__INTERNAL,
|
|
11
|
+
} from "atom.io/internal/"
|
|
12
|
+
|
|
13
|
+
import type { AtomFamily, AtomToken } from "."
|
|
9
14
|
|
|
10
15
|
export type TimelineToken = {
|
|
11
16
|
key: string
|
package/src/transaction.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Store } from "atom.io/internal"
|
|
2
|
+
import { IMPLICIT, transaction__INTERNAL, withdraw } from "atom.io/internal"
|
|
2
3
|
|
|
3
|
-
import type { KeyedStateUpdate, ReadonlySelectorToken, StateToken } from "."
|
|
4
|
-
import type { Store } from "./internal"
|
|
5
|
-
import { IMPLICIT, transaction__INTERNAL, withdraw } from "./internal"
|
|
4
|
+
import type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from "."
|
|
6
5
|
|
|
7
6
|
export type TransactionToken<_> = {
|
|
8
7
|
key: string
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Subject } from "."
|
|
2
|
-
import { deposit } from "./get"
|
|
3
|
-
import { markAtomAsDefault } from "./is-default"
|
|
4
|
-
import { cacheValue } from "./operation"
|
|
5
|
-
import type { Store } from "./store"
|
|
6
|
-
import { IMPLICIT } from "./store"
|
|
7
|
-
import { target } from "./transaction-internal"
|
|
8
|
-
import type { AtomToken, FamilyMetadata, UpdateHandler } from ".."
|
|
9
|
-
import { setState, subscribe } from ".."
|
|
10
|
-
import type { AtomOptions } from "../atom"
|
|
11
|
-
|
|
12
|
-
export type Atom<T> = {
|
|
13
|
-
key: string
|
|
14
|
-
type: `atom`
|
|
15
|
-
family?: FamilyMetadata
|
|
16
|
-
subject: Subject<{ newValue: T; oldValue: T }>
|
|
17
|
-
default: T
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function atom__INTERNAL<T>(
|
|
21
|
-
options: AtomOptions<T>,
|
|
22
|
-
family?: FamilyMetadata,
|
|
23
|
-
store: Store = IMPLICIT.STORE,
|
|
24
|
-
): AtomToken<T> {
|
|
25
|
-
const core = target(store)
|
|
26
|
-
const existing = core.atoms.get(options.key)
|
|
27
|
-
if (existing) {
|
|
28
|
-
store.config.logger?.error?.(
|
|
29
|
-
`Key "${options.key}" already exists in the store.`,
|
|
30
|
-
)
|
|
31
|
-
return deposit(existing)
|
|
32
|
-
}
|
|
33
|
-
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
34
|
-
const newAtom = {
|
|
35
|
-
...options,
|
|
36
|
-
subject,
|
|
37
|
-
type: `atom`,
|
|
38
|
-
...(family && { family }),
|
|
39
|
-
} as const
|
|
40
|
-
const initialValue =
|
|
41
|
-
options.default instanceof Function ? options.default() : options.default
|
|
42
|
-
core.atoms.set(newAtom.key, newAtom)
|
|
43
|
-
markAtomAsDefault(options.key, store)
|
|
44
|
-
cacheValue(options.key, initialValue, store)
|
|
45
|
-
const token = deposit(newAtom)
|
|
46
|
-
options.effects?.forEach((effect) =>
|
|
47
|
-
effect({
|
|
48
|
-
setSelf: (next) => setState(token, next, store),
|
|
49
|
-
onSet: (handle: UpdateHandler<T>) => subscribe(token, handle, store),
|
|
50
|
-
}),
|
|
51
|
-
)
|
|
52
|
-
store.subject.atomCreation.next(token)
|
|
53
|
-
return token as AtomToken<T>
|
|
54
|
-
}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { Serializable } from "~/packages/anvl/src/json"
|
|
2
|
-
import { stringifyJson } from "~/packages/anvl/src/json"
|
|
3
|
-
|
|
4
|
-
import type { Store } from "."
|
|
5
|
-
import {
|
|
6
|
-
Subject,
|
|
7
|
-
atom__INTERNAL,
|
|
8
|
-
withdraw,
|
|
9
|
-
selector__INTERNAL,
|
|
10
|
-
target,
|
|
11
|
-
deposit,
|
|
12
|
-
IMPLICIT,
|
|
13
|
-
} from "."
|
|
14
|
-
import type {
|
|
15
|
-
AtomFamily,
|
|
16
|
-
AtomFamilyOptions,
|
|
17
|
-
AtomToken,
|
|
18
|
-
FamilyMetadata,
|
|
19
|
-
ReadonlySelectorFamily,
|
|
20
|
-
ReadonlySelectorFamilyOptions,
|
|
21
|
-
ReadonlySelectorToken,
|
|
22
|
-
SelectorFamily,
|
|
23
|
-
SelectorFamilyOptions,
|
|
24
|
-
SelectorToken,
|
|
25
|
-
} from ".."
|
|
26
|
-
|
|
27
|
-
export function atomFamily__INTERNAL<T, K extends Serializable>(
|
|
28
|
-
options: AtomFamilyOptions<T, K>,
|
|
29
|
-
store: Store = IMPLICIT.STORE,
|
|
30
|
-
): AtomFamily<T, K> {
|
|
31
|
-
const subject = new Subject<AtomToken<T>>()
|
|
32
|
-
return Object.assign(
|
|
33
|
-
(key: K): AtomToken<T> => {
|
|
34
|
-
const subKey = stringifyJson(key)
|
|
35
|
-
const family: FamilyMetadata = { key: options.key, subKey }
|
|
36
|
-
const fullKey = `${options.key}(${subKey})`
|
|
37
|
-
const existing = withdraw({ key: fullKey, type: `atom` }, store)
|
|
38
|
-
const token: AtomToken<any> = existing
|
|
39
|
-
? deposit(existing)
|
|
40
|
-
: atom__INTERNAL<T>(
|
|
41
|
-
{
|
|
42
|
-
key: fullKey,
|
|
43
|
-
default:
|
|
44
|
-
options.default instanceof Function
|
|
45
|
-
? options.default(key)
|
|
46
|
-
: options.default,
|
|
47
|
-
effects: options.effects?.(key),
|
|
48
|
-
},
|
|
49
|
-
family,
|
|
50
|
-
store,
|
|
51
|
-
)
|
|
52
|
-
subject.next(token)
|
|
53
|
-
return token
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
key: options.key,
|
|
57
|
-
type: `atom_family`,
|
|
58
|
-
subject,
|
|
59
|
-
} as const,
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function readonlySelectorFamily__INTERNAL<T, K extends Serializable>(
|
|
64
|
-
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
65
|
-
store?: Store,
|
|
66
|
-
): ReadonlySelectorFamily<T, K> {
|
|
67
|
-
const core = target(store)
|
|
68
|
-
const subject = new Subject<ReadonlySelectorToken<T>>()
|
|
69
|
-
return Object.assign(
|
|
70
|
-
(key: K): ReadonlySelectorToken<T> => {
|
|
71
|
-
const subKey = stringifyJson(key)
|
|
72
|
-
const family: FamilyMetadata = { key: options.key, subKey }
|
|
73
|
-
const fullKey = `${options.key}(${subKey})`
|
|
74
|
-
const existing = core.readonlySelectors.get(fullKey)
|
|
75
|
-
if (existing) {
|
|
76
|
-
return deposit(existing)
|
|
77
|
-
}
|
|
78
|
-
return selector__INTERNAL<T>(
|
|
79
|
-
{
|
|
80
|
-
key: fullKey,
|
|
81
|
-
get: options.get(key),
|
|
82
|
-
},
|
|
83
|
-
family,
|
|
84
|
-
store,
|
|
85
|
-
) as ReadonlySelectorToken<T>
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
key: options.key,
|
|
89
|
-
type: `readonly_selector_family`,
|
|
90
|
-
subject,
|
|
91
|
-
} as const,
|
|
92
|
-
) as ReadonlySelectorFamily<T, K>
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function selectorFamily__INTERNAL<T, K extends Serializable>(
|
|
96
|
-
options: SelectorFamilyOptions<T, K>,
|
|
97
|
-
store?: Store,
|
|
98
|
-
): SelectorFamily<T, K>
|
|
99
|
-
export function selectorFamily__INTERNAL<T, K extends Serializable>(
|
|
100
|
-
options: ReadonlySelectorFamilyOptions<T, K>,
|
|
101
|
-
store?: Store,
|
|
102
|
-
): ReadonlySelectorFamily<T, K>
|
|
103
|
-
export function selectorFamily__INTERNAL<T, K extends Serializable>(
|
|
104
|
-
options: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,
|
|
105
|
-
store: Store = IMPLICIT.STORE,
|
|
106
|
-
): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {
|
|
107
|
-
const isReadonly = !(`set` in options)
|
|
108
|
-
|
|
109
|
-
if (isReadonly) {
|
|
110
|
-
return readonlySelectorFamily__INTERNAL(options, store)
|
|
111
|
-
}
|
|
112
|
-
const core = target(store)
|
|
113
|
-
const subject = new Subject<SelectorToken<T>>()
|
|
114
|
-
|
|
115
|
-
return Object.assign(
|
|
116
|
-
(key: K): SelectorToken<T> => {
|
|
117
|
-
const subKey = stringifyJson(key)
|
|
118
|
-
const family: FamilyMetadata = { key: options.key, subKey }
|
|
119
|
-
const fullKey = `${options.key}(${subKey})`
|
|
120
|
-
const existing = core.selectors.get(fullKey)
|
|
121
|
-
if (existing) {
|
|
122
|
-
return deposit(existing)
|
|
123
|
-
}
|
|
124
|
-
const token = selector__INTERNAL<T>(
|
|
125
|
-
{
|
|
126
|
-
key: fullKey,
|
|
127
|
-
get: options.get(key),
|
|
128
|
-
set: options.set(key),
|
|
129
|
-
},
|
|
130
|
-
family,
|
|
131
|
-
store,
|
|
132
|
-
)
|
|
133
|
-
subject.next(token)
|
|
134
|
-
return token
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
key: options.key,
|
|
138
|
-
type: `selector_family`,
|
|
139
|
-
} as const,
|
|
140
|
-
) as SelectorFamily<T, K>
|
|
141
|
-
}
|