alepha@docs:~/docs/reference/primitives$
cat $store.md | pretty
1 min read

#$store

#Import

typescript
1import { $store } from "alepha";

#Overview

Reads a value out of the application store from a class property.

The declarative counterpart of alepha.store.get(target) — same store, same operation, expressed as a class member instead of an imperative call. The property is reactive: it re-reads on every access, so a mutation made elsewhere is visible immediately.

Accepts either side of the state model:

  • an {@link Atom} — read from the store, and registered on first use if it was not already
  • a {@link Computed} — derived from its dependencies on every read. Computed values are never stored, so nothing is registered.

Use cases: global state, configuration, sharing data between services, reading a derived value without wiring its dependencies by hand.

#Examples

Reading an atom

ts
 1const userState = $atom({ 2  name: "user.state", 3  schema: z.object({ name: z.text(), role: z.text() }), 4  default: { name: "", role: "guest" }, 5}); 6  7class UserService { 8  user = $store(userState); 9 10  greet() {11    return `Hello ${this.user.name}!`;12  }13}

Reading a computed

ts
1const cartTotal = $computed({2  name: "cart.total",3  deps: [cartAtom],4  get: (cart) => cart.items.reduce((sum, it) => sum + it.price, 0),5});6 7class CheckoutService {8  total = $store(cartTotal); // number, re-derived on every read9}