Module: lib/core/trace/resource

Recording and replay of <resource> requests.

Resources are Avenx's declarative async boundary, which makes them the one place the framework can see network work happening. Recording their settlements — and feeding those settlements back during replay — is what lets a recorded session be reproduced without a server.

This deliberately does not intercept fetch or XMLHttpRequest globally. A trace that silently swallowed every request in the page would be recording work Avenx has no model of, and would report success for reproductions that only appeared to work. Requests made outside a <resource> are not reproduced, and a trace whose state depends on them diverges visibly during replay rather than passing by accident.

Source:

Members

(inner) onMissingResponse :function

Called when replay asks for a response that was never recorded.

Type:
  • function
Source:

(inner, constant) recordedResponses :Map:.<string:, Array:.<object:>>

Recorded settlements queued per resource name, oldest first.

Empty outside replay, so takeRecordedResponse is a Map.size check on the recording path.

Type:
  • Map:.<string:, Array:.<object:>>
Source:

Methods

(static) clearResourceResponses()

Discards any loaded responses, restoring live resource behaviour.

Source:

(static) hasRecordedResponses() → {boolean}

Whether replay has responses loaded.

Source:
Returns:
Type
boolean

(static) installResourceResponses(trace, onMissingopt)

Loads a trace's resource settlements so replay can serve them.

Parameters:
Name Type Attributes Description
trace object

The trace to replay.

onMissing function <optional>

Called when a resource asks for a response the trace does not have.

Source:

(static) takeRecordedResponse(name) → {object|null}

Takes the next recorded settlement for a resource.

A resource that asks for more settlements than were recorded is reported rather than served a repeat: replay has gone further than the recording did, which is divergence, and inventing a response would hide it.

Parameters:
Name Type Description
name string

The resource name.

Source:
Returns:

{status, value, error}, or null when nothing is queued.

Type
object | null

(static) traceResourceSettle(pending, name, status, payload)

Records how a resource settled.

Settlements are recorded as their own node rather than by annotating the pending one: a resource settles asynchronously, and a trace that mutated an older node in place would lose the ordering that replay depends on.

Parameters:
Name Type Description
pending object | null

The node returned by traceResourceStart.

name string

The resource name.

status 'resolved' | 'rejected'

How it settled.

payload any

The value, or the error.

Source:

(static) traceResourceStart(name, component, pollInterval) → {object|null}

Opens a node for a resource that has started work.

Parameters:
Name Type Description
name string

The resource name.

component object | null

The owning component instance.

pollInterval number

The configured poll interval, if any.

Source:
Returns:

The opened node, for later settlement.

Type
object | null