Piece | Contract | Purpose |
|---|---|---|
GlobalState | Runtime-owned durable app state | Holds product truth shared across screens, reducers, tests, and shells |
StateField<T> | Handle to retained local widget state | Stores UI-local memory for one stable widget identity |
BuildCtxHandle<S> | Build-scope wiring handle | Binds actions, local reducers, resources, portals, media, and animations |
ViewHandle<S> | Build-scope read handle | Reads GlobalState, Env, runtime values, layout snapshots, and selectors |
Provider<T, F> | Typed build-stack value scoped to descendants | Lets parents inject contextual read-only values without prop drilling |
Action | Typed, serializable intent with stable ActionId | Describes what happened in app terms |
reducer | Function that updates state for an action | Centralizes mutations in one explicit path |
ReducerContext<S> | Reducer-time effect and input context | Lets reducers request outside work and read returned payloads |
Selector<S> | Read-only derived view computation | Keeps component conversion focused on view-ready values |
#[derive(Debug, Default, Clone, FissionGlobalState)]
pub struct ShopState {
pub cart: CartState,
pub session: SessionState,
}
#[derive(Debug, Default, Clone, FissionStateView)]
pub struct CartState {
pub items: Vec<CartItem>,
}
let (ctx, view) = fission::build::current::<ShopState>();
let (ctx, _) = fission::build::current::<()>();
Method | Purpose |
|---|---|
state() | Returns the current &S app state |
global() | Returns the generated typed state view when S: FissionViewField |
select(...) | Runs a one-off closure selector against &S |
select_with::<T>() | Runs a reusable Selector<S> implementation |
env() | Reads the current environment |
theme() | Reads env.theme |
i18n() | Reads env.i18n |
viewport_size() | Reads the current viewport size |
layout() | Reads the optional previous layout snapshot |
get_rect(id) | Reads a previous layout rectangle for a widget id |
get_constraints(id) | Reads previous constraints for a widget id |
animation_value(id, property) | Reads runtime animation state for a widget property |
video_state(id) | Reads runtime video state for a widget |
Method | Purpose |
|---|---|
bind(action, handler) | Creates an ActionEnvelope for a normal app-state reducer |
register::<A, H>(handler) | Registers a reducer handler without immediately binding a widget event |
bind_local(action, field, handler) | Binds a reducer to a retained local StateField<T> |
request_animation_for(id, request) | Queues an animation request for a widget id |
anim_for(id) | Creates a scoped animation helper for a target widget id |
register_video(...) | Registers a video node with the runtime |
register_web_view(...) | Registers a web view node with the runtime |
register_portal(...) | Registers a default-layer portal |
register_portal_with_id(...) | Registers a portal with an explicit widget id |
register_portal_with_layer(...) | Registers a portal in a specific layer |
with_resources(...) | Gives controlled access to the build resource registry |
video_controls(id) | Creates controls for a registered video widget |
impl From<CartBadge> for Widget {
fn from(_: CartBadge) -> Widget {
let (_, view) = fission::build::current::<ShopState>();
Text::new(format!("{}", view.state().cart.items.len())).into()
}
}
// Do not store handles for later reducer, async, service, or static use.
struct BadCache<S: GlobalState> {
view: ViewHandle<S>,
}
#[fission_component]
pub struct Counter {
#[local_state(default = 0)]
count: i32,
}
let count = counter.count();
let value = count.get();
#[fission_reducer(Increment)]
fn increment(count: &mut i32) {
*count += 1;
}
let (ctx, _) = fission::build::current::<()>();
let count = counter.count();
let on_press = ctx.bind_local(Increment, count.clone(), reduce!(increment));
Method | Purpose |
|---|---|
get() | Clones and returns the current retained value |
component() | Returns the component identity string used by the generated accessor |
field() | Returns the field name |
key() | Returns the LocalStateKey |
action_id::<A>() | Builds the scoped local action id for action A |
let children = rows
.into_iter()
.map(|row| RowCard { row: row.clone() }
.id(WidgetId::explicit(&format!("row.{}", row.id))))
.collect();
#[derive(Clone)]
struct SectionName(&'static str);
Provider::new(SectionName("billing"), || BillingFields).into()
let section = fission::build::read::<SectionName>();
let section = fission::build::try_read::<SectionName>()
.unwrap_or(SectionName("default"));
#[fission_reducer(SetFilter)]
fn on_set_filter(state: &mut ShopState, filter: ProductFilter) {
state.filter = filter;
}
#[fission_reducer(SaveRequested)]
fn on_save_requested(state: &mut ShopState, ctx: &mut ReducerContext<ShopState>) {
state.saving = true;
// request outside work through ctx.effects
}
Field | Purpose |
|---|---|
effects | Queues jobs, services, commands, capabilities, timers, and other runtime-managed work |
input | Reads explicit input that arrived with this dispatch, such as job results or capability payloads |
let (_, view) = fission::build::current::<ShopState>();
let cart_count = view.global().cart().items().map(|items| items.len()).get();
let cart_count = view.select(|state| state.cart.items.len());
Need | API |
|---|---|
Durable product data | GlobalState |
One widget's temporary retained memory | #[local_state] and StateField<T> |
Parent-scoped contextual read-only data | Provider<T, F>, read::<T>(), try_read::<T>() |
Theme, locale, viewport, window, safe-area, and platform presentation context | Env through ViewHandle |
Bind a widget event to app-state change | BuildCtxHandle::bind(...) or with_reducer!(...) |
Bind a widget event to local state change | BuildCtxHandle::bind_local(...) |
Read app state or derived view models | ViewHandle::state, global, select, or select_with |
Request outside work | ReducerContext::effects |
Keep identity stable across reordered dynamic children | .id(WidgetId::explicit(...)) |