@livestore/livestore 0.0.21 → 0.0.23
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 +14 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/__tests__/react/fixture.d.ts.map +1 -1
- package/dist/__tests__/react/fixture.js +0 -2
- package/dist/__tests__/react/fixture.js.map +1 -1
- package/dist/__tests__/react/useQuery.test.js +1 -1
- package/dist/__tests__/react/useQuery.test.js.map +1 -1
- package/dist/__tests__/react/utils/stack-info.test.d.ts +2 -0
- package/dist/__tests__/react/utils/stack-info.test.d.ts.map +1 -0
- package/dist/__tests__/react/utils/stack-info.test.js +43 -0
- package/dist/__tests__/react/utils/stack-info.test.js.map +1 -0
- package/dist/__tests__/reactive.test.js +13 -1
- package/dist/__tests__/reactive.test.js.map +1 -1
- package/dist/__tests__/reactiveQueries/sql.test.js +3 -3
- package/dist/__tests__/reactiveQueries/sql.test.js.map +1 -1
- package/dist/inMemoryDatabase.d.ts +2 -1
- package/dist/inMemoryDatabase.d.ts.map +1 -1
- package/dist/inMemoryDatabase.js +3 -2
- package/dist/inMemoryDatabase.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/useComponentState.d.ts.map +1 -1
- package/dist/react/useComponentState.js +19 -27
- package/dist/react/useComponentState.js.map +1 -1
- package/dist/react/useQuery.d.ts.map +1 -1
- package/dist/react/useQuery.js +46 -26
- package/dist/react/useQuery.js.map +1 -1
- package/dist/react/useTemporaryQuery.d.ts.map +1 -1
- package/dist/react/useTemporaryQuery.js +2 -0
- package/dist/react/useTemporaryQuery.js.map +1 -1
- package/dist/react/utils/stack-info.d.ts +11 -0
- package/dist/react/utils/stack-info.d.ts.map +1 -0
- package/dist/react/utils/stack-info.js +49 -0
- package/dist/react/utils/stack-info.js.map +1 -0
- package/dist/reactive.d.ts +33 -43
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +66 -255
- package/dist/reactive.js.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +15 -13
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js +5 -8
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/graphql.d.ts +4 -3
- package/dist/reactiveQueries/graphql.d.ts.map +1 -1
- package/dist/reactiveQueries/graphql.js +29 -34
- package/dist/reactiveQueries/graphql.js.map +1 -1
- package/dist/reactiveQueries/js.d.ts +2 -1
- package/dist/reactiveQueries/js.d.ts.map +1 -1
- package/dist/reactiveQueries/js.js +8 -9
- package/dist/reactiveQueries/js.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +11 -5
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +31 -34
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/store.d.ts +26 -12
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +41 -255
- package/dist/store.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/react/fixture.tsx +0 -3
- package/src/__tests__/react/useQuery.test.tsx +1 -1
- package/src/__tests__/react/utils/{extractStackInfoFromStackTrace.test.ts → stack-info.test.ts} +25 -20
- package/src/__tests__/reactive.test.ts +20 -1
- package/src/__tests__/reactiveQueries/sql.test.ts +3 -3
- package/src/inMemoryDatabase.ts +9 -6
- package/src/react/index.ts +1 -0
- package/src/react/useComponentState.ts +25 -30
- package/src/react/useQuery.ts +66 -34
- package/src/react/useTemporaryQuery.ts +2 -0
- package/src/react/utils/{extractStackInfoFromStackTrace.ts → stack-info.ts} +21 -5
- package/src/reactive.ts +148 -339
- package/src/reactiveQueries/base-class.ts +23 -22
- package/src/reactiveQueries/graphql.ts +34 -36
- package/src/reactiveQueries/js.ts +14 -10
- package/src/reactiveQueries/sql.ts +55 -48
- package/src/store.ts +70 -305
package/dist/reactive.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// This is a simple implementation of a reactive dependency graph.
|
|
2
|
-
import { pick
|
|
3
|
-
import { isEqual,
|
|
2
|
+
import { pick } from '@livestore/utils';
|
|
3
|
+
import { isEqual, uniqueId } from 'lodash-es';
|
|
4
4
|
import { BoundArray } from './bounded-collections.js';
|
|
5
5
|
// import { getDurationMsFromSpan } from './otel.js'
|
|
6
6
|
export const NOT_REFRESHED_YET = Symbol.for('NOT_REFRESHED_YET');
|
|
@@ -11,7 +11,7 @@ export const unknownRefreshReason = () => {
|
|
|
11
11
|
const uniqueNodeId = () => uniqueId('node-');
|
|
12
12
|
const uniqueRefreshInfoId = () => uniqueId('refresh-info-');
|
|
13
13
|
const serializeAtom = (atom) => ({
|
|
14
|
-
...pick(atom, ['_tag', '
|
|
14
|
+
...pick(atom, ['_tag', 'id', 'label', 'meta']),
|
|
15
15
|
sub: Array.from(atom.sub).map((a) => a.id),
|
|
16
16
|
super: Array.from(atom.super).map((a) => a.id),
|
|
17
17
|
});
|
|
@@ -20,6 +20,27 @@ export class ReactiveGraph {
|
|
|
20
20
|
constructor(options) {
|
|
21
21
|
this.atoms = new Set();
|
|
22
22
|
this.debugRefreshInfos = new BoundArray(5000);
|
|
23
|
+
this.runEffects = (effectsToRefresh, options) => {
|
|
24
|
+
this.effectsWrapper(() => {
|
|
25
|
+
this.currentDebugRefresh = { refreshedAtoms: [], startMs: performance.now() };
|
|
26
|
+
for (const effect of effectsToRefresh) {
|
|
27
|
+
effect.doEffect(options?.otelContext);
|
|
28
|
+
}
|
|
29
|
+
const refreshedAtoms = this.currentDebugRefresh.refreshedAtoms;
|
|
30
|
+
const durationMs = performance.now() - this.currentDebugRefresh.startMs;
|
|
31
|
+
this.currentDebugRefresh = undefined;
|
|
32
|
+
const refreshDebugInfo = {
|
|
33
|
+
id: uniqueRefreshInfoId(),
|
|
34
|
+
reason: options?.debugRefreshReason ?? unknownRefreshReason(),
|
|
35
|
+
skippedRefresh: false,
|
|
36
|
+
refreshedAtoms,
|
|
37
|
+
durationMs,
|
|
38
|
+
completedTimestamp: Date.now(),
|
|
39
|
+
graphSnapshot: this.getSnapshot(),
|
|
40
|
+
};
|
|
41
|
+
this.debugRefreshInfos.push(refreshDebugInfo);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
23
44
|
this.getSnapshot = () => ({
|
|
24
45
|
atoms: Array.from(this.atoms).map(serializeAtom),
|
|
25
46
|
// effects: Array.from(this.effects).map(serializeEffect),
|
|
@@ -33,7 +54,6 @@ export class ReactiveGraph {
|
|
|
33
54
|
id: uniqueNodeId(),
|
|
34
55
|
isDirty: false,
|
|
35
56
|
previousResult: val,
|
|
36
|
-
height: 0,
|
|
37
57
|
computeResult: () => ref.previousResult,
|
|
38
58
|
sub: new Set(),
|
|
39
59
|
super: new Set(),
|
|
@@ -44,53 +64,54 @@ export class ReactiveGraph {
|
|
|
44
64
|
this.atoms.add(ref);
|
|
45
65
|
return ref;
|
|
46
66
|
}
|
|
47
|
-
makeThunk(
|
|
48
|
-
// const computeResult = (): T => {
|
|
49
|
-
// const getAtom = (atom: Atom<T, any>): T => {
|
|
50
|
-
// const __getResult = atom._tag === 'thunk' ? atom.__getResult.toString() : ''
|
|
51
|
-
// if (atom.isDirty) {
|
|
52
|
-
// console.log('atom is dirty', atom.id, atom.label ?? '', atom._tag, __getResult)
|
|
53
|
-
// const result = atom.computeResult()
|
|
54
|
-
// atom.isDirty = false
|
|
55
|
-
// atom.previousResult = result
|
|
56
|
-
// return result
|
|
57
|
-
// } else {
|
|
58
|
-
// console.log('atom is clean', atom.id, atom.label ?? '', atom._tag, __getResult)
|
|
59
|
-
// return atom.previousResult as T
|
|
60
|
-
// }
|
|
61
|
-
// }
|
|
62
|
-
// let resultChanged = false
|
|
63
|
-
// const debugInfoForAtom = {
|
|
64
|
-
// atom: serializeAtom(null as TODO),
|
|
65
|
-
// resultChanged,
|
|
66
|
-
// // debugInfo: unknownRefreshReason() as TDebugThunkInfo,
|
|
67
|
-
// debugInfo: { _tag: 'unknown' } as TDebugThunkInfo,
|
|
68
|
-
// durationMs: 0,
|
|
69
|
-
// } satisfies AtomDebugInfo<TDebugThunkInfo>
|
|
70
|
-
const addDebugInfo = (_debugInfo) => {
|
|
71
|
-
// debugInfoForAtom.debugInfo = debugInfo
|
|
72
|
-
};
|
|
73
|
-
// debugInfoForRefreshedAtoms.push(debugInfoForAtom)
|
|
74
|
-
// return getResult_(getAtom as GetAtom, addDebugInfo, this.context!)
|
|
75
|
-
// }
|
|
67
|
+
makeThunk(getResult, options) {
|
|
76
68
|
const thunk = {
|
|
77
69
|
_tag: 'thunk',
|
|
78
70
|
id: uniqueNodeId(),
|
|
79
71
|
previousResult: NOT_REFRESHED_YET,
|
|
80
72
|
isDirty: true,
|
|
81
|
-
|
|
82
|
-
computeResult: (otelContext) => {
|
|
73
|
+
computeResult: (otelContext, debugRefreshReason) => {
|
|
83
74
|
if (thunk.isDirty) {
|
|
75
|
+
const neededCurrentRefresh = this.currentDebugRefresh === undefined;
|
|
76
|
+
if (neededCurrentRefresh) {
|
|
77
|
+
this.currentDebugRefresh = { refreshedAtoms: [], startMs: performance.now() };
|
|
78
|
+
}
|
|
84
79
|
// Reset previous subcomputations as we're about to re-add them as part of the `doEffect` call below
|
|
85
80
|
thunk.sub = new Set();
|
|
86
|
-
const
|
|
81
|
+
const getAtom = (atom, otelContext) => {
|
|
87
82
|
this.addEdge(thunk, atom);
|
|
88
83
|
return compute(atom, otelContext);
|
|
89
84
|
};
|
|
90
|
-
|
|
85
|
+
let debugInfo = undefined;
|
|
86
|
+
const setDebugInfo = (debugInfo_) => {
|
|
87
|
+
debugInfo = debugInfo_;
|
|
88
|
+
};
|
|
89
|
+
const result = getResult(getAtom, setDebugInfo, this.context ?? throwContextNotSetError(), otelContext);
|
|
90
|
+
const resultChanged = thunk.equal(thunk.previousResult, result) === false;
|
|
91
|
+
const debugInfoForAtom = {
|
|
92
|
+
atom: serializeAtom(thunk),
|
|
93
|
+
resultChanged,
|
|
94
|
+
debugInfo: debugInfo ?? unknownRefreshReason(),
|
|
95
|
+
};
|
|
96
|
+
this.currentDebugRefresh.refreshedAtoms.push(debugInfoForAtom);
|
|
91
97
|
thunk.isDirty = false;
|
|
92
98
|
thunk.previousResult = result;
|
|
93
99
|
thunk.recomputations++;
|
|
100
|
+
if (neededCurrentRefresh) {
|
|
101
|
+
const refreshedAtoms = this.currentDebugRefresh.refreshedAtoms;
|
|
102
|
+
const durationMs = performance.now() - this.currentDebugRefresh.startMs;
|
|
103
|
+
this.currentDebugRefresh = undefined;
|
|
104
|
+
const refreshDebugInfo = {
|
|
105
|
+
id: uniqueRefreshInfoId(),
|
|
106
|
+
reason: debugRefreshReason ?? { _tag: 'makeThunk', label: options?.label },
|
|
107
|
+
skippedRefresh: false,
|
|
108
|
+
refreshedAtoms,
|
|
109
|
+
durationMs,
|
|
110
|
+
completedTimestamp: Date.now(),
|
|
111
|
+
graphSnapshot: this.getSnapshot(),
|
|
112
|
+
};
|
|
113
|
+
this.debugRefreshInfos.push(refreshDebugInfo);
|
|
114
|
+
}
|
|
94
115
|
return result;
|
|
95
116
|
}
|
|
96
117
|
else {
|
|
@@ -103,21 +124,9 @@ export class ReactiveGraph {
|
|
|
103
124
|
label: options?.label,
|
|
104
125
|
meta: options?.meta,
|
|
105
126
|
equal: options?.equal ?? isEqual,
|
|
106
|
-
__getResult:
|
|
127
|
+
__getResult: getResult,
|
|
107
128
|
};
|
|
108
129
|
this.atoms.add(thunk);
|
|
109
|
-
// this.dirtyNodes.add(thunk)
|
|
110
|
-
const debugRefreshReason = options?.debugRefreshReason ?? { _tag: 'makeThunk', label: options?.label };
|
|
111
|
-
const refreshDebugInfo = {
|
|
112
|
-
id: uniqueRefreshInfoId(),
|
|
113
|
-
reason: debugRefreshReason,
|
|
114
|
-
skippedRefresh: true,
|
|
115
|
-
refreshedAtoms: [],
|
|
116
|
-
durationMs: 0,
|
|
117
|
-
completedTimestamp: Date.now(),
|
|
118
|
-
graphSnapshot: this.getSnapshot(),
|
|
119
|
-
};
|
|
120
|
-
this.debugRefreshInfos.push(refreshDebugInfo);
|
|
121
130
|
return thunk;
|
|
122
131
|
}
|
|
123
132
|
destroy(node) {
|
|
@@ -140,6 +149,7 @@ export class ReactiveGraph {
|
|
|
140
149
|
_tag: 'effect',
|
|
141
150
|
id: uniqueNodeId(),
|
|
142
151
|
doEffect: (otelContext) => {
|
|
152
|
+
// NOTE we're not tracking any debug refresh info for effects as they're tracked by the thunks they depend on
|
|
143
153
|
// Reset previous subcomputations as we're about to re-add them as part of the `doEffect` call below
|
|
144
154
|
effect.sub = new Set();
|
|
145
155
|
const getAtom = (atom, otelContext) => {
|
|
@@ -149,233 +159,31 @@ export class ReactiveGraph {
|
|
|
149
159
|
doEffect(getAtom, otelContext);
|
|
150
160
|
},
|
|
151
161
|
sub: new Set(),
|
|
162
|
+
label: options?.label,
|
|
152
163
|
};
|
|
153
|
-
// this.effects.add(effect)
|
|
154
|
-
// this.dirtyNodes.add(effect)
|
|
155
|
-
const debugRefreshReason = options?.debugRefreshReason ?? { _tag: 'makeEffect', label: options?.label };
|
|
156
|
-
const refreshDebugInfo = {
|
|
157
|
-
id: uniqueRefreshInfoId(),
|
|
158
|
-
reason: debugRefreshReason ?? unknownRefreshReason(),
|
|
159
|
-
skippedRefresh: true,
|
|
160
|
-
refreshedAtoms: [],
|
|
161
|
-
durationMs: 0,
|
|
162
|
-
completedTimestamp: Date.now(),
|
|
163
|
-
graphSnapshot: this.getSnapshot(),
|
|
164
|
-
};
|
|
165
|
-
this.debugRefreshInfos.push(refreshDebugInfo);
|
|
166
164
|
return effect;
|
|
167
165
|
}
|
|
168
166
|
setRef(ref, val, options) {
|
|
169
|
-
const { debugRefreshReason } = options ?? {};
|
|
170
167
|
ref.previousResult = val;
|
|
171
168
|
const effectsToRefresh = new Set();
|
|
172
169
|
markSuperCompDirtyRec(ref, effectsToRefresh);
|
|
173
|
-
this.
|
|
174
|
-
for (const effect of effectsToRefresh) {
|
|
175
|
-
effect.doEffect(options?.otelContext);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
const refreshDebugInfo = {
|
|
179
|
-
id: uniqueRefreshInfoId(),
|
|
180
|
-
reason: debugRefreshReason ?? unknownRefreshReason(),
|
|
181
|
-
skippedRefresh: true,
|
|
182
|
-
refreshedAtoms: [],
|
|
183
|
-
durationMs: 0,
|
|
184
|
-
completedTimestamp: Date.now(),
|
|
185
|
-
graphSnapshot: this.getSnapshot(),
|
|
186
|
-
};
|
|
187
|
-
this.debugRefreshInfos.push(refreshDebugInfo);
|
|
170
|
+
this.runEffects(effectsToRefresh, options);
|
|
188
171
|
}
|
|
189
172
|
setRefs(refs, options) {
|
|
190
|
-
const debugRefreshReason = options?.debugRefreshReason;
|
|
191
173
|
const effectsToRefresh = new Set();
|
|
192
174
|
for (const [ref, val] of refs) {
|
|
193
175
|
ref.previousResult = val;
|
|
194
176
|
markSuperCompDirtyRec(ref, effectsToRefresh);
|
|
195
177
|
}
|
|
196
|
-
this.
|
|
197
|
-
for (const effect of effectsToRefresh) {
|
|
198
|
-
effect.doEffect(options?.otelContext);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
const refreshDebugInfo = {
|
|
202
|
-
id: uniqueRefreshInfoId(),
|
|
203
|
-
reason: debugRefreshReason ?? unknownRefreshReason(),
|
|
204
|
-
skippedRefresh: true,
|
|
205
|
-
refreshedAtoms: [],
|
|
206
|
-
durationMs: 0,
|
|
207
|
-
completedTimestamp: Date.now(),
|
|
208
|
-
graphSnapshot: this.getSnapshot(),
|
|
209
|
-
};
|
|
210
|
-
this.debugRefreshInfos.push(refreshDebugInfo);
|
|
211
|
-
}
|
|
212
|
-
// get<T>(atom: Atom<T, TContext>, context: Atom<any, TContext> | Effect): T {
|
|
213
|
-
// // Autotracking: if we're getting the value of an atom,
|
|
214
|
-
// // that means it's a subcomputation for the currently refreshing atom.
|
|
215
|
-
// this.addEdge(context, atom)
|
|
216
|
-
// const dependencyMightBeStale = context._tag !== 'effect' && context.height <= atom.height
|
|
217
|
-
// const dependencyNotRefreshedYet = atom.result === NOT_REFRESHED_YET
|
|
218
|
-
// if (dependencyMightBeStale || dependencyNotRefreshedYet) {
|
|
219
|
-
// throw new DependencyNotReadyError(
|
|
220
|
-
// `${this.label(context)} referenced dependency ${this.label(atom)} which isn't ready`,
|
|
221
|
-
// )
|
|
222
|
-
// }
|
|
223
|
-
// return atom.result
|
|
224
|
-
// }
|
|
225
|
-
/**
|
|
226
|
-
* Update the graph to be consistent with the current values of the root atoms.
|
|
227
|
-
* Generally we run this after a ref is updated.
|
|
228
|
-
* At the end of the refresh, we run any effects that were scheduled.
|
|
229
|
-
*
|
|
230
|
-
* @param roots Root atoms to start the refresh from
|
|
231
|
-
*/
|
|
232
|
-
// refresh(
|
|
233
|
-
// options?:
|
|
234
|
-
// | {
|
|
235
|
-
// otelHint?: string
|
|
236
|
-
// debugRefreshReason?: RefreshReasonWithGenericReasons<TDebugRefreshReason>
|
|
237
|
-
// }
|
|
238
|
-
// | undefined,
|
|
239
|
-
// otelContext: otel.Context = otel.context.active(),
|
|
240
|
-
// ): void {
|
|
241
|
-
// const otelHint = options?.otelHint ?? ''
|
|
242
|
-
// const debugRefreshReason = options?.debugRefreshReason
|
|
243
|
-
// const roots = [...this.dirtyNodes]
|
|
244
|
-
// const debugInfoForRefreshedAtoms: AtomDebugInfo<TDebugThunkInfo>[] = []
|
|
245
|
-
// // if (otelHint.includes('tableName')) {
|
|
246
|
-
// // console.log('refresh', otelHint, { shouldTrace })
|
|
247
|
-
// // }
|
|
248
|
-
// this.otelTracer.startActiveSpan(`LiveStore.refresh:${otelHint}`, {}, otelContext, (span) => {
|
|
249
|
-
// const atomsToRefresh = roots.filter(isAtom)
|
|
250
|
-
// const effectsToRun = new Set(roots.filter(isEffect))
|
|
251
|
-
// span.setAttribute('livestore.hint', otelHint)
|
|
252
|
-
// span.setAttribute('livestore.rootsCount', roots.length)
|
|
253
|
-
// // span.setAttribute('sstack', new Error().stack!)
|
|
254
|
-
// // Sort in topological order, starting with minimum height
|
|
255
|
-
// while (atomsToRefresh.length > 0) {
|
|
256
|
-
// atomsToRefresh.sort((a, b) => a.height - b.height)
|
|
257
|
-
// const atomToRefresh = atomsToRefresh.shift()!
|
|
258
|
-
// // Recompute the value
|
|
259
|
-
// let resultChanged = false
|
|
260
|
-
// const debugInfoForAtom = {
|
|
261
|
-
// atom: serializeAtom(atomToRefresh),
|
|
262
|
-
// resultChanged,
|
|
263
|
-
// // debugInfo: unknownRefreshReason() as TDebugThunkInfo,
|
|
264
|
-
// debugInfo: { _tag: 'unknown' } as TDebugThunkInfo,
|
|
265
|
-
// durationMs: 0,
|
|
266
|
-
// } satisfies AtomDebugInfo<TDebugThunkInfo>
|
|
267
|
-
// try {
|
|
268
|
-
// atomToRefresh.sub = new Set()
|
|
269
|
-
// const beforeTimestamp = performance.now()
|
|
270
|
-
// const newResult = atomToRefresh.getResult(
|
|
271
|
-
// (atom) => this.get(atom, atomToRefresh),
|
|
272
|
-
// (debugInfo) => {
|
|
273
|
-
// debugInfoForAtom.debugInfo = debugInfo
|
|
274
|
-
// },
|
|
275
|
-
// this.context ?? shouldNeverHappen(`No context provided yet for ReactiveGraph`),
|
|
276
|
-
// )
|
|
277
|
-
// const afterTimestamp = performance.now()
|
|
278
|
-
// debugInfoForAtom.durationMs = afterTimestamp - beforeTimestamp
|
|
279
|
-
// // Determine if the result changed to do early cutoff and avoid further unnecessary updates.
|
|
280
|
-
// // Refs never depend on anything, so if a ref is being refreshed it definitely changed.
|
|
281
|
-
// // For thunks, we use a deep equality check.
|
|
282
|
-
// resultChanged =
|
|
283
|
-
// atomToRefresh._tag === 'ref' ||
|
|
284
|
-
// (atomToRefresh._tag === 'thunk' && !atomToRefresh.equal(atomToRefresh.result, newResult))
|
|
285
|
-
// if (resultChanged) {
|
|
286
|
-
// atomToRefresh.result = newResult
|
|
287
|
-
// }
|
|
288
|
-
// this.dirtyNodes.delete(atomToRefresh)
|
|
289
|
-
// } catch (e) {
|
|
290
|
-
// if (e instanceof DependencyNotReadyError) {
|
|
291
|
-
// // If we hit a dependency that wasn't ready yet,
|
|
292
|
-
// // abort this recomputation and try again later.
|
|
293
|
-
// if (!atomsToRefresh.includes(atomToRefresh)) {
|
|
294
|
-
// atomsToRefresh.push(atomToRefresh)
|
|
295
|
-
// }
|
|
296
|
-
// } else {
|
|
297
|
-
// throw e
|
|
298
|
-
// }
|
|
299
|
-
// }
|
|
300
|
-
// debugInfoForRefreshedAtoms.push(debugInfoForAtom)
|
|
301
|
-
// if (!resultChanged) {
|
|
302
|
-
// continue
|
|
303
|
-
// }
|
|
304
|
-
// // Schedule supercomputations
|
|
305
|
-
// for (const superComp of atomToRefresh.super) {
|
|
306
|
-
// switch (superComp._tag) {
|
|
307
|
-
// case 'ref':
|
|
308
|
-
// case 'thunk': {
|
|
309
|
-
// if (!atomsToRefresh.includes(superComp)) {
|
|
310
|
-
// atomsToRefresh.push(superComp)
|
|
311
|
-
// }
|
|
312
|
-
// break
|
|
313
|
-
// }
|
|
314
|
-
// case 'effect': {
|
|
315
|
-
// effectsToRun.add(superComp)
|
|
316
|
-
// break
|
|
317
|
-
// }
|
|
318
|
-
// }
|
|
319
|
-
// }
|
|
320
|
-
// }
|
|
321
|
-
// this.effectsWrapper(() => {
|
|
322
|
-
// for (const effect of effectsToRun) {
|
|
323
|
-
// effect.doEffect((atom: Atom<any, TContext>) => this.get(atom, effect))
|
|
324
|
-
// this.dirtyNodes.delete(effect)
|
|
325
|
-
// }
|
|
326
|
-
// })
|
|
327
|
-
// span.end()
|
|
328
|
-
// const spanDurationMs = getDurationMsFromSpan(span)
|
|
329
|
-
// const refreshDebugInfo: RefreshDebugInfo<
|
|
330
|
-
// RefreshReasonWithGenericReasons<TDebugRefreshReason>,
|
|
331
|
-
// TDebugThunkInfo
|
|
332
|
-
// > = {
|
|
333
|
-
// id: uniqueRefreshInfoId(),
|
|
334
|
-
// reason: debugRefreshReason ?? unknownRefreshReason(),
|
|
335
|
-
// refreshedAtoms: debugInfoForRefreshedAtoms,
|
|
336
|
-
// skippedRefresh: false,
|
|
337
|
-
// durationMs: spanDurationMs,
|
|
338
|
-
// completedTimestamp: Date.now(),
|
|
339
|
-
// graphSnapshot: this.getSnapshot(),
|
|
340
|
-
// }
|
|
341
|
-
// this.debugRefreshInfos.push(refreshDebugInfo)
|
|
342
|
-
// })
|
|
343
|
-
// }
|
|
344
|
-
label(atom) {
|
|
345
|
-
if (atom._tag === 'effect') {
|
|
346
|
-
return `unknown effect`;
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
return atom.label ?? `unknown ${atom._tag}`;
|
|
350
|
-
}
|
|
178
|
+
this.runEffects(effectsToRefresh, options);
|
|
351
179
|
}
|
|
352
180
|
addEdge(superComp, subComp) {
|
|
353
181
|
superComp.sub.add(subComp);
|
|
354
182
|
subComp.super.add(superComp);
|
|
355
|
-
this.updateAtomHeight(superComp);
|
|
356
183
|
}
|
|
357
184
|
removeEdge(superComp, subComp) {
|
|
358
185
|
superComp.sub.delete(subComp);
|
|
359
186
|
subComp.super.delete(superComp);
|
|
360
|
-
this.updateAtomHeight(superComp);
|
|
361
|
-
}
|
|
362
|
-
updateAtomHeight(atom) {
|
|
363
|
-
switch (atom._tag) {
|
|
364
|
-
case 'ref': {
|
|
365
|
-
atom.height = 0;
|
|
366
|
-
break;
|
|
367
|
-
}
|
|
368
|
-
case 'thunk': {
|
|
369
|
-
atom.height = (max([...atom.sub].map((atom) => atom.height)) || 0) + 1;
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
case 'effect': {
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
get atomsCount() {
|
|
378
|
-
return this.atoms.size;
|
|
379
187
|
}
|
|
380
188
|
}
|
|
381
189
|
// const isAtom = <T, TContext>(a: Atom<T, TContext> | Effect): a is Atom<T, TContext> =>
|
|
@@ -406,4 +214,7 @@ const markSuperCompDirtyRec = (atom, effectsToRefresh) => {
|
|
|
406
214
|
}
|
|
407
215
|
}
|
|
408
216
|
};
|
|
217
|
+
const throwContextNotSetError = () => {
|
|
218
|
+
throw new Error(`LiveStore Error: \`context\` not set on ReactiveGraph`);
|
|
219
|
+
};
|
|
409
220
|
//# sourceMappingURL=reactive.js.map
|
package/dist/reactive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactive.js","sourceRoot":"","sources":["../src/reactive.ts"],"names":[],"mappings":"AAAA,kEAAkE;AA0BlE,OAAO,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"reactive.js","sourceRoot":"","sources":["../src/reactive.ts"],"names":[],"mappings":"AAAA,kEAAkE;AA0BlE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,oDAAoD;AAEpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AAyFhE,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,WAAW;IACX,OAAO,EAAE,IAAI,EAAE,SAAkB,EAAE,CAAA;AACrC,CAAC,CAAA;AAoBD,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;AAC5C,MAAM,mBAAmB,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAA;AAE3D,MAAM,aAAa,GAAG,CAAC,IAA6B,EAAkB,EAAE,CAAC,CAAC;IACxE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9C,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG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K,EAAE;YAC1D,SAAS,CAAC,OAAO,GAAG,IAAI,CAAA;YACxB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAA;SACnD;aAAM;YACL,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;SAChC;KACF;AACH,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,GAAU,EAAE;IAC1C,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAA;AAC1E,CAAC,CAAA"}
|
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import type * as otel from '@opentelemetry/api';
|
|
2
|
-
import type { StackInfo } from '../react/utils/
|
|
3
|
-
import type { Atom, GetAtom, Thunk } from '../reactive.js';
|
|
2
|
+
import type { StackInfo } from '../react/utils/stack-info.js';
|
|
3
|
+
import type { Atom, GetAtom, RefreshReasonWithGenericReasons, Thunk } from '../reactive.js';
|
|
4
|
+
import type { RefreshReason } from '../store.js';
|
|
4
5
|
import { type DbContext } from './graph.js';
|
|
5
6
|
import type { LiveStoreJSQuery } from './js.js';
|
|
6
7
|
export type UnsubscribeQuery = () => void;
|
|
7
8
|
export interface ILiveStoreQuery<TResult> {
|
|
8
9
|
id: number;
|
|
9
10
|
/** A reactive thunk representing the query results */
|
|
10
|
-
results$: Thunk<TResult, DbContext>;
|
|
11
|
+
results$: Thunk<TResult, DbContext, RefreshReason>;
|
|
11
12
|
label: string;
|
|
12
|
-
run: (otelContext?: otel.Context) => TResult;
|
|
13
|
+
run: (otelContext?: otel.Context, debugRefreshReason?: RefreshReasonWithGenericReasons<RefreshReason>) => TResult;
|
|
13
14
|
destroy(): void;
|
|
14
|
-
activeSubscriptions: Set<
|
|
15
|
+
activeSubscriptions: Set<StackInfo>;
|
|
15
16
|
}
|
|
16
|
-
export type SubscriberInfo = {
|
|
17
|
-
stack: StackInfo[];
|
|
18
|
-
};
|
|
19
17
|
export declare abstract class LiveStoreQueryBase<TResult> implements ILiveStoreQuery<TResult> {
|
|
20
18
|
id: number;
|
|
21
19
|
/** Human-readable label for the query for debugging */
|
|
22
20
|
abstract label: string;
|
|
23
|
-
abstract results$: Thunk<TResult, DbContext>;
|
|
24
|
-
activeSubscriptions: Set<
|
|
21
|
+
abstract results$: Thunk<TResult, DbContext, RefreshReason>;
|
|
22
|
+
activeSubscriptions: Set<StackInfo>;
|
|
25
23
|
get runs(): number;
|
|
26
24
|
abstract destroy: () => void;
|
|
27
|
-
run: (otelContext?: otel.Context) => TResult;
|
|
28
|
-
runAndDestroy: (otelContext?: otel.Context) => TResult;
|
|
25
|
+
run: (otelContext?: otel.Context, debugRefreshReason?: RefreshReasonWithGenericReasons<RefreshReason>) => TResult;
|
|
26
|
+
runAndDestroy: (otelContext?: otel.Context, debugRefreshReason?: RefreshReasonWithGenericReasons<RefreshReason>) => TResult;
|
|
27
|
+
subscribe: (onNewValue: (value: TResult) => void, onUnsubsubscribe?: () => void, options?: {
|
|
28
|
+
label?: string;
|
|
29
|
+
otelContext?: otel.Context;
|
|
30
|
+
} | undefined) => (() => void);
|
|
29
31
|
}
|
|
30
|
-
export type GetAtomResult = <T>(atom: Atom<T, any> | LiveStoreJSQuery<T>) => T;
|
|
32
|
+
export type GetAtomResult = <T>(atom: Atom<T, any, RefreshReason> | LiveStoreJSQuery<T>) => T;
|
|
31
33
|
export declare const makeGetAtomResult: (get: GetAtom, otelContext: otel.Context) => GetAtomResult;
|
|
32
34
|
//# sourceMappingURL=base-class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-class.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/base-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"base-class.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/base-class.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB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AAa,iBACG,KAAK,OAAO,uBACL,gCAAgC,aAAa,CAAC,KAClE,OAAO,CAIT;IAED,SAAS,uBACa,OAAO,KAAK,IAAI,qBACjB,MAAM,IAAI,YACnB;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,KAAK,OAAO,CAAA;KAAE,GAAG,SAAS,KACnE,CAAC,MAAM,IAAI,CAAC,CAAiF;CACjG;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAE7F,eAAO,MAAM,iBAAiB,QAAS,OAAO,eAAe,KAAK,OAAO,kBAOxE,CAAA"}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
+
import { dbGraph } from './graph.js';
|
|
1
2
|
let queryIdCounter = 0;
|
|
2
3
|
export class LiveStoreQueryBase {
|
|
3
4
|
constructor() {
|
|
4
5
|
this.id = queryIdCounter++;
|
|
5
6
|
this.activeSubscriptions = new Set();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// options?: { label?: string } | undefined,
|
|
10
|
-
// ): (() => void) => this.store.subscribe(this as any, onNewValue as any, onSubsubscribe, options)
|
|
11
|
-
this.run = (otelContext) => this.results$.computeResult(otelContext);
|
|
12
|
-
this.runAndDestroy = (otelContext) => {
|
|
13
|
-
const result = this.run(otelContext);
|
|
7
|
+
this.run = (otelContext, debugRefreshReason) => this.results$.computeResult(otelContext, debugRefreshReason);
|
|
8
|
+
this.runAndDestroy = (otelContext, debugRefreshReason) => {
|
|
9
|
+
const result = this.run(otelContext, debugRefreshReason);
|
|
14
10
|
this.destroy();
|
|
15
11
|
return result;
|
|
16
12
|
};
|
|
13
|
+
this.subscribe = (onNewValue, onUnsubsubscribe, options) => dbGraph.context.store.subscribe(this, onNewValue, onUnsubsubscribe, options);
|
|
17
14
|
}
|
|
18
15
|
get runs() {
|
|
19
16
|
return this.results$.recomputations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-class.js","sourceRoot":"","sources":["../../src/reactiveQueries/base-class.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-class.js","sourceRoot":"","sources":["../../src/reactiveQueries/base-class.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,OAAO,EAAE,MAAM,YAAY,CAAA;AAKpD,IAAI,cAAc,GAAG,CAAC,CAAA;AAiBtB,MAAM,OAAgB,kBAAkB;IAAxC;QACE,OAAE,GAAG,cAAc,EAAE,CAAA;QAOrB,wBAAmB,GAAmB,IAAI,GAAG,EAAE,CAAA;QAQ/C,QAAG,GAAG,CAAC,WAA0B,EAAE,kBAAmE,EAAW,EAAE,CACjH,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAA;QAE9D,kBAAa,GAAG,CACd,WAA0B,EAC1B,kBAAmE,EAC1D,EAAE;YACX,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAA;YACxD,IAAI,CAAC,OAAO,EAAE,CAAA;YACd,OAAO,MAAM,CAAA;QACf,CAAC,CAAA;QAED,cAAS,GAAG,CACV,UAAoC,EACpC,gBAA6B,EAC7B,OAAoE,EACtD,EAAE,CAAC,OAAO,CAAC,OAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAA;IAClG,CAAC;IAvBC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAA;IACrC,CAAC;CAqBF;AAID,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAY,EAAE,WAAyB,EAAE,EAAE;IAC3E,MAAM,OAAO,GAAkB,CAAC,IAAI,EAAE,EAAE;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK;YAAE,OAAO,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QAC/E,OAAO,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAA;IACxC,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -2,7 +2,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-
|
|
|
2
2
|
import * as otel from '@opentelemetry/api';
|
|
3
3
|
import * as graphql from 'graphql';
|
|
4
4
|
import type { Thunk } from '../reactive.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { BaseGraphQLContext, RefreshReason, Store } from '../store.js';
|
|
6
6
|
import { type GetAtomResult, LiveStoreQueryBase } from './base-class.js';
|
|
7
7
|
import { type DbContext } from './graph.js';
|
|
8
8
|
import { LiveStoreJSQuery } from './js.js';
|
|
@@ -14,8 +14,8 @@ export declare class LiveStoreGraphQLQuery<TResult extends Record<string, any>,
|
|
|
14
14
|
/** The abstract GraphQL query */
|
|
15
15
|
document: DocumentNode<TResult, TVariableValues>;
|
|
16
16
|
/** A reactive thunk representing the query results */
|
|
17
|
-
results$: Thunk<TResult, DbContext>;
|
|
18
|
-
variableValues$: Thunk<TVariableValues, DbContext>;
|
|
17
|
+
results$: Thunk<TResult, DbContext, RefreshReason>;
|
|
18
|
+
variableValues$: Thunk<TVariableValues, DbContext, RefreshReason>;
|
|
19
19
|
label: string;
|
|
20
20
|
constructor({ document, label, genVariableValues, }: {
|
|
21
21
|
document: DocumentNode<TResult, TVariableValues>;
|
|
@@ -36,6 +36,7 @@ export declare class LiveStoreGraphQLQuery<TResult extends Record<string, any>,
|
|
|
36
36
|
}) => {
|
|
37
37
|
result: TResult;
|
|
38
38
|
queriedTables: string[];
|
|
39
|
+
durationMs: number;
|
|
39
40
|
};
|
|
40
41
|
destroy: () => void;
|
|
41
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAE1F,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAE1F,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAGlC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EAAE,KAAK,aAAa,EAAE,kBAAkB,EAAqB,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,KAAK,SAAS,EAAW,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1C,eAAO,MAAM,YAAY,mLAEqB,aAAa;;yEAEW,CAAA;AAEtE,qBAAa,qBAAqB,CAChC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,eAAe,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3C,QAAQ,SAAS,kBAAkB,CACnC,SAAQ,kBAAkB,CAAC,OAAO,CAAC;IACnC,IAAI,EAAE,SAAS,CAAY;IAE3B,iCAAiC;IACjC,QAAQ,EAAE,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;IAEhD,sDAAsD;IACtD,QAAQ,EAAE,KAAK,CAAC,OAA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