@livestore/livestore 0.3.0-dev.5 → 0.3.0-dev.50
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/.tsbuildinfo +1 -1
- package/dist/QueryCache.d.ts.map +1 -1
- package/dist/SqliteDbWrapper.d.ts +60 -0
- package/dist/SqliteDbWrapper.d.ts.map +1 -0
- package/dist/{SynchronousDatabaseWrapper.js → SqliteDbWrapper.js} +69 -34
- package/dist/SqliteDbWrapper.js.map +1 -0
- package/dist/effect/LiveStore.d.ts +6 -34
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +10 -12
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/effect/mod.d.ts +3 -0
- package/dist/effect/mod.d.ts.map +1 -0
- package/dist/effect/mod.js +3 -0
- package/dist/effect/mod.js.map +1 -0
- package/dist/internal/mod.d.ts +3 -0
- package/dist/internal/mod.d.ts.map +1 -0
- package/dist/internal/mod.js +3 -0
- package/dist/internal/mod.js.map +1 -0
- package/dist/live-queries/base-class.d.ts +65 -27
- package/dist/live-queries/base-class.d.ts.map +1 -1
- package/dist/live-queries/base-class.js +54 -13
- package/dist/live-queries/base-class.js.map +1 -1
- package/dist/live-queries/client-document-get-query.d.ts +12 -0
- package/dist/live-queries/client-document-get-query.d.ts.map +1 -0
- package/dist/live-queries/client-document-get-query.js +18 -0
- package/dist/live-queries/client-document-get-query.js.map +1 -0
- package/dist/live-queries/computed.d.ts +12 -14
- package/dist/live-queries/computed.d.ts.map +1 -1
- package/dist/live-queries/computed.js +37 -15
- package/dist/live-queries/computed.js.map +1 -1
- package/dist/live-queries/db-query.d.ts +93 -0
- package/dist/live-queries/db-query.d.ts.map +1 -0
- package/dist/live-queries/{db.js → db-query.js} +111 -40
- package/dist/live-queries/db-query.js.map +1 -0
- package/dist/live-queries/db-query.test.d.ts +2 -0
- package/dist/live-queries/db-query.test.d.ts.map +1 -0
- package/dist/live-queries/db-query.test.js +133 -0
- package/dist/live-queries/db-query.test.js.map +1 -0
- package/dist/live-queries/mod.d.ts +5 -0
- package/dist/live-queries/mod.d.ts.map +1 -0
- package/dist/live-queries/mod.js +5 -0
- package/dist/live-queries/mod.js.map +1 -0
- package/dist/live-queries/signal.d.ts +20 -0
- package/dist/live-queries/signal.d.ts.map +1 -0
- package/dist/live-queries/signal.js +33 -0
- package/dist/live-queries/signal.js.map +1 -0
- package/dist/live-queries/signal.test.d.ts +2 -0
- package/dist/live-queries/signal.test.d.ts.map +1 -0
- package/dist/live-queries/signal.test.js +25 -0
- package/dist/live-queries/signal.test.js.map +1 -0
- package/dist/mod.d.ts +14 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +13 -0
- package/dist/mod.js.map +1 -0
- package/dist/reactive.d.ts +23 -17
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +23 -19
- package/dist/reactive.js.map +1 -1
- package/dist/reactive.test.js +1 -1
- package/dist/reactive.test.js.map +1 -1
- package/dist/store/create-store.d.ts +70 -12
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/create-store.js +68 -19
- package/dist/store/create-store.js.map +1 -1
- package/dist/store/devtools.d.ts +5 -4
- package/dist/store/devtools.d.ts.map +1 -1
- package/dist/store/devtools.js +92 -40
- package/dist/store/devtools.js.map +1 -1
- package/dist/store/store-types.d.ts +54 -42
- package/dist/store/store-types.d.ts.map +1 -1
- package/dist/store/store-types.js +2 -5
- package/dist/store/store-types.js.map +1 -1
- package/dist/store/store.d.ts +141 -35
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +319 -153
- package/dist/store/store.js.map +1 -1
- package/dist/utils/data-structures.d.ts.map +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +6 -1
- package/dist/utils/dev.js.map +1 -1
- package/dist/utils/function-string.d.ts +7 -0
- package/dist/utils/function-string.d.ts.map +1 -0
- package/dist/utils/function-string.js +9 -0
- package/dist/utils/function-string.js.map +1 -0
- package/dist/utils/stack-info.d.ts.map +1 -1
- package/dist/utils/stack-info.js +6 -1
- package/dist/utils/stack-info.js.map +1 -1
- package/dist/utils/stack-info.test.js +54 -1
- package/dist/utils/stack-info.test.js.map +1 -1
- package/dist/utils/tests/fixture.d.ts +59 -216
- package/dist/utils/tests/fixture.d.ts.map +1 -1
- package/dist/utils/tests/fixture.js +23 -18
- package/dist/utils/tests/fixture.js.map +1 -1
- package/dist/utils/tests/mod.d.ts +1 -0
- package/dist/utils/tests/mod.d.ts.map +1 -1
- package/dist/utils/tests/mod.js +1 -0
- package/dist/utils/tests/mod.js.map +1 -1
- package/dist/utils/tests/otel.d.ts.map +1 -1
- package/dist/utils/tests/otel.js +8 -3
- package/dist/utils/tests/otel.js.map +1 -1
- package/package.json +29 -26
- package/src/{SynchronousDatabaseWrapper.ts → SqliteDbWrapper.ts} +92 -42
- package/src/effect/LiveStore.ts +27 -64
- package/src/effect/{index.ts → mod.ts} +2 -3
- package/src/internal/mod.ts +2 -0
- package/src/live-queries/__snapshots__/{db.test.ts.snap → db-query.test.ts.snap} +241 -45
- package/src/live-queries/base-class.ts +152 -50
- package/src/live-queries/client-document-get-query.ts +52 -0
- package/src/live-queries/computed.ts +51 -33
- package/src/live-queries/db-query.test.ts +192 -0
- package/src/live-queries/{db.ts → db-query.ts} +168 -81
- package/src/live-queries/mod.ts +4 -0
- package/src/live-queries/signal.test.ts +40 -0
- package/src/live-queries/signal.ts +47 -0
- package/src/mod.ts +42 -0
- package/src/reactive.test.ts +1 -1
- package/src/reactive.ts +66 -43
- package/src/store/create-store.ts +188 -62
- package/src/store/devtools.ts +124 -46
- package/src/store/store-types.ts +54 -43
- package/src/store/store.ts +454 -236
- package/src/utils/dev.ts +6 -1
- package/src/utils/function-string.ts +12 -0
- package/src/utils/stack-info.test.ts +58 -1
- package/src/utils/stack-info.ts +6 -1
- package/src/utils/tests/fixture.ts +22 -31
- package/src/utils/tests/mod.ts +1 -0
- package/src/utils/tests/otel.ts +10 -3
- package/dist/SynchronousDatabaseWrapper.d.ts +0 -41
- package/dist/SynchronousDatabaseWrapper.d.ts.map +0 -1
- package/dist/SynchronousDatabaseWrapper.js.map +0 -1
- package/dist/effect/index.d.ts +0 -2
- package/dist/effect/index.d.ts.map +0 -1
- package/dist/effect/index.js +0 -2
- package/dist/effect/index.js.map +0 -1
- package/dist/global-state.d.ts +0 -14
- package/dist/global-state.d.ts.map +0 -1
- package/dist/global-state.js +0 -16
- package/dist/global-state.js.map +0 -1
- package/dist/index.d.ts +0 -20
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -16
- package/dist/index.js.map +0 -1
- package/dist/live-queries/db.d.ts +0 -66
- package/dist/live-queries/db.d.ts.map +0 -1
- package/dist/live-queries/db.js.map +0 -1
- package/dist/live-queries/db.test.d.ts +0 -2
- package/dist/live-queries/db.test.d.ts.map +0 -1
- package/dist/live-queries/db.test.js +0 -118
- package/dist/live-queries/db.test.js.map +0 -1
- package/dist/live-queries/graphql.d.ts +0 -49
- package/dist/live-queries/graphql.d.ts.map +0 -1
- package/dist/live-queries/graphql.js +0 -122
- package/dist/live-queries/graphql.js.map +0 -1
- package/dist/row-query-utils.d.ts +0 -17
- package/dist/row-query-utils.d.ts.map +0 -1
- package/dist/row-query-utils.js +0 -30
- package/dist/row-query-utils.js.map +0 -1
- package/dist/utils/otel.d.ts +0 -4
- package/dist/utils/otel.d.ts.map +0 -1
- package/dist/utils/otel.js +0 -6
- package/dist/utils/otel.js.map +0 -1
- package/src/global-state.ts +0 -20
- package/src/index.ts +0 -66
- package/src/live-queries/db.test.ts +0 -154
- package/src/live-queries/graphql.ts +0 -219
- package/src/row-query-utils.ts +0 -65
- package/src/utils/otel.ts +0 -9
- package/tsconfig.json +0 -18
- package/vitest.config.js +0 -9
package/src/reactive.ts
CHANGED
@@ -24,15 +24,19 @@
|
|
24
24
|
/* eslint-disable prefer-arrow/prefer-arrow-functions */
|
25
25
|
|
26
26
|
import { BoundArray } from '@livestore/common'
|
27
|
-
import type { PrettifyFlat } from '@livestore/utils'
|
28
27
|
import { deepEqual, shouldNeverHappen } from '@livestore/utils'
|
28
|
+
import type { Types } from '@livestore/utils/effect'
|
29
29
|
import type * as otel from '@opentelemetry/api'
|
30
30
|
// import { getDurationMsFromSpan } from './otel.js'
|
31
31
|
|
32
32
|
export const NOT_REFRESHED_YET = Symbol.for('NOT_REFRESHED_YET')
|
33
33
|
export type NOT_REFRESHED_YET = typeof NOT_REFRESHED_YET
|
34
34
|
|
35
|
-
export type GetAtom = <T>(
|
35
|
+
export type GetAtom = <T>(
|
36
|
+
atom: Atom<T, any, any>,
|
37
|
+
otelContext?: otel.Context | undefined,
|
38
|
+
debugRefreshReason?: TODO | undefined,
|
39
|
+
) => T
|
36
40
|
|
37
41
|
export type Ref<T, TContext, TDebugRefreshReason extends DebugRefreshReason> = {
|
38
42
|
_tag: 'ref'
|
@@ -42,7 +46,7 @@ export type Ref<T, TContext, TDebugRefreshReason extends DebugRefreshReason> = {
|
|
42
46
|
previousResult: T
|
43
47
|
computeResult: () => T
|
44
48
|
sub: Set<Atom<any, TContext, TDebugRefreshReason>> // always empty
|
45
|
-
super: Set<Thunk<any, TContext, TDebugRefreshReason> | Effect
|
49
|
+
super: Set<Thunk<any, TContext, TDebugRefreshReason> | Effect<TDebugRefreshReason>>
|
46
50
|
label?: string
|
47
51
|
/** Container for meta information (e.g. the LiveStore Store) */
|
48
52
|
meta?: any
|
@@ -58,7 +62,7 @@ export type Thunk<TResult, TContext, TDebugRefreshReason extends DebugRefreshRea
|
|
58
62
|
computeResult: (otelContext?: otel.Context, debugRefreshReason?: TDebugRefreshReason) => TResult
|
59
63
|
previousResult: TResult | NOT_REFRESHED_YET
|
60
64
|
sub: Set<Atom<any, TContext, TDebugRefreshReason>>
|
61
|
-
super: Set<Thunk<any, TContext, TDebugRefreshReason> | Effect
|
65
|
+
super: Set<Thunk<any, TContext, TDebugRefreshReason> | Effect<TDebugRefreshReason>>
|
62
66
|
label?: string
|
63
67
|
/** Container for meta information (e.g. the LiveStore Store) */
|
64
68
|
meta?: any
|
@@ -72,11 +76,11 @@ export type Atom<T, TContext, TDebugRefreshReason extends DebugRefreshReason> =
|
|
72
76
|
| Ref<T, TContext, TDebugRefreshReason>
|
73
77
|
| Thunk<T, TContext, TDebugRefreshReason>
|
74
78
|
|
75
|
-
export type Effect = {
|
79
|
+
export type Effect<TDebugRefreshReason extends DebugRefreshReason> = {
|
76
80
|
_tag: 'effect'
|
77
81
|
id: string
|
78
82
|
isDestroyed: boolean
|
79
|
-
doEffect: (otelContext?: otel.Context) => void
|
83
|
+
doEffect: (otelContext?: otel.Context | undefined, debugRefreshReason?: TDebugRefreshReason | undefined) => void
|
80
84
|
sub: Set<Atom<any, TODO, TODO>>
|
81
85
|
label?: string
|
82
86
|
invocations: number
|
@@ -84,7 +88,7 @@ export type Effect = {
|
|
84
88
|
|
85
89
|
export type Node<T, TContext, TDebugRefreshReason extends DebugRefreshReason> =
|
86
90
|
| Atom<T, TContext, TDebugRefreshReason>
|
87
|
-
| Effect
|
91
|
+
| Effect<TDebugRefreshReason>
|
88
92
|
|
89
93
|
export const isThunk = <T, TContext, TDebugRefreshReason extends DebugRefreshReason>(
|
90
94
|
obj: unknown,
|
@@ -98,7 +102,7 @@ export type DebugThunkInfo<T extends string = string> = {
|
|
98
102
|
}
|
99
103
|
|
100
104
|
export type DebugRefreshReasonBase =
|
101
|
-
/** Usually in response to some `
|
105
|
+
/** Usually in response to some `commit` calls with `skipRefresh: true` */
|
102
106
|
| {
|
103
107
|
_tag: 'runDeferredEffects'
|
104
108
|
originalRefreshReasons?: ReadonlyArray<DebugRefreshReasonBase>
|
@@ -140,7 +144,7 @@ const encodedOptionNone = <A>(): EncodedOption<A> => ({ _tag: 'None' })
|
|
140
144
|
export type SerializedAtom = SerializedRef | SerializedThunk
|
141
145
|
|
142
146
|
export type SerializedRef = Readonly<
|
143
|
-
|
147
|
+
Types.Simplify<
|
144
148
|
Pick<Ref<unknown, unknown, any>, '_tag' | 'id' | 'label' | 'meta' | 'isDirty' | 'isDestroyed' | 'refreshes'> & {
|
145
149
|
/** Is `None` if `getSnapshot` was called with `includeResults: false` which is the default */
|
146
150
|
previousResult: EncodedOption<string>
|
@@ -151,7 +155,7 @@ export type SerializedRef = Readonly<
|
|
151
155
|
>
|
152
156
|
|
153
157
|
export type SerializedThunk = Readonly<
|
154
|
-
|
158
|
+
Types.Simplify<
|
155
159
|
Pick<
|
156
160
|
Thunk<unknown, unknown, any>,
|
157
161
|
'_tag' | 'id' | 'label' | 'meta' | 'isDirty' | 'isDestroyed' | 'recomputations'
|
@@ -165,8 +169,8 @@ export type SerializedThunk = Readonly<
|
|
165
169
|
>
|
166
170
|
|
167
171
|
export type SerializedEffect = Readonly<
|
168
|
-
|
169
|
-
Pick<Effect
|
172
|
+
Types.Simplify<
|
173
|
+
Pick<Effect<any>, '_tag' | 'id' | 'label' | 'invocations' | 'isDestroyed'> & {
|
170
174
|
sub: ReadonlyArray<string>
|
171
175
|
}
|
172
176
|
>
|
@@ -179,14 +183,14 @@ export type ReactiveGraphSnapshot = {
|
|
179
183
|
readonly deferredEffects: ReadonlyArray<string>
|
180
184
|
}
|
181
185
|
|
182
|
-
let nodeIdCounter = 0
|
183
|
-
const uniqueNodeId = () => `node-${++nodeIdCounter}`
|
184
|
-
let refreshInfoIdCounter = 0
|
185
|
-
const uniqueRefreshInfoId = () => `refresh-info-${++refreshInfoIdCounter}`
|
186
|
-
|
187
186
|
let globalGraphIdCounter = 0
|
188
187
|
const uniqueGraphId = () => `graph-${++globalGraphIdCounter}`
|
189
188
|
|
189
|
+
/** Used for testing */
|
190
|
+
export const __resetIds = () => {
|
191
|
+
globalGraphIdCounter = 0
|
192
|
+
}
|
193
|
+
|
190
194
|
export class ReactiveGraph<
|
191
195
|
TDebugRefreshReason extends DebugRefreshReason,
|
192
196
|
TDebugThunkInfo extends DebugThunkInfo,
|
@@ -195,27 +199,32 @@ export class ReactiveGraph<
|
|
195
199
|
id = uniqueGraphId()
|
196
200
|
|
197
201
|
readonly atoms: Set<Atom<any, TContext, TDebugRefreshReason>> = new Set()
|
198
|
-
readonly effects: Set<Effect
|
202
|
+
readonly effects: Set<Effect<TDebugRefreshReason>> = new Set()
|
199
203
|
|
200
204
|
context: TContext | undefined
|
201
205
|
|
202
|
-
debugRefreshInfos: BoundArray<RefreshDebugInfo<TDebugRefreshReason, TDebugThunkInfo>> = new BoundArray(
|
206
|
+
debugRefreshInfos: BoundArray<RefreshDebugInfo<TDebugRefreshReason, TDebugThunkInfo>> = new BoundArray(200)
|
203
207
|
|
204
208
|
private currentDebugRefresh:
|
205
209
|
| { refreshedAtoms: AtomDebugInfo<TDebugThunkInfo>[]; startMs: DOMHighResTimeStamp }
|
206
210
|
| undefined
|
207
211
|
|
208
|
-
private deferredEffects: Map<Effect
|
212
|
+
private deferredEffects: Map<Effect<TDebugRefreshReason>, Set<TDebugRefreshReason>> = new Map()
|
209
213
|
|
210
214
|
private refreshCallbacks: Set<() => void> = new Set()
|
211
215
|
|
216
|
+
private nodeIdCounter = 0
|
217
|
+
private uniqueNodeId = () => `node-${++this.nodeIdCounter}`
|
218
|
+
private refreshInfoIdCounter = 0
|
219
|
+
private uniqueRefreshInfoId = () => `refresh-info-${++this.refreshInfoIdCounter}`
|
220
|
+
|
212
221
|
makeRef<T>(
|
213
222
|
val: T,
|
214
223
|
options?: { label?: string; meta?: unknown; equal?: (a: T, b: T) => boolean },
|
215
224
|
): Ref<T, TContext, TDebugRefreshReason> {
|
216
225
|
const ref: Ref<T, TContext, TDebugRefreshReason> = {
|
217
226
|
_tag: 'ref',
|
218
|
-
id: uniqueNodeId(),
|
227
|
+
id: this.uniqueNodeId(),
|
219
228
|
isDirty: false,
|
220
229
|
isDestroyed: false,
|
221
230
|
previousResult: val,
|
@@ -239,6 +248,7 @@ export class ReactiveGraph<
|
|
239
248
|
setDebugInfo: (debugInfo: TDebugThunkInfo) => void,
|
240
249
|
ctx: TContext,
|
241
250
|
otelContext: otel.Context | undefined,
|
251
|
+
debugRefreshReason: TDebugRefreshReason | undefined,
|
242
252
|
) => T,
|
243
253
|
options?:
|
244
254
|
| {
|
@@ -250,7 +260,7 @@ export class ReactiveGraph<
|
|
250
260
|
): Thunk<T, TContext, TDebugRefreshReason> {
|
251
261
|
const thunk: Thunk<T, TContext, TDebugRefreshReason> = {
|
252
262
|
_tag: 'thunk',
|
253
|
-
id: uniqueNodeId(),
|
263
|
+
id: this.uniqueNodeId(),
|
254
264
|
previousResult: NOT_REFRESHED_YET,
|
255
265
|
isDirty: true,
|
256
266
|
isDestroyed: false,
|
@@ -266,7 +276,7 @@ export class ReactiveGraph<
|
|
266
276
|
|
267
277
|
const getAtom = (atom: Atom<T, TContext, TDebugRefreshReason>, otelContext: otel.Context) => {
|
268
278
|
this.addEdge(thunk, atom)
|
269
|
-
return compute(atom, otelContext)
|
279
|
+
return compute(atom, otelContext, debugRefreshReason)
|
270
280
|
}
|
271
281
|
|
272
282
|
let debugInfo: TDebugThunkInfo | undefined = undefined
|
@@ -279,6 +289,7 @@ export class ReactiveGraph<
|
|
279
289
|
setDebugInfo,
|
280
290
|
this.context ?? throwContextNotSetError(this),
|
281
291
|
otelContext,
|
292
|
+
debugRefreshReason,
|
282
293
|
)
|
283
294
|
|
284
295
|
const resultChanged = thunk.equal(thunk.previousResult as T, result) === false
|
@@ -301,7 +312,7 @@ export class ReactiveGraph<
|
|
301
312
|
this.currentDebugRefresh = undefined
|
302
313
|
|
303
314
|
this.debugRefreshInfos.push({
|
304
|
-
id: uniqueRefreshInfoId(),
|
315
|
+
id: this.uniqueRefreshInfoId(),
|
305
316
|
reason: debugRefreshReason ?? ({ _tag: 'makeThunk', label: options?.label } as TDebugRefreshReason),
|
306
317
|
skippedRefresh: false,
|
307
318
|
refreshedAtoms,
|
@@ -365,14 +376,18 @@ export class ReactiveGraph<
|
|
365
376
|
}
|
366
377
|
|
367
378
|
makeEffect(
|
368
|
-
doEffect: (
|
379
|
+
doEffect: (
|
380
|
+
get: GetAtom,
|
381
|
+
otelContext: otel.Context | undefined,
|
382
|
+
debugRefreshReason: DebugRefreshReason | undefined,
|
383
|
+
) => void,
|
369
384
|
options?: { label?: string } | undefined,
|
370
|
-
): Effect {
|
371
|
-
const effect: Effect = {
|
385
|
+
): Effect<TDebugRefreshReason> {
|
386
|
+
const effect: Effect<TDebugRefreshReason> = {
|
372
387
|
_tag: 'effect',
|
373
|
-
id: uniqueNodeId(),
|
388
|
+
id: this.uniqueNodeId(),
|
374
389
|
isDestroyed: false,
|
375
|
-
doEffect: (otelContext) => {
|
390
|
+
doEffect: (otelContext, debugRefreshReason) => {
|
376
391
|
effect.invocations++
|
377
392
|
|
378
393
|
// NOTE we're not tracking any debug refresh info for effects as they're tracked by the thunks they depend on
|
@@ -380,12 +395,16 @@ export class ReactiveGraph<
|
|
380
395
|
// Reset previous subcomputations as we're about to re-add them as part of the `doEffect` call below
|
381
396
|
effect.sub = new Set()
|
382
397
|
|
383
|
-
const getAtom = (
|
398
|
+
const getAtom = (
|
399
|
+
atom: Atom<any, TContext, TDebugRefreshReason>,
|
400
|
+
otelContext: otel.Context,
|
401
|
+
debugRefreshReason: DebugRefreshReason | undefined,
|
402
|
+
) => {
|
384
403
|
this.addEdge(effect, atom)
|
385
|
-
return compute(atom, otelContext)
|
404
|
+
return compute(atom, otelContext, debugRefreshReason)
|
386
405
|
}
|
387
406
|
|
388
|
-
doEffect(getAtom as GetAtom, otelContext)
|
407
|
+
doEffect(getAtom as GetAtom, otelContext, debugRefreshReason)
|
389
408
|
},
|
390
409
|
sub: new Set(),
|
391
410
|
label: options?.label,
|
@@ -421,7 +440,7 @@ export class ReactiveGraph<
|
|
421
440
|
}
|
422
441
|
| undefined,
|
423
442
|
) {
|
424
|
-
const effectsToRefresh = new Set<Effect
|
443
|
+
const effectsToRefresh = new Set<Effect<TDebugRefreshReason>>()
|
425
444
|
for (const [ref, val] of refs) {
|
426
445
|
ref.previousResult = val
|
427
446
|
ref.refreshes++
|
@@ -448,7 +467,7 @@ export class ReactiveGraph<
|
|
448
467
|
}
|
449
468
|
|
450
469
|
private runEffects = (
|
451
|
-
effectsToRefresh: Set<Effect
|
470
|
+
effectsToRefresh: Set<Effect<TDebugRefreshReason>>,
|
452
471
|
options: {
|
453
472
|
debugRefreshReason: TDebugRefreshReason
|
454
473
|
otelContext?: otel.Context
|
@@ -459,7 +478,7 @@ export class ReactiveGraph<
|
|
459
478
|
this.currentDebugRefresh = { refreshedAtoms: [], startMs: performance.now() }
|
460
479
|
|
461
480
|
for (const effect of effectsToRefresh) {
|
462
|
-
effect.doEffect(options?.otelContext)
|
481
|
+
effect.doEffect(options?.otelContext, options.debugRefreshReason)
|
463
482
|
}
|
464
483
|
|
465
484
|
const refreshedAtoms = this.currentDebugRefresh.refreshedAtoms
|
@@ -467,7 +486,7 @@ export class ReactiveGraph<
|
|
467
486
|
this.currentDebugRefresh = undefined
|
468
487
|
|
469
488
|
const refreshDebugInfo: RefreshDebugInfo<TDebugRefreshReason, TDebugThunkInfo> = {
|
470
|
-
id: uniqueRefreshInfoId(),
|
489
|
+
id: this.uniqueRefreshInfoId(),
|
471
490
|
reason: options.debugRefreshReason,
|
472
491
|
skippedRefresh: false,
|
473
492
|
refreshedAtoms,
|
@@ -504,7 +523,7 @@ export class ReactiveGraph<
|
|
504
523
|
}
|
505
524
|
|
506
525
|
addEdge(
|
507
|
-
superComp: Thunk<any, TContext, TDebugRefreshReason> | Effect
|
526
|
+
superComp: Thunk<any, TContext, TDebugRefreshReason> | Effect<TDebugRefreshReason>,
|
508
527
|
subComp: Atom<any, TContext, TDebugRefreshReason>,
|
509
528
|
) {
|
510
529
|
superComp.sub.add(subComp)
|
@@ -516,11 +535,11 @@ export class ReactiveGraph<
|
|
516
535
|
}
|
517
536
|
|
518
537
|
removeEdge(
|
519
|
-
superComp: Thunk<any, TContext, TDebugRefreshReason> | Effect
|
538
|
+
superComp: Thunk<any, TContext, TDebugRefreshReason> | Effect<TDebugRefreshReason>,
|
520
539
|
subComp: Atom<any, TContext, TDebugRefreshReason>,
|
521
540
|
) {
|
522
541
|
superComp.sub.delete(subComp)
|
523
|
-
const effectsToRefresh = new Set<Effect
|
542
|
+
const effectsToRefresh = new Set<Effect<TDebugRefreshReason>>()
|
524
543
|
markSuperCompDirtyRec(subComp, effectsToRefresh)
|
525
544
|
|
526
545
|
for (const effect of effectsToRefresh) {
|
@@ -563,7 +582,11 @@ export class ReactiveGraph<
|
|
563
582
|
}
|
564
583
|
}
|
565
584
|
|
566
|
-
const compute = <T>(
|
585
|
+
const compute = <T>(
|
586
|
+
atom: Atom<T, unknown, any>,
|
587
|
+
otelContext: otel.Context,
|
588
|
+
debugRefreshReason: DebugRefreshReason | undefined,
|
589
|
+
): T => {
|
567
590
|
// const __getResult = atom._tag === 'thunk' ? atom.__getResult.toString() : ''
|
568
591
|
if (atom.isDestroyed) {
|
569
592
|
shouldNeverHappen(`LiveStore Error: Attempted to compute destroyed ${atom._tag} (${atom.id}): ${atom.label ?? ''}`)
|
@@ -571,7 +594,7 @@ const compute = <T>(atom: Atom<T, unknown, any>, otelContext: otel.Context): T =
|
|
571
594
|
|
572
595
|
if (atom.isDirty) {
|
573
596
|
// console.log('atom is dirty', atom.id, atom.label ?? '', atom._tag, __getResult)
|
574
|
-
const result = atom.computeResult(otelContext)
|
597
|
+
const result = atom.computeResult(otelContext, debugRefreshReason)
|
575
598
|
atom.isDirty = false
|
576
599
|
atom.previousResult = result
|
577
600
|
return result
|
@@ -581,7 +604,7 @@ const compute = <T>(atom: Atom<T, unknown, any>, otelContext: otel.Context): T =
|
|
581
604
|
}
|
582
605
|
}
|
583
606
|
|
584
|
-
const markSuperCompDirtyRec = <T>(atom: Atom<T, unknown, any>, effectsToRefresh: Set<Effect
|
607
|
+
const markSuperCompDirtyRec = <T>(atom: Atom<T, unknown, any>, effectsToRefresh: Set<Effect<any>>) => {
|
585
608
|
for (const superComp of atom.super) {
|
586
609
|
if (superComp._tag === 'thunk') {
|
587
610
|
superComp.isDirty = true
|
@@ -644,7 +667,7 @@ const serializeAtom = (atom: Atom<any, unknown, any>, includeResult: boolean): S
|
|
644
667
|
}
|
645
668
|
|
646
669
|
// NOTE This function is performance-optimized (i.e. not using `pick` and `Array.from`)
|
647
|
-
const serializeEffect = (effect: Effect): SerializedEffect => {
|
670
|
+
const serializeEffect = (effect: Effect<any>): SerializedEffect => {
|
648
671
|
const sub: string[] = []
|
649
672
|
for (const a of effect.sub) {
|
650
673
|
sub.push(a.id)
|