Trait composable::effects::Effects

source ·
pub trait Effects: Clone + Scheduler<Action = Self::Action> {
    type Action;

    // Required methods
    fn action(&self, action: impl Into<<Self as Effects>::Action>);
    fn task<S: Stream<Item = <Self as Effects>::Action> + 'static>(
        &self,
        stream: S,
    ) -> Task;

    // Provided methods
    fn future<F: Future<Output = Option<<Self as Effects>::Action>> + 'static>(
        &self,
        future: F,
    )
       where <Self as Effects>::Action: 'static { ... }
    fn stream<S: Stream<Item = <Self as Effects>::Action> + 'static>(
        &self,
        stream: S,
    ) { ... }
    fn scope<ChildAction>(&self) -> Scoped<Self, ChildAction>
       where <Self as Effects>::Action: From<ChildAction> { ... }
}
Expand description

Effects are used within Reducers to propagate Actions as side-effects of performing other Actions.

Effects are also Schedulers — able to apply modifiers to when (and how often) Actions. are sent.

See the module level documentation for more.

Required Associated Types§

source

type Action

The Action type sent by this Effects.

Required Methods§

source

fn action(&self, action: impl Into<<Self as Effects>::Action>)

An effect that sends an Action through the Store’s Reducer.

source

fn task<S: Stream<Item = <Self as Effects>::Action> + 'static>( &self, stream: S, ) -> Task

A Task represents asynchronous work that will then send zero or more Actions back into the Store’s Reducer as it runs.

Use this method if you need to ability to cancel the task while it is running. Otherwise future or stream should be preferred.

Provided Methods§

source

fn future<F: Future<Output = Option<<Self as Effects>::Action>> + 'static>( &self, future: F, )
where <Self as Effects>::Action: 'static,

An effect that runs a Future and, if it returns an Action, sends it through the Store’s Reducer.

source

fn stream<S: Stream<Item = <Self as Effects>::Action> + 'static>( &self, stream: S, )

An effect that runs a Stream and sends every Action it returns through the Store’s Reducer.

source

fn scope<ChildAction>(&self) -> Scoped<Self, ChildAction>
where <Self as Effects>::Action: From<ChildAction>,

Scopes the Effects down to one that sends child actions.

For example, the inner loop of the RecursiveReducer macro is, effectively, just calling

if let Ok(action) = action.clone().try_into() {
    reduce(&mut self.child_reducer, action, effects.scope());
}

on each child-reducer.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Parent, Child> Effects for Scoped<Parent, Child>
where Parent: Effects, <Parent as Effects>::Action: Clone + From<Child> + 'static, Child: 'static,

§

type Action = Child