Module: lib/core/runtime/atomic

The atomic() marker for bridge actions.

A component declares a transaction in its template — <action name="inc" atomic> — because that is where its actions are declared. A bridge is an ordinary ES module, so there is no attribute to hang the declaration on and it takes a wrapper instead:

import { bridge, atomic } from 'avenx-core/runtime';

export default bridge({ state: { items: [] }, addQty: atomic(function (id, n) { ... }), });

The wrapper does two jobs at once. At runtime it marks the function so the Bridge factory knows to run it inside a transaction. At compile time it is the syntax BridgeParser recognises, which is what puts the action's write set into Atlas and its effects into the AVX_W43 report.

It returns the same function rather than a new one, so a bridge action keeps its name, its arity and its identity — a wrapper that changed any of those would show up in stack traces and in fn.length checks for no reason.

Source:

Members

(static, constant) ATOMIC_MARK :symbol

Marks a bridge action as transactional.

A symbol keeps the mark out of the member namespace that ownKeys and template scopes see.

Type:
  • symbol
Source:

Methods

(static) atomic(fn, optionsopt) → {T}

Declares a bridge action transactional.

Every state write the action makes — its own and those of anything it calls — is journaled. If the action throws, or returns a promise that rejects, the journal is played backwards and the state is what it was before the action ran.

Parameters:
Name Type Attributes Description
fn T

The action implementation.

options object <optional>

Transaction options.

Properties
Name Type Attributes Description
onConflict 'safe' | 'force' | 'abort' <optional>

What a rewind does when it finds a value this transaction did not write. Defaults to the project's rewind.onConflict.

Source:
Throws:

When given something that is not a function.

Type
AvenxError
Returns:

The same function, marked.

Type
T

(static) atomicOptions(fn) → {Object|null}

Reads the transaction options off a marked function.

Parameters:
Name Type Description
fn function

A possible atomic action.

Source:
Returns:

Its options, or null when unmarked.

Type
Object | null

(static) isAtomic(fn) → {boolean}

Whether a function was declared atomic.

Parameters:
Name Type Description
fn function

A possible atomic action.

Source:
Returns:

True when the function carries the mark.

Type
boolean