atom.io 0.21.0 → 0.22.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 +139 -66
- package/data/dist/index.d.ts +6 -0
- package/data/dist/index.js +3 -3
- package/data/src/join.ts +135 -56
- package/data/src/struct-family.ts +2 -2
- package/dist/{chunk-RT43TVKP.js → chunk-GVHKIJ3G.js} +1 -1
- package/dist/{chunk-KGZGBCYS.js → chunk-JA4V7TJY.js} +135 -62
- package/dist/index.cjs +2 -7
- package/dist/index.d.ts +29 -14
- package/dist/index.js +4 -8
- package/ephemeral/dist/index.cjs +11 -0
- package/ephemeral/dist/index.js +9 -0
- package/ephemeral/package.json +16 -0
- package/ephemeral/src/index.ts +1 -0
- package/eslint-plugin/dist/index.cjs +156 -1
- package/eslint-plugin/dist/index.js +156 -1
- package/eslint-plugin/src/rules/index.ts +1 -0
- package/eslint-plugin/src/rules/lifespan.ts +204 -0
- package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -65
- package/eslint-plugin/src/walk.ts +73 -0
- package/immortal/dist/index.cjs +100 -0
- package/immortal/dist/index.js +97 -0
- package/immortal/package.json +16 -0
- package/immortal/src/index.ts +2 -0
- package/immortal/src/molecule.ts +134 -0
- package/immortal/src/seek-state.ts +60 -0
- package/internal/dist/index.cjs +211 -194
- package/internal/dist/index.d.ts +30 -14
- package/internal/dist/index.js +210 -194
- package/internal/src/atom/dispose-atom.ts +4 -1
- package/internal/src/families/create-readonly-selector-family.ts +9 -9
- package/internal/src/families/create-regular-atom-family.ts +15 -20
- package/internal/src/families/create-writable-selector-family.ts +6 -7
- package/internal/src/families/find-in-store.ts +11 -5
- package/internal/src/families/index.ts +2 -0
- package/internal/src/families/init-family-member.ts +91 -0
- package/internal/src/families/seek-in-store.ts +106 -0
- package/internal/src/future.ts +6 -20
- package/internal/src/get-state/get-from-store.ts +2 -3
- package/internal/src/mutable/create-mutable-atom-family.ts +17 -23
- package/internal/src/mutable/create-mutable-atom.ts +3 -1
- package/internal/src/mutable/get-json-family.ts +2 -2
- package/internal/src/mutable/get-json-token.ts +27 -12
- package/internal/src/mutable/tracker-family.ts +14 -12
- package/internal/src/mutable/tracker.ts +2 -24
- package/internal/src/not-found-error.ts +11 -3
- package/internal/src/operation.ts +0 -1
- package/internal/src/selector/create-readonly-selector.ts +2 -2
- package/internal/src/selector/create-writable-selector.ts +2 -2
- package/internal/src/selector/dispose-selector.ts +40 -23
- package/internal/src/selector/register-selector.ts +8 -5
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/store/index.ts +0 -1
- package/internal/src/store/store.ts +18 -5
- package/internal/src/subscribe/recall-state.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +18 -5
- package/internal/src/transaction/build-transaction.ts +7 -2
- package/introspection/dist/index.cjs +39 -65
- package/introspection/dist/index.js +39 -65
- package/introspection/src/attach-atom-index.ts +38 -48
- package/introspection/src/attach-introspection-states.ts +0 -1
- package/introspection/src/attach-selector-index.ts +45 -50
- package/introspection/src/attach-timeline-family.ts +2 -17
- package/json/dist/index.cjs +38 -4
- package/json/dist/index.js +40 -6
- package/json/src/select-json-family.ts +46 -7
- package/package.json +31 -11
- package/react/dist/index.cjs +1 -1
- package/react/dist/index.js +1 -1
- package/react/src/use-json.ts +1 -1
- package/react-devtools/dist/index.cjs +11 -10
- package/react-devtools/dist/index.js +2 -1
- package/react-devtools/src/StateIndex.tsx +2 -1
- package/react-devtools/src/TimelineIndex.tsx +2 -1
- package/react-devtools/src/TransactionIndex.tsx +7 -7
- package/realtime-client/dist/index.cjs +3 -3
- package/realtime-client/dist/index.js +3 -3
- package/realtime-client/src/pull-mutable-atom-family-member.ts +1 -1
- package/realtime-client/src/pull-mutable-atom.ts +1 -1
- package/realtime-client/src/sync-continuity.ts +1 -2
- package/realtime-react/dist/index.cjs +1 -1
- package/realtime-react/dist/index.js +1 -1
- package/realtime-server/dist/index.cjs +18 -17
- package/realtime-server/dist/index.js +7 -6
- package/realtime-server/src/realtime-continuity-synchronizer.ts +5 -3
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
- package/realtime-server/src/realtime-mutable-provider.ts +1 -1
- package/realtime-testing/dist/index.cjs +6 -2
- package/realtime-testing/dist/index.js +8 -5
- package/realtime-testing/src/setup-realtime-test.tsx +5 -2
- package/src/atom.ts +10 -4
- package/src/index.ts +1 -2
- package/src/selector.ts +10 -4
- package/src/silo.ts +3 -3
- package/src/transaction.ts +5 -2
- package/src/validators.ts +0 -6
- package/internal/src/store/withdraw-new-family-member.ts +0 -69
- /package/{src → ephemeral/src}/find-state.ts +0 -0
- /package/src/{dispose.ts → dispose-state.ts} +0 -0
|
@@ -2,7 +2,7 @@ import type { MutableAtomFamily, RegularAtomFamily } from "atom.io"
|
|
|
2
2
|
import type { Json } from "atom.io/json"
|
|
3
3
|
import { parseJson } from "atom.io/json"
|
|
4
4
|
|
|
5
|
-
import { createRegularAtomFamily } from "../families"
|
|
5
|
+
import { createRegularAtomFamily, seekInStore } from "../families"
|
|
6
6
|
import type { Store } from "../store"
|
|
7
7
|
import { Tracker } from "./tracker"
|
|
8
8
|
import type { Transceiver } from "./transceiver"
|
|
@@ -15,44 +15,46 @@ export class FamilyTracker<
|
|
|
15
15
|
? Signal
|
|
16
16
|
: never
|
|
17
17
|
|
|
18
|
-
public readonly
|
|
18
|
+
public readonly latestUpdateAtoms: RegularAtomFamily<
|
|
19
19
|
typeof this.Update | null,
|
|
20
20
|
FamilyMemberKey
|
|
21
21
|
>
|
|
22
|
-
public readonly
|
|
22
|
+
public readonly mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>
|
|
23
23
|
|
|
24
24
|
public constructor(
|
|
25
|
-
|
|
25
|
+
mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>,
|
|
26
26
|
store: Store,
|
|
27
27
|
) {
|
|
28
|
-
this.
|
|
28
|
+
this.latestUpdateAtoms = createRegularAtomFamily<
|
|
29
29
|
typeof this.Update | null,
|
|
30
30
|
FamilyMemberKey
|
|
31
31
|
>(
|
|
32
32
|
{
|
|
33
|
-
key: `*${
|
|
33
|
+
key: `*${mutableAtoms.key}`,
|
|
34
34
|
default: null,
|
|
35
35
|
},
|
|
36
36
|
store,
|
|
37
37
|
)
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
38
|
+
this.mutableAtoms = mutableAtoms
|
|
39
|
+
this.mutableAtoms.subject.subscribe(
|
|
40
40
|
`store=${store.config.name}::tracker-atom-family`,
|
|
41
41
|
(atomToken) => {
|
|
42
42
|
if (atomToken.family) {
|
|
43
43
|
const key = parseJson(atomToken.family.subKey) as FamilyMemberKey
|
|
44
|
-
this.
|
|
44
|
+
seekInStore(this.latestUpdateAtoms, key, store)
|
|
45
45
|
new Tracker<Core>(atomToken, store)
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
)
|
|
49
|
-
this.
|
|
49
|
+
this.latestUpdateAtoms.subject.subscribe(
|
|
50
50
|
`store=${store.config.name}::tracker-atom-family`,
|
|
51
51
|
(atomToken) => {
|
|
52
52
|
if (atomToken.family) {
|
|
53
53
|
const key = parseJson(atomToken.family.subKey) as FamilyMemberKey
|
|
54
|
-
const mutableAtomToken = this.
|
|
55
|
-
|
|
54
|
+
const mutableAtomToken = seekInStore(this.mutableAtoms, key, store)
|
|
55
|
+
if (mutableAtomToken) {
|
|
56
|
+
new Tracker<Core>(mutableAtomToken, store)
|
|
57
|
+
}
|
|
56
58
|
}
|
|
57
59
|
},
|
|
58
60
|
)
|
|
@@ -66,18 +66,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
66
66
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
67
67
|
subscriptionKey,
|
|
68
68
|
(update) => {
|
|
69
|
-
|
|
70
|
-
const unsubscribe = target.on.operationClose.subscribe(
|
|
71
|
-
subscriptionKey,
|
|
72
|
-
() => {
|
|
73
|
-
unsubscribe()
|
|
74
|
-
setIntoStore(latestUpdateState, update, target)
|
|
75
|
-
},
|
|
76
|
-
)
|
|
77
|
-
} else {
|
|
78
|
-
setIntoStore(mutableState, (current) => current, target)
|
|
79
|
-
setIntoStore(latestUpdateState, update, target)
|
|
80
|
-
}
|
|
69
|
+
setIntoStore(latestUpdateState, update, target)
|
|
81
70
|
},
|
|
82
71
|
)
|
|
83
72
|
this.unsubscribeFromState = subscribeToState(
|
|
@@ -88,18 +77,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
88
77
|
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
89
78
|
subscriptionKey,
|
|
90
79
|
(transceiverUpdate) => {
|
|
91
|
-
|
|
92
|
-
const unsubscribe = target.on.operationClose.subscribe(
|
|
93
|
-
subscriptionKey,
|
|
94
|
-
() => {
|
|
95
|
-
unsubscribe()
|
|
96
|
-
setIntoStore(latestUpdateState, transceiverUpdate, target)
|
|
97
|
-
},
|
|
98
|
-
)
|
|
99
|
-
} else {
|
|
100
|
-
setIntoStore(mutableState, (current) => current, target)
|
|
101
|
-
setIntoStore(latestUpdateState, transceiverUpdate, target)
|
|
102
|
-
}
|
|
80
|
+
setIntoStore(latestUpdateState, transceiverUpdate, target)
|
|
103
81
|
},
|
|
104
82
|
)
|
|
105
83
|
}
|
|
@@ -16,10 +16,18 @@ type AtomIOToken =
|
|
|
16
16
|
| TransactionToken<any>
|
|
17
17
|
|
|
18
18
|
function prettyPrintTokenType(token: AtomIOToken) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
switch (token.type) {
|
|
20
|
+
case `atom_family`:
|
|
21
|
+
return `Atom Family`
|
|
22
|
+
case `readonly_selector`:
|
|
23
|
+
return `Readonly Selector`
|
|
24
|
+
case `readonly_selector_family`:
|
|
25
|
+
return `Readonly Selector Family`
|
|
26
|
+
case `selector_family`:
|
|
27
|
+
return `Selector Family`
|
|
28
|
+
default:
|
|
29
|
+
return capitalize(token.type)
|
|
21
30
|
}
|
|
22
|
-
return capitalize(token.type)
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export class NotFoundError extends Error {
|
|
@@ -19,9 +19,9 @@ export const createReadonlySelector = <T>(
|
|
|
19
19
|
const target = newest(store)
|
|
20
20
|
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
21
21
|
|
|
22
|
-
const { get, find } = registerSelector(options.key, target)
|
|
22
|
+
const { get, find, seek } = registerSelector(options.key, target)
|
|
23
23
|
const getSelf = () => {
|
|
24
|
-
const value = options.get({ get, find })
|
|
24
|
+
const value = options.get({ get, find, seek })
|
|
25
25
|
cacheValue(options.key, value, subject, newest(store))
|
|
26
26
|
return value
|
|
27
27
|
}
|
|
@@ -22,8 +22,8 @@ export const createWritableSelector = <T>(
|
|
|
22
22
|
const target = newest(store)
|
|
23
23
|
const subject = new Subject<{ newValue: T; oldValue: T }>()
|
|
24
24
|
const transactors = registerSelector(options.key, target)
|
|
25
|
-
const { find, get } = transactors
|
|
26
|
-
const readonlyTransactors = { find, get }
|
|
25
|
+
const { find, get, seek } = transactors
|
|
26
|
+
const readonlyTransactors = { find, get, seek }
|
|
27
27
|
|
|
28
28
|
const getSelf = () => {
|
|
29
29
|
const value = options.get(readonlyTransactors)
|
|
@@ -9,30 +9,47 @@ export function disposeSelector(
|
|
|
9
9
|
): void {
|
|
10
10
|
const target = newest(store)
|
|
11
11
|
const { key } = selectorToken
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
([downstreamSelectorKey]) =>
|
|
27
|
-
target.selectors.get(downstreamSelectorKey) ??
|
|
28
|
-
target.readonlySelectors.get(downstreamSelectorKey),
|
|
12
|
+
const selector = target.selectors.get(key) ?? target.readonlySelectors.get(key)
|
|
13
|
+
if (!selector) {
|
|
14
|
+
store.logger.error(
|
|
15
|
+
`❌`,
|
|
16
|
+
`selector`,
|
|
17
|
+
key,
|
|
18
|
+
`Tried to dispose selector, but it does not exist in the store.`,
|
|
19
|
+
)
|
|
20
|
+
} else if (!selector.family) {
|
|
21
|
+
store.logger.error(
|
|
22
|
+
`❌`,
|
|
23
|
+
`selector`,
|
|
24
|
+
key,
|
|
25
|
+
`Standalone selectors cannot be disposed.`,
|
|
29
26
|
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
} else {
|
|
28
|
+
switch (selectorToken.type) {
|
|
29
|
+
case `selector`:
|
|
30
|
+
target.selectors.delete(key)
|
|
31
|
+
break
|
|
32
|
+
case `readonly_selector`:
|
|
33
|
+
target.readonlySelectors.delete(key)
|
|
34
|
+
break
|
|
35
|
+
}
|
|
36
|
+
target.valueMap.delete(key)
|
|
37
|
+
target.selectorAtoms.delete(key)
|
|
38
|
+
const downstreamTokens = target.selectorGraph
|
|
39
|
+
.getRelationEntries({ upstreamSelectorKey: key })
|
|
40
|
+
.filter(([_, { source }]) => source === key)
|
|
41
|
+
.map(
|
|
42
|
+
([downstreamSelectorKey]) =>
|
|
43
|
+
target.selectors.get(downstreamSelectorKey) ??
|
|
44
|
+
target.readonlySelectors.get(downstreamSelectorKey),
|
|
45
|
+
)
|
|
46
|
+
for (const downstreamToken of downstreamTokens) {
|
|
47
|
+
if (downstreamToken) {
|
|
48
|
+
disposeSelector(downstreamToken, store)
|
|
49
|
+
}
|
|
33
50
|
}
|
|
51
|
+
target.selectorGraph.delete(key)
|
|
52
|
+
store.logger.info(`🔥`, selectorToken.type, key, `deleted`)
|
|
53
|
+
store.on.selectorDisposal.next(selectorToken)
|
|
34
54
|
}
|
|
35
|
-
target.selectorGraph.delete(key)
|
|
36
|
-
store.logger.info(`🔥`, selectorToken.type, key, `deleted`)
|
|
37
|
-
store.on.selectorDisposal.next(selectorToken)
|
|
38
55
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Transactors } from "atom.io"
|
|
2
|
+
import type { findState } from "atom.io/ephemeral"
|
|
3
|
+
import type { seekState } from "atom.io/immortal"
|
|
2
4
|
|
|
3
|
-
import { findInStore } from "../families"
|
|
5
|
+
import { findInStore, seekInStore } from "../families"
|
|
4
6
|
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
5
7
|
import { newest } from "../lineage"
|
|
6
8
|
import { setAtomOrSelector } from "../set-state"
|
|
7
9
|
import type { Store } from "../store"
|
|
8
|
-
import {
|
|
10
|
+
import { withdraw } from "../store"
|
|
9
11
|
import { updateSelectorAtoms } from "./update-selector-atoms"
|
|
10
12
|
|
|
11
13
|
export const registerSelector = (
|
|
@@ -15,7 +17,7 @@ export const registerSelector = (
|
|
|
15
17
|
get: (dependency) => {
|
|
16
18
|
const target = newest(store)
|
|
17
19
|
|
|
18
|
-
const dependencyState =
|
|
20
|
+
const dependencyState = withdraw(dependency, store)
|
|
19
21
|
const dependencyValue = readOrComputeValue(dependencyState, store)
|
|
20
22
|
|
|
21
23
|
store.logger.info(
|
|
@@ -40,8 +42,9 @@ export const registerSelector = (
|
|
|
40
42
|
return dependencyValue
|
|
41
43
|
},
|
|
42
44
|
set: (WritableToken, newValue) => {
|
|
43
|
-
const state =
|
|
45
|
+
const state = withdraw(WritableToken, store)
|
|
44
46
|
setAtomOrSelector(state, newValue, store)
|
|
45
47
|
},
|
|
46
48
|
find: ((token, key) => findInStore(token, key, store)) as typeof findState,
|
|
49
|
+
seek: ((token, key) => seekInStore(token, key, store)) as typeof seekState,
|
|
47
50
|
})
|
|
@@ -2,7 +2,7 @@ import type { WritableToken } from "atom.io"
|
|
|
2
2
|
|
|
3
3
|
import { closeOperation, openOperation } from "../operation"
|
|
4
4
|
import type { Store } from "../store"
|
|
5
|
-
import {
|
|
5
|
+
import { withdraw } from "../store"
|
|
6
6
|
import { setAtomOrSelector } from "./set-atom-or-selector"
|
|
7
7
|
|
|
8
8
|
export function setIntoStore<T, New extends T>(
|
|
@@ -27,7 +27,7 @@ export function setIntoStore<T, New extends T>(
|
|
|
27
27
|
)
|
|
28
28
|
return
|
|
29
29
|
}
|
|
30
|
-
const state =
|
|
30
|
+
const state = withdraw(token, store)
|
|
31
31
|
setAtomOrSelector(state, value, store)
|
|
32
32
|
closeOperation(store)
|
|
33
33
|
}
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
WritableSelectorToken,
|
|
13
13
|
} from "atom.io"
|
|
14
14
|
import { AtomIOLogger } from "atom.io"
|
|
15
|
+
import type { Molecule } from "atom.io/immortal"
|
|
15
16
|
|
|
16
17
|
import { Junction } from "~/packages/rel8/junction/src"
|
|
17
18
|
|
|
@@ -80,6 +81,9 @@ export class Store implements Lineage {
|
|
|
80
81
|
},
|
|
81
82
|
)
|
|
82
83
|
|
|
84
|
+
public molecules = new Map<string, Molecule<any>>()
|
|
85
|
+
public miscResources = new Map<string, Disposable>()
|
|
86
|
+
|
|
83
87
|
public on = {
|
|
84
88
|
atomCreation: new Subject<AtomToken<unknown>>(),
|
|
85
89
|
atomDisposal: new Subject<AtomToken<unknown>>(),
|
|
@@ -107,8 +111,10 @@ export class Store implements Lineage {
|
|
|
107
111
|
|
|
108
112
|
public config: {
|
|
109
113
|
name: string
|
|
114
|
+
lifespan: `ephemeral` | `immortal`
|
|
110
115
|
} = {
|
|
111
116
|
name: `IMPLICIT_STORE`,
|
|
117
|
+
lifespan: `ephemeral`,
|
|
112
118
|
}
|
|
113
119
|
|
|
114
120
|
public loggers: AtomIOLogger[] = [
|
|
@@ -126,7 +132,7 @@ export class Store implements Lineage {
|
|
|
126
132
|
},
|
|
127
133
|
}
|
|
128
134
|
|
|
129
|
-
public constructor(
|
|
135
|
+
public constructor(config: Store[`config`], store: Store | null = null) {
|
|
130
136
|
if (store !== null) {
|
|
131
137
|
this.valueMap = new Map(store?.valueMap)
|
|
132
138
|
this.operation = { ...store?.operation }
|
|
@@ -141,7 +147,7 @@ export class Store implements Lineage {
|
|
|
141
147
|
|
|
142
148
|
this.config = {
|
|
143
149
|
...store?.config,
|
|
144
|
-
|
|
150
|
+
...config,
|
|
145
151
|
}
|
|
146
152
|
for (const [, family] of store.families) {
|
|
147
153
|
family.install(this)
|
|
@@ -153,7 +159,7 @@ export class Store implements Lineage {
|
|
|
153
159
|
}
|
|
154
160
|
atom.install(this)
|
|
155
161
|
if (atom.type === `mutable_atom`) {
|
|
156
|
-
const originalJsonToken = getJsonToken(atom)
|
|
162
|
+
const originalJsonToken = getJsonToken(atom, store)
|
|
157
163
|
const originalUpdateToken = getUpdateToken(atom)
|
|
158
164
|
mutableHelpers.add(originalJsonToken.key)
|
|
159
165
|
mutableHelpers.add(originalUpdateToken.key)
|
|
@@ -182,13 +188,20 @@ export const IMPLICIT = {
|
|
|
182
188
|
STORE_INTERNAL: undefined as Store | undefined,
|
|
183
189
|
get STORE(): Store {
|
|
184
190
|
return (
|
|
185
|
-
this.STORE_INTERNAL ??
|
|
191
|
+
this.STORE_INTERNAL ??
|
|
192
|
+
(this.STORE_INTERNAL = new Store({
|
|
193
|
+
name: `IMPLICIT_STORE`,
|
|
194
|
+
lifespan: `ephemeral`,
|
|
195
|
+
}))
|
|
186
196
|
)
|
|
187
197
|
},
|
|
188
198
|
}
|
|
189
199
|
|
|
190
200
|
export const clearStore = (store: Store): void => {
|
|
191
201
|
const { config } = store
|
|
192
|
-
|
|
202
|
+
for (const disposable of store.miscResources.values()) {
|
|
203
|
+
disposable[Symbol.dispose]()
|
|
204
|
+
}
|
|
205
|
+
Object.assign(store, new Store(config))
|
|
193
206
|
store.config = config
|
|
194
207
|
}
|
|
@@ -4,8 +4,8 @@ import type { Store } from "../store"
|
|
|
4
4
|
|
|
5
5
|
export const recallState = <T>(state: ReadableState<T>, store: Store): T => {
|
|
6
6
|
const target = newest(store)
|
|
7
|
-
if (
|
|
8
|
-
return target.
|
|
7
|
+
if (target.operation.open) {
|
|
8
|
+
return target.operation.prev.get(state.key)
|
|
9
9
|
}
|
|
10
|
-
return target.
|
|
10
|
+
return target.valueMap.get(state.key)
|
|
11
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ReadableToken, UpdateHandler } from "atom.io"
|
|
1
|
+
import type { ReadableToken, StateUpdate, UpdateHandler } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import type { Store } from "../store"
|
|
4
|
-
import {
|
|
4
|
+
import { withdraw } from "../store"
|
|
5
5
|
import { subscribeToRootAtoms } from "./subscribe-to-root-atoms"
|
|
6
6
|
|
|
7
7
|
export function subscribeToState<T>(
|
|
@@ -10,12 +10,25 @@ export function subscribeToState<T>(
|
|
|
10
10
|
key: string,
|
|
11
11
|
store: Store,
|
|
12
12
|
): () => void {
|
|
13
|
-
|
|
13
|
+
function safelyHandleUpdate(update: StateUpdate<any>): void {
|
|
14
|
+
if (store.operation.open) {
|
|
15
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
16
|
+
`state subscription ${key}`,
|
|
17
|
+
() => {
|
|
18
|
+
unsubscribe()
|
|
19
|
+
handleUpdate(update)
|
|
20
|
+
},
|
|
21
|
+
)
|
|
22
|
+
} else {
|
|
23
|
+
handleUpdate(update)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const state = withdraw(token, store)
|
|
14
27
|
store.logger.info(`👀`, state.type, state.key, `Adding subscription "${key}"`)
|
|
15
28
|
const isSelector =
|
|
16
29
|
state.type === `selector` || state.type === `readonly_selector`
|
|
17
30
|
let dependencyUnsubFunctions: (() => void)[] | null = null
|
|
18
|
-
let updateHandler: UpdateHandler<T> =
|
|
31
|
+
let updateHandler: UpdateHandler<T> = safelyHandleUpdate
|
|
19
32
|
if (isSelector) {
|
|
20
33
|
dependencyUnsubFunctions = subscribeToRootAtoms(state, store)
|
|
21
34
|
updateHandler = (update) => {
|
|
@@ -23,7 +36,7 @@ export function subscribeToState<T>(
|
|
|
23
36
|
dependencyUnsubFunctions.length = 0
|
|
24
37
|
dependencyUnsubFunctions.push(...subscribeToRootAtoms(state, store))
|
|
25
38
|
}
|
|
26
|
-
|
|
39
|
+
safelyHandleUpdate(update)
|
|
27
40
|
}
|
|
28
41
|
}
|
|
29
42
|
const mainUnsubFunction = state.subject.subscribe(key, updateHandler)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Func } from "atom.io"
|
|
2
|
+
import type { findState } from "atom.io/ephemeral"
|
|
3
|
+
import type { seekState } from "atom.io/immortal"
|
|
2
4
|
|
|
3
5
|
import { Junction } from "~/packages/rel8/junction/src"
|
|
4
6
|
|
|
5
7
|
import { arbitrary } from "../arbitrary"
|
|
6
|
-
import { findInStore } from "../families"
|
|
8
|
+
import { findInStore, seekInStore } from "../families"
|
|
7
9
|
import { getEnvironmentData } from "../get-environment-data"
|
|
8
10
|
import { getFromStore } from "../get-state"
|
|
9
11
|
import { LazyMap } from "../lazy-map"
|
|
@@ -43,6 +45,8 @@ export const buildTransaction = (
|
|
|
43
45
|
}),
|
|
44
46
|
selectors: new LazyMap(parent.selectors),
|
|
45
47
|
valueMap: new LazyMap(parent.valueMap),
|
|
48
|
+
molecules: new LazyMap(parent.molecules),
|
|
49
|
+
miscResources: new LazyMap(parent.miscResources),
|
|
46
50
|
}
|
|
47
51
|
const epoch = getEpochNumberOfAction(key, store)
|
|
48
52
|
const transactionMeta: TransactionProgress<Func> = {
|
|
@@ -63,6 +67,7 @@ export const buildTransaction = (
|
|
|
63
67
|
run: (token, identifier = arbitrary()) =>
|
|
64
68
|
actUponStore(token, identifier, child),
|
|
65
69
|
find: ((token, k) => findInStore(token, k, child)) as typeof findState,
|
|
70
|
+
seek: ((token, k) => seekInStore(token, k, child)) as typeof seekState,
|
|
66
71
|
env: () => getEnvironmentData(child),
|
|
67
72
|
},
|
|
68
73
|
}
|
|
@@ -66,55 +66,45 @@ var attachAtomIndex = (store = Internal2.IMPLICIT.STORE) => {
|
|
|
66
66
|
},
|
|
67
67
|
effects: [
|
|
68
68
|
({ setSelf }) => {
|
|
69
|
-
|
|
70
|
-
`
|
|
71
|
-
|
|
72
|
-
if (atomToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
setSelf((self) => {
|
|
76
|
-
if (atomToken.family) {
|
|
77
|
-
const { key: familyKey, subKey } = atomToken.family;
|
|
78
|
-
let familyNode = self.get(familyKey);
|
|
79
|
-
if (familyNode === void 0 || !(`familyMembers` in familyNode)) {
|
|
80
|
-
familyNode = {
|
|
81
|
-
key: familyKey,
|
|
82
|
-
familyMembers: /* @__PURE__ */ new Map()
|
|
83
|
-
};
|
|
84
|
-
self.set(familyKey, familyNode);
|
|
85
|
-
}
|
|
86
|
-
familyNode.familyMembers.set(subKey, atomToken);
|
|
87
|
-
} else {
|
|
88
|
-
self.set(atomToken.key, atomToken);
|
|
89
|
-
}
|
|
90
|
-
return self;
|
|
91
|
-
});
|
|
69
|
+
store.on.atomCreation.subscribe(`introspection`, (atomToken) => {
|
|
70
|
+
if (atomToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
|
|
71
|
+
return;
|
|
92
72
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
73
|
+
setSelf((self) => {
|
|
74
|
+
if (atomToken.family) {
|
|
75
|
+
const { key: familyKey, subKey } = atomToken.family;
|
|
76
|
+
let familyNode = self.get(familyKey);
|
|
77
|
+
if (familyNode === void 0 || !(`familyMembers` in familyNode)) {
|
|
78
|
+
familyNode = {
|
|
79
|
+
key: familyKey,
|
|
80
|
+
familyMembers: /* @__PURE__ */ new Map()
|
|
81
|
+
};
|
|
82
|
+
self.set(familyKey, familyNode);
|
|
83
|
+
}
|
|
84
|
+
familyNode.familyMembers.set(subKey, atomToken);
|
|
85
|
+
} else {
|
|
86
|
+
self.set(atomToken.key, atomToken);
|
|
87
|
+
}
|
|
88
|
+
return self;
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
store.on.atomDisposal.subscribe(`introspection`, (atomToken) => {
|
|
92
|
+
setSelf((self) => {
|
|
93
|
+
if (atomToken.family) {
|
|
94
|
+
const { key: familyKey, subKey } = atomToken.family;
|
|
95
|
+
const familyNode = self.get(familyKey);
|
|
96
|
+
if (familyNode && `familyMembers` in familyNode) {
|
|
97
|
+
familyNode.familyMembers.delete(subKey);
|
|
98
|
+
if (familyNode.familyMembers.size === 0) {
|
|
99
|
+
self.delete(familyKey);
|
|
106
100
|
}
|
|
107
|
-
} else {
|
|
108
|
-
self.delete(atomToken.key);
|
|
109
101
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
unsubscribeFromAtomDisposal();
|
|
117
|
-
};
|
|
102
|
+
} else {
|
|
103
|
+
self.delete(atomToken.key);
|
|
104
|
+
}
|
|
105
|
+
return self;
|
|
106
|
+
});
|
|
107
|
+
});
|
|
118
108
|
}
|
|
119
109
|
]
|
|
120
110
|
},
|
|
@@ -159,7 +149,7 @@ var attachSelectorIndex = (store = Internal2.IMPLICIT.STORE) => {
|
|
|
159
149
|
},
|
|
160
150
|
effects: [
|
|
161
151
|
({ setSelf }) => {
|
|
162
|
-
|
|
152
|
+
store.on.selectorCreation.subscribe(
|
|
163
153
|
`introspection`,
|
|
164
154
|
(selectorToken) => {
|
|
165
155
|
if (selectorToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
|
|
@@ -184,7 +174,7 @@ var attachSelectorIndex = (store = Internal2.IMPLICIT.STORE) => {
|
|
|
184
174
|
});
|
|
185
175
|
}
|
|
186
176
|
);
|
|
187
|
-
|
|
177
|
+
store.on.selectorDisposal.subscribe(
|
|
188
178
|
`introspection`,
|
|
189
179
|
(selectorToken) => {
|
|
190
180
|
setSelf((self) => {
|
|
@@ -204,10 +194,6 @@ var attachSelectorIndex = (store = Internal2.IMPLICIT.STORE) => {
|
|
|
204
194
|
});
|
|
205
195
|
}
|
|
206
196
|
);
|
|
207
|
-
return () => {
|
|
208
|
-
unsubscribeFromSelectorCreation();
|
|
209
|
-
unsubscribeFromSelectorDisposal();
|
|
210
|
-
};
|
|
211
197
|
}
|
|
212
198
|
]
|
|
213
199
|
},
|
|
@@ -245,19 +231,7 @@ var attachTimelineFamily = (store = Internal2.IMPLICIT.STORE) => {
|
|
|
245
231
|
({ setSelf }) => {
|
|
246
232
|
const tl = store.timelines.get(key);
|
|
247
233
|
tl == null ? void 0 : tl.subject.subscribe(`introspection`, (_) => {
|
|
248
|
-
|
|
249
|
-
const unsubscribe = store.on.operationClose.subscribe(
|
|
250
|
-
`introspection`,
|
|
251
|
-
(operationClose) => {
|
|
252
|
-
if (operationClose.open === false) {
|
|
253
|
-
unsubscribe();
|
|
254
|
-
setSelf(__spreadValues({}, tl));
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
);
|
|
258
|
-
} else {
|
|
259
|
-
setSelf(__spreadValues({}, tl));
|
|
260
|
-
}
|
|
234
|
+
setSelf(__spreadValues({}, tl));
|
|
261
235
|
});
|
|
262
236
|
}
|
|
263
237
|
]
|