SimpleR State

The simplest app state management for React

View project on GitHub

Orchestrating Updates to Multiple Entities with One Action

Although each action is normally associated with just one entity, it is still defined outside the entity object. Because of this, we can easily implement an action such that it can access and update multiple entities. Such an action is also known as an orchestrator.

There are two ways an orchestrator action can update entities:

  • directly call the set method of each relevant entity, or
  • invoke other actions that are associated with the entities

Here's a simplified example:

import { counter } from './entities/counter'
import { signOut } from './entities/auth'

export const logout = () => {
  counter.set(0)  // 👈 using an entity's setter
  signOut()  // 👈 using an associated action

Back to home | More recipes...