Skip to content

enum

Decl

pub enum Decl {
    State { name: String, init: Expr },
    Let { name: String, expr: Expr },
    Prop { name: String, default: Option<Expr>, kind: Option<PropKind> },
    Data { name: String, variants: Vec<String> },
    On { name: String, params: Vec<String>, actions: Vec<Action> },
    Load { name: String, request: Expr },
    Timer { kind: TimerKind, when: Option<Expr>, actions: Vec<Action> },
    Fn { name: String, params: Vec<String>, body: Expr },
    Use { path: String },
    StaticParams { expr: Expr },
    Provide { names: Vec<String> },
    Window { event: String, listener: Listener },
}

A declaration at a template's top level.

Variants

State

State { name: String, init: Expr }

state name = init

Let

Let { name: String, expr: Expr }

let name = expr

Prop

Prop { name: String, default: Option<Expr>, kind: Option<PropKind> }

props (name = default, other): a prop the component takes, and what it is when the caller passes none (null without a default).

Data

Data { name: String, variants: Vec<String> }

data Size = small | medium | large: a named set of variants.

On

On { name: String, params: Vec<String>, actions: Vec<Action> }

on name(params) = action, action, …

Load

Load { name: String, request: Expr }

load name = get(url, options)

Timer

Timer { kind: TimerKind, when: Option<Expr>, actions: Vec<Action> }

every 1 when cond = action, …, after …, every frame …

Fn

Fn { name: String, params: Vec<String>, body: Expr }

fn name(params) = body: a function of values.

Use

Use { path: String }

use "shared.weft": another file's declarations, which crate::parse_file puts in its place.

StaticParams

StaticParams { expr: Expr }

static params = expr: the route parameters of the pages built ahead of time.

Provide

Provide { names: Vec<String> }

provide name, other: names the components inside can read.

Window

Window { event: String, listener: Listener }

@resize: width <- event.innerWidth or @keydown: press(event.key): a window event and what it does, while the component is on the page.

Methods

name

pub fn name(&self) -> &str

The name it declares ("" for a timer, a window event, a use, static params and provide, which declare none).

references

pub fn references(&self, bound: &mut Vec<String>, out: &mut BTreeSet<String>)

Names the declaration reads from outside it (its parameters and event excluded), added to out.

Trait implementations