# @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](/docs/decorators/subscribe). See [Data flow](/docs/getting-started/dataFlow) for the overall model.

## Import

<sonic-code language="typescript">
  <template>
import { publish } from "@supersoniks/concorde/decorators";
import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";

type CheckIn = { passenger: string; seat: string };
const checkInKey = new DataProviderKey&lt;CheckIn&gt;("checkIn");

@publish(checkInKey.passenger)
@state()
passenger = "Ada Lindqvist";
  </template>
</sonic-code>

## Basic usage

Each assignment calls `set()` on the publisher at the [DataProviderKey](/docs/misc/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](/docs/decorators/bind) with `reflect: true`.

The check-in form below publishes `passenger` and `seat`; the boarding pass reads them back with [sub()](/docs/directives/sub).

<sonic-code>
  <template>
    <docs-demo-sources for="demo-publish"></docs-demo-sources>
    <demo-publish></demo-publish>
  </template>
</sonic-code>

## 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](/docs/misc/dynamic-path).

<sonic-code language="typescript">
  <template>
@property({ type: Number }) seatIndex = 0;

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

## 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 |
