BuiltinSideEffects extension
A collection of builtin side effects.
Methods
-
api(
) → SideEffectApi - Convenience side effect that gives a copy of the SideEffectApi.
-
asListener(
) → void - Declares the associated capsule as a non-idempotent listener.
-
callonce<
T> (T callback()) → T -
Side effect that calls the supplied
callback
once, on the first build. -
data<
T> (T initial) → ValueWrapper< T> - Keeps track of some data that can be stateful. You may set the value of returned ValueWrapper both:
-
disposable<
T> (T init(), void dispose(T), [List< Object?> dependencies = const []]) → T - A shortcut over memo and effect to handle disposable objects. Specifically, this:
-
effect(
void Function()? effect(), [List< Object?> ? dependencies]) → void -
Equivalent to the
useEffect
hook from React. See https://react.dev/reference/react/useEffect -
future<
T> (Future< T> future) → AsyncValue<T> -
Consumes a Future and watches the given
future
. -
hydrate<
T> (T? newData, {required Future< T> read(), required Future<void> write(T)}) → AsyncValue<T> - A mechanism to persist changes made to some provided state. Unlike persist, hydrate allows you to pass in the state to persist, if there is one, to enable easier composition with other side effects.
-
invalidatableFuture<
T> (Future< T> futureFactory()) → (AsyncValue<T> Function(), void Function()) - A side effect that allows you to watch a future lazily (by invoking the first callback) that can be invalidated lazily (by invoking the second callback).
-
isFirstBuild(
) → bool - Returns true on the first build and false on subsequent builds.
-
lazyData<
T> (T init()) → ValueWrapper< T> - Keeps track of some data that can be stateful. You may set the value of returned ValueWrapper both:
-
lazyState<
T> (T init()) → (T, void Function(T)) -
Side effect that provides a way for capsules to contain some state,
where the initial state is computationally expensive.
Similar to the
useState
hook from React; see https://react.dev/reference/react/useState -
lazyStateGetterSetter<
T> (T init()) → (T Function(), void Function(T)) -
Side effect that provides a way for capsules to contain some state,
where the initial state is computationally expensive.
Further, instead of returning the state directly, this instead returns
a getter that is safe to capture in closures.
Similar to the
useState
hook from React; see https://react.dev/reference/react/useState -
lazyValue<
T> (T init()) → T -
Side effect that provides a way for capsules to hold onto some value
between builds, where the initial value is computationally expensive.
Similar to the
useRef
hook from React; see https://react.dev/reference/react/useRef -
memo<
T> (T memo(), [List< Object?> dependencies = const []]) → T -
Equivalent to the
useMemo
hook from React. See https://react.dev/reference/react/useMemo -
mutation<
T> () → Mutation< T> - Allows you to trigger and watch Futures (called mutations, since they often mutate some state) from within the build function. See the documentation for more.
-
nullableFuture<
T> (Future< T> ? future) → AsyncValue<T> ? -
Consumes a nullable Future and watches the given
future
. -
nullableStream<
T> (Stream< T> ? stream) → AsyncValue<T> ? -
Consumes a nullable Stream and watches the given
stream
. -
persist<
T> ({required Future< T> read(), required Future<void> write(T)}) → (AsyncValue<T> , void Function(T)) - A mechanism to persist changes made in state that manages its own state. See the docs for usage information.
-
previous<
T> (T current) → T? -
Returns the previous value passed into previous,
or
null
on first build. -
rebuilder(
) → void Function([void sideEffectMutation(void cancelRebuild())?]) - Convenience side effect that gives a copy of SideEffectApi.rebuild.
-
reducer<
State, Action> (Reducer< State, Action> reducer, State initialState) → (State, void Function(Action)) - A simple implementation of the reducer pattern as a side effect.
-
refreshableFuture<
T> (Future< T> futureFactory()) → (AsyncValue<T> , void Function()) - A side effect that allows you to watch a future that can be refreshed by invoking the supplied callback.
-
replay<
T> () → (T?, void Function(T), {void Function()? redo, void Function()? undo}) - Provides a way to keep track of some state while also providing "undo" and "redo" operations. This side effect is analogous to the replay bloc library, if you have heard of it.
-
state<
T> (T initial) → (T, void Function(T)) -
Side effect that provides a way for capsules to contain some state.
Similar to the
useState
hook from React; see https://react.dev/reference/react/useState -
stateGetterSetter<
T> (T initial) → (T Function(), void Function(T)) -
Side effect that provides a way for capsules to contain some state.
Further, instead of returning the state directly, this instead returns
a getter that is safe to capture in closures.
Similar to the
useState
hook from React; see https://react.dev/reference/react/useState -
stream<
T> (Stream< T> stream) → AsyncValue<T> -
Consumes a Stream and watches the given
stream
. -
transactionRunner(
) → void Function(void ()) - Convenience side effect that gives a copy of SideEffectApi.runTransaction.
-
value<
T> (T initial) → T -
Side effect that provides a way for capsules to hold onto some value
between builds.
Similar to the
useRef
hook from React; see https://react.dev/reference/react/useRef