Concorde documentation · same URL (interactive) · llms.txt

Concorde decorator — @publish. @publish(key) writes a component property to one path of the store: every assignment to the property is published there. It never reads back from the store; it is the inverse of @subscribe. See Data f Doc ID: docs/decorators/publish. Keywords: Concorde, supersoniks, docs/decorators/publish, publish, @publish, decorator, @publish(key), set(), undefined, reflect: true, passenger, seat, ${prop}, null, skipEmptyPlaceholder. URL: https://concorde.supersoniks.org/docs/decorators/publish.

@publish

@publish(key) writes a component property to one path of the store: every assignment to the property is published there. It never reads back from the store; it is the inverse of @subscribe. See Data flow for the overall model.

Import

import { publish } from "@supersoniks/concorde/decorators";
import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";

type CheckIn = { passenger: string; seat: string };
const checkInKey = new DataProviderKey<CheckIn>("checkIn");

@publish(checkInKey.passenger)
@state()
passenger = "Ada Lindqvist";

Basic usage

Each assignment calls set() on the publisher at the DataProviderKey path. On connect, a defined property value is published immediately, so the initializer overwrites what the store held. Leave the property undefined to keep the store value. To read and write the same path, use @bind with reflect: true.

The check-in form below publishes passenger and seat; the boarding pass reads them back with sub().

<docs-demo-sources for="demo-publish"></docs-demo-sources>
    <demo-publish></demo-publish>

Dynamic path

${prop} placeholders resolve from properties of the same component. When a placeholder changes, the property is published to the new path. While it is null or undefined, nothing is published. Rules and skipEmptyPlaceholder: Dynamic paths.

@property({ type: Number }) seatIndex = 0;

@publish(
  new DataProviderKey&lt;string, { seatIndex: number }&gt;("onBoard.${seatIndex}.seat"),
  { skipEmptyPlaceholder: true },
)
@state()
seat = "1A";

API reference

Argument Type Description
key DataProviderKey<T, U> Path to write. U lists the host properties used by ${…} placeholders
options.skipEmptyPlaceholder boolean (default false) Treat a placeholder resolved to "" as not ready