You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 088a23b
Browse filesBrowse the repository at this point in the historyBrowse files
* feat(getConfig): reactive subscribe via responseNotifier
Lets a query make subscribe (or any config field) react to response
state surgically. The framework exposes a Notifier on the execution
context that fires after each fetch; user code wraps reads of
this.response in reactiveSignal + responseNotifier.consume() to opt
into per-value reactive tracking.
class GetPrice extends RESTQuery {
getConfig() {
const ok = reactiveSignal(() => {
this.responseNotifier.consume();
return this.response?.ok;
}).value;
return { subscribe: poll({ interval: ok ? 1000 : 5000 }) };
}
}
getConfig re-runs only when ok actually transitions, not on every
fetch. The derived signal's default Object.is equals filters
propagation; the outer resolveOptions wrapper stays clean when no
deps changed; setupSubscription sees the same subscribe ref and
short-circuits.
Framework changes:
- ctx.response stays a plain field. New ctx.responseNotifier (Notifier)
is initialized in createExecutionContext.
- RESTQueryAdapter.executeRequest writes both ctx.response and
ctx.responseNotifier.notify() after each fetch.
- this.config and this.retryConfig on QueryInstance become getters
backed by a reactiveSignal wrapping resolveOptions.
- setupSubscription ref-checks against lastSubscribeFn before tearing
down, so identical-subscribe reads no-op.
- lastSubscribeFn cleared on deactivate and on paramsDidChange so
rebuilds happen in those cases regardless of ref.
Three lifecycle tests in query-stream.test.ts converted from
getConfig() returning inline closures to static config = ..., since
their getConfig usage was incidental (the tests verify subscribe
lifecycle, not dynamic config). The static form gives a stable
subscribe ref so the new behavior's ref check naturally short-circuits.
Two new tests in poll.test.ts cover the dynamic-interval and
stop-on-error patterns end-to-end.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* style: prettier format QueryResult.ts
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix: rebuild _resolvedSignal when ctx is recreated
Inline arrow functions inside getConfig() lexically capture `this`,
so a cached config from a previous ctx will read stale params (and
other ctx fields) when invoked under a new ctx. The framework was
caching the resolved-options signal across ctx changes, so a query
whose params changed kept seeing the old ctx through the cached
subscribe closure.
Replace _resolvedSignal whenever getOrCreateExecutionContext builds
a new ctx. Future reads pick up the new signal and re-call getConfig
with the new ctx as `this`, so inline arrows see the new params.
This removes the previous test diagnostic conversion to static
config: getConfig() returning an inline arrow with this.params access
now works correctly across param changes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test: drop extraneous onEvent rename in query-stream tests
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor: rename setupSubscription to reconcileSubscription
Reflects the post-reactive-getConfig role of the function: not a one-shot
setup but a reconcile against possibly-changed config. Also drops a
vestigial cast on ctx.responseNotifier in the REST adapter and refreshes
the _resolvedSignal header comment to name the reactivity contract
(upstream notifier, param-change replacement).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: tighten _resolvedOptions comments
Drop the redundant inline comment at the reassignment site (the field
header already explains it). Refresh the field header to name the
mechanism accurately (memoization, not closure capture) and use "such
as" rather than "typically" since third-party use cases are open-ended.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: document reactive getConfig and responseNotifier
Replace the broken dynamic-poll-interval example with the canonical
reactiveSignal + responseNotifier.consume() pattern, add a Notifier row
to the RESTQuery instance properties table, and note in the methods
table that getConfig is reactive. Also adds a minor changeset.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: flag reactive getConfig changeset as breaking
The prior "implementations that never read reactive state continue to
work" line was only true for getConfig that doesn't read mutable
execution-context state at all. Direct this.response reads (the
canonical pre-existing pattern) silently return stale config under the
new memoization model. Spell out the failure mode and the fix.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
**Breaking:**`getConfig()` is now memoized via a `reactiveSignal` instead of being recomputed on every fetch; it only re-runs when a signal consumed inside notifies. Existing implementations that read mutable execution-context state directly (most commonly `this.response`) silently return stale config after first evaluation, because plain field reads track no signals. To react to new responses, wrap the read in a `reactiveSignal` thunk that consumes the newly-exposed `this.responseNotifier` (a Signalium `Notifier` on the execution context, fired by `RESTQueryAdapter` after each request): `reactiveSignal(() => { this.responseNotifier.consume(); return this.response?.ok; }).value`. `getConfig()` implementations that don't read mutable ctx state continue to work unchanged.
|`fetchNext`|`FetchNextConfig \| undefined`| — | Static pagination config. Values can be FieldRefs (e.g. `this.result.nextCursor`). |
91
-
|`response`|`Response \| undefined`| — | The raw HTTP `Response` from the last fetch. Set by `RESTQueryAdapter` after each request completes. Available in `getConfig()`. |
|`fetchNext`|`FetchNextConfig \| undefined`| — | Static pagination config. Values can be FieldRefs (e.g. `this.result.nextCursor`). |
91
+
|`response`|`Response \| undefined`| — | The raw HTTP `Response` from the last fetch. Set by `RESTQueryAdapter` after each request completes. Available in `getConfig()`. |
92
+
|`responseNotifier`|`Notifier`| — | Notifier fired by `RESTQueryAdapter` after each fetch completes. Consume inside a `reactiveSignal` in `getConfig()` to react to new responses. |
Copy file name to clipboardExpand all lines: docs/src/app/core/queries/page.md
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,7 +97,7 @@ The full list of options provided by `RESTQuery` is available below, but there a
97
97
1. Parameters should not be connected to the _specifics_ of your Queries. You should be able to change if a parameter is passed as a search param, a path param, a header, or so on, without having to change every _usage_ of the query.
98
98
2. More broadly, this distinction allows you to keep your Queries _protocol agnostic_. If you decide to switch from REST to GraphQL or gRPC in the future, none of your usage sites need to change.
99
99
100
-
The same distinction applies to query _results_. Internally, `RESTQuery` exposes the raw HTTP response on `this.response` after each fetch completes (which can be used in `getConfig()`for things like controlling retry or polling behavior based on whether the response was successful or errored). Externally, the result gets parsed by the `this.result` definition and exposed as the query's value.
100
+
The same distinction applies to query _results_. Internally, `RESTQuery` exposes the raw HTTP response on `this.response` after each fetch completes (which can be used reactively in `getConfig()`via `this.responseNotifier` to control retry or polling behavior based on whether the response was successful or errored). Externally, the result gets parsed by the `this.result` definition and exposed as the query's value.
101
101
102
102
This brings us to the next topic: Using Queries.
103
103
@@ -394,9 +394,11 @@ class GetUser extends RESTQuery {
394
394
}
395
395
```
396
396
397
-
But let's say we wanted to provide a _dynamic_ polling interval based on the query response. We can't use conditional logic in the _field_ version of `config`, but we can in the _method_ version:
397
+
But let's say we wanted to provide a _dynamic_ polling interval based on the query response. We can't use conditional logic in the _field_ version of `config`, but we can in the _method_ version. `getConfig()` is reactive: it re-runs whenever a signal it consumed notifies. `this.responseNotifier` is fired after every fetch, so wrap response reads in a `reactiveSignal` that consumes it:
398
398
399
399
```ts
400
+
import { reactiveSignal } from'signalium';
401
+
400
402
classGetUserextendsRESTQuery {
401
403
params = {
402
404
id: t.number,
@@ -409,7 +411,10 @@ class GetUser extends RESTQuery {
409
411
};
410
412
411
413
getConfig() {
412
-
const lastResponseOk =this.response?.ok??true;
414
+
const lastResponseOk =reactiveSignal(() => {
415
+
this.responseNotifier.consume();
416
+
returnthis.response?.ok??true;
417
+
}).value;
413
418
414
419
// If the last response was ok, poll quickly. Else, poll
415
420
// slowly - the service might be having trouble.
@@ -422,6 +427,8 @@ class GetUser extends RESTQuery {
422
427
}
423
428
```
424
429
430
+
`this.response` is a plain field, not a signal, so reading it directly inside `getConfig()` would only evaluate once at activation and never re-run as new responses arrive. `responseNotifier.consume()` inside a `reactiveSignal` is what subscribes the outer `getConfig()` to fetch completions.
431
+
425
432
### Field reference
426
433
427
434
Here is a quick reference of the fields that are available for configuration on `RESTQuery`:
Copy file name to clipboardExpand all lines: docs/src/app/reference/rest-queries/page.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ This is useful when search params or body fields affect the response but don't a
86
86
87
87
## Dynamic Config with getConfig()
88
88
89
-
For runtime-dependent configuration, override `getConfig()`. This is useful when caching, network behavior, or retry logic should vary based on the query's params or other runtime state:
89
+
For runtime-dependent configuration, override `getConfig()`. This is useful when caching, network behavior, or retry logic should vary based on the query's params or other runtime state. `getConfig()` is reactive: it re-runs whenever a signal consumed inside notifies. Read `this.response` reactively via `this.responseNotifier` (see [Core: Queries](/core/queries#avoid-arrow-functions-for-dynamic-logic)).
0 commit comments