atom.io 0.22.0 → 0.23.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/data/dist/index.cjs +17 -1
- package/data/dist/index.js +1 -1
- package/data/src/join.ts +30 -1
- package/dist/chunk-6MLFYN32.js +18 -0
- package/dist/{chunk-JA4V7TJY.js → chunk-7DT3PVS3.js} +18 -2
- package/dist/chunk-OAYGID5B.js +27 -0
- package/dist/index.cjs +2 -11
- package/dist/index.d.ts +51 -23
- package/dist/index.js +2 -11
- package/eslint-plugin/dist/index.cjs +0 -1
- package/eslint-plugin/dist/index.js +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -1
- package/immortal/dist/index.cjs +180 -20
- package/immortal/dist/index.js +134 -19
- package/immortal/src/index.ts +1 -0
- package/immortal/src/make-molecule.ts +222 -0
- package/immortal/src/molecule.ts +49 -16
- package/immortal/src/seek-state.ts +15 -2
- package/internal/dist/index.cjs +1119 -754
- package/internal/dist/index.d.ts +109 -12
- package/internal/dist/index.js +1098 -760
- package/internal/src/atom/create-regular-atom.ts +0 -2
- package/internal/src/atom/create-standalone-atom.ts +6 -2
- package/internal/src/atom/dispose-atom.ts +22 -2
- package/internal/src/families/create-readonly-selector-family.ts +7 -2
- package/internal/src/families/create-regular-atom-family.ts +6 -2
- package/internal/src/families/create-writable-selector-family.ts +7 -2
- package/internal/src/families/dispose-from-store.ts +22 -0
- package/internal/src/families/find-in-store.ts +0 -1
- package/internal/src/families/index.ts +1 -0
- package/internal/src/families/init-family-member.ts +22 -1
- package/internal/src/families/seek-in-store.ts +23 -6
- package/internal/src/ingest-updates/index.ts +1 -0
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +104 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +26 -4
- package/internal/src/mutable/create-mutable-atom-family.ts +6 -2
- package/internal/src/mutable/create-mutable-atom.ts +0 -2
- package/internal/src/mutable/get-json-token.ts +0 -1
- package/internal/src/mutable/tracker-family.ts +7 -7
- package/internal/src/not-found-error.ts +5 -0
- package/internal/src/selector/create-readonly-selector.ts +2 -3
- package/internal/src/selector/create-standalone-selector.ts +6 -2
- package/internal/src/selector/create-writable-selector.ts +2 -3
- package/internal/src/selector/dispose-selector.ts +32 -5
- package/internal/src/selector/register-selector.ts +2 -0
- package/internal/src/set-state/stow-update.ts +5 -1
- package/internal/src/store/deposit.ts +41 -7
- package/internal/src/store/store.ts +11 -0
- package/internal/src/store/withdraw.ts +28 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +206 -182
- package/internal/src/timeline/create-timeline.ts +181 -60
- package/internal/src/timeline/time-travel.ts +20 -0
- package/internal/src/transaction/apply-transaction.ts +2 -12
- package/internal/src/transaction/build-transaction.ts +11 -2
- package/introspection/dist/index.cjs +2 -1
- package/introspection/dist/index.js +2 -1
- package/introspection/src/attach-timeline-family.ts +1 -0
- package/json/dist/index.cjs +3 -3
- package/json/dist/index.js +6 -5
- package/json/src/select-json-family.ts +3 -4
- package/package.json +5 -5
- package/react-devtools/dist/index.cjs +58 -47
- package/react-devtools/dist/index.js +60 -48
- package/react-devtools/src/TimelineIndex.tsx +15 -13
- package/react-devtools/src/Updates.tsx +41 -32
- package/realtime-server/dist/index.cjs +21 -10
- package/realtime-server/dist/index.d.ts +1 -1
- package/realtime-server/dist/index.js +21 -11
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +21 -11
- package/realtime-testing/dist/index.cjs +1 -0
- package/realtime-testing/dist/index.js +1 -1
- package/src/atom.ts +9 -3
- package/src/dispose-state.ts +3 -12
- package/src/index.ts +4 -0
- package/src/selector.ts +3 -3
- package/src/subscribe.ts +8 -4
- package/src/timeline.ts +18 -1
- package/src/transaction.ts +56 -4
- package/dist/chunk-BF4MVQF6.js +0 -44
package/immortal/src/molecule.ts
CHANGED
|
@@ -7,30 +7,58 @@ import type {
|
|
|
7
7
|
ReadonlySelectorToken,
|
|
8
8
|
RegularAtomFamilyToken,
|
|
9
9
|
RegularAtomToken,
|
|
10
|
+
StateCreation,
|
|
11
|
+
StateDisposal,
|
|
10
12
|
WritableFamilyToken,
|
|
11
13
|
WritableSelectorFamilyToken,
|
|
12
14
|
WritableSelectorToken,
|
|
13
15
|
WritableToken,
|
|
14
16
|
} from "atom.io"
|
|
15
|
-
import { disposeState } from "atom.io"
|
|
16
17
|
import type { Join, JoinToken } from "atom.io/data"
|
|
17
18
|
import { getJoin } from "atom.io/data"
|
|
18
19
|
import type { Store, Transceiver } from "atom.io/internal"
|
|
19
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
disposeFromStore,
|
|
22
|
+
getJsonFamily,
|
|
23
|
+
initFamilyMember,
|
|
24
|
+
newest,
|
|
25
|
+
Subject,
|
|
26
|
+
} from "atom.io/internal"
|
|
20
27
|
import { type Json, stringifyJson } from "atom.io/json"
|
|
21
28
|
|
|
29
|
+
import type { MoleculeFamilyToken, MoleculeToken } from "./make-molecule"
|
|
30
|
+
|
|
22
31
|
export class Molecule<Key extends Json.Serializable> {
|
|
32
|
+
public readonly type = `molecule`
|
|
33
|
+
public get key(): Key {
|
|
34
|
+
return this.token.key
|
|
35
|
+
}
|
|
36
|
+
public readonly family?: MoleculeFamilyToken<Key, any, any>
|
|
37
|
+
public readonly above: Molecule<any>[]
|
|
23
38
|
public readonly below: Molecule<any>[] = []
|
|
24
39
|
public readonly tokens: ReadableToken<any>[] = []
|
|
25
40
|
public readonly joins: Join<any, any, any, any>[] = []
|
|
41
|
+
public readonly subject = new Subject<
|
|
42
|
+
StateCreation<any> | StateDisposal<any>
|
|
43
|
+
>()
|
|
26
44
|
public constructor(
|
|
27
|
-
public readonly
|
|
28
|
-
|
|
29
|
-
public readonly
|
|
45
|
+
public readonly store: Store,
|
|
46
|
+
above: Molecule<any> | Molecule<any>[] | undefined,
|
|
47
|
+
public readonly token: MoleculeToken<Key, any, any>,
|
|
30
48
|
) {
|
|
31
|
-
store.molecules.set(stringifyJson(key), this)
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
// store.molecules.set(stringifyJson(key), this) // consider removing this
|
|
50
|
+
if (above) {
|
|
51
|
+
if (Array.isArray(above)) {
|
|
52
|
+
this.above = above
|
|
53
|
+
for (const parent of above) {
|
|
54
|
+
parent.below.push(this)
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
this.above = [above]
|
|
58
|
+
above.below.push(this)
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
this.above = []
|
|
34
62
|
}
|
|
35
63
|
}
|
|
36
64
|
|
|
@@ -55,24 +83,28 @@ export class Molecule<Key extends Json.Serializable> {
|
|
|
55
83
|
token: ReadableFamilyToken<T, K>,
|
|
56
84
|
): ReadableToken<T>
|
|
57
85
|
public bond(token: ReadableFamilyToken<any, any>): ReadableToken<any> {
|
|
58
|
-
const state = initFamilyMember(token, this.key, this.store)
|
|
86
|
+
const state = initFamilyMember(token, this.token.key, this.store)
|
|
59
87
|
if (token.type === `mutable_atom_family`) {
|
|
60
88
|
const jsonFamily = getJsonFamily(token, this.store)
|
|
61
|
-
const jsonState = initFamilyMember(jsonFamily, this.key, this.store)
|
|
89
|
+
const jsonState = initFamilyMember(jsonFamily, this.token.key, this.store)
|
|
62
90
|
this.tokens.push(jsonState)
|
|
63
91
|
}
|
|
64
92
|
this.tokens.push(state)
|
|
93
|
+
this.subject.next({ type: `state_creation`, token: state })
|
|
65
94
|
return state
|
|
66
95
|
}
|
|
67
96
|
|
|
68
97
|
public spawn<K extends Json.Serializable>(key: K): Molecule<K> {
|
|
69
|
-
const child = new Molecule(
|
|
98
|
+
const child = new Molecule(this.store, this, { key, type: `molecule` })
|
|
70
99
|
return child
|
|
71
100
|
}
|
|
72
101
|
|
|
73
102
|
public with(molecule: Molecule<any>): (key: string) => Molecule<any> {
|
|
74
103
|
return (key) => {
|
|
75
|
-
const child = new Molecule(
|
|
104
|
+
const child = new Molecule(this.store, [this, molecule], {
|
|
105
|
+
key,
|
|
106
|
+
type: `molecule`,
|
|
107
|
+
})
|
|
76
108
|
return child
|
|
77
109
|
}
|
|
78
110
|
}
|
|
@@ -106,26 +138,27 @@ export class Molecule<Key extends Json.Serializable> {
|
|
|
106
138
|
while (this.tokens.length > 0) {
|
|
107
139
|
const token = this.tokens.pop()
|
|
108
140
|
if (token) {
|
|
109
|
-
|
|
141
|
+
disposeFromStore(token, this.store)
|
|
110
142
|
}
|
|
111
143
|
}
|
|
112
144
|
while (this.joins.length > 0) {
|
|
113
145
|
const join = this.joins.pop()
|
|
114
146
|
if (join) {
|
|
115
|
-
join.molecules.delete(stringifyJson(this.key))
|
|
147
|
+
join.molecules.delete(stringifyJson(this.token.key))
|
|
116
148
|
}
|
|
117
149
|
}
|
|
118
150
|
}
|
|
119
151
|
|
|
120
152
|
public join(token: JoinToken<any, any, any, any>): void {
|
|
121
153
|
const join = getJoin(token, this.store)
|
|
122
|
-
join.molecules.set(stringifyJson(this.key), this)
|
|
154
|
+
join.molecules.set(stringifyJson(this.token.key), this)
|
|
123
155
|
this.joins.push(join)
|
|
124
156
|
}
|
|
125
157
|
|
|
126
158
|
private [Symbol.dispose](): void {
|
|
127
159
|
this.clear()
|
|
128
|
-
this.store
|
|
160
|
+
const target = newest(this.store)
|
|
161
|
+
target.molecules.delete(stringifyJson(this.token.key))
|
|
129
162
|
for (const parent of this.above) {
|
|
130
163
|
parent.detach(this)
|
|
131
164
|
}
|
|
@@ -16,6 +16,8 @@ import type { Transceiver } from "atom.io/internal"
|
|
|
16
16
|
import { IMPLICIT, seekInStore } from "atom.io/internal"
|
|
17
17
|
import type { Json } from "atom.io/json"
|
|
18
18
|
|
|
19
|
+
import type { MoleculeFamilyToken, MoleculeToken } from "./make-molecule"
|
|
20
|
+
|
|
19
21
|
export function seekState<
|
|
20
22
|
T extends Transceiver<any>,
|
|
21
23
|
J extends Json.Serializable,
|
|
@@ -51,10 +53,21 @@ export function seekState<T, K extends Json.Serializable, Key extends K>(
|
|
|
51
53
|
key: Key,
|
|
52
54
|
): ReadableToken<T> | undefined
|
|
53
55
|
|
|
56
|
+
export function seekState<
|
|
57
|
+
K extends Json.Serializable,
|
|
58
|
+
S extends { [key: string]: any },
|
|
59
|
+
>(
|
|
60
|
+
token: MoleculeFamilyToken<K, S, any[]>,
|
|
61
|
+
key: K,
|
|
62
|
+
): MoleculeToken<K, S, any[]> | undefined
|
|
63
|
+
|
|
54
64
|
export function seekState(
|
|
55
|
-
token: ReadableFamilyToken<any, any>,
|
|
65
|
+
token: MoleculeFamilyToken<any, any, any> | ReadableFamilyToken<any, any>,
|
|
56
66
|
key: Json.Serializable,
|
|
57
|
-
): ReadableToken<any> | undefined {
|
|
67
|
+
): MoleculeToken<any, any, any> | ReadableToken<any> | undefined {
|
|
68
|
+
if (token.type === `molecule_family`) {
|
|
69
|
+
return seekInStore(token, key, IMPLICIT.STORE)
|
|
70
|
+
}
|
|
58
71
|
const state = seekInStore(token, key, IMPLICIT.STORE)
|
|
59
72
|
return state
|
|
60
73
|
}
|