An architectural case study About one minute

From middleware
to engines.

Keep the side-effects. Remove the power to intercept actions.

Middleware can watch state, too. The architectural change is what an engine cannot do: delay, rename, or swallow an action on its way to the reducer. It watches committed state and can dispatch new actions, each through the same direct path.

The experiment

One action. Two interfaces.

architecture.pdf

Try both. Middleware can behave like an engine; its interface still permits interception.

Both dispatch UPLOAD_QUEUED with the same file and scheduled start.

Ready

Queue an upload and compare the original action’s receipt. Then try the other middleware behavior.

01

Middleware

May intercept the dispatch path.

Action→Delay · rename · send→Store

next(action) decides what reaches the reducer.

Original action: not dispatched

Upload widget reads the storeNo upload in state

Central store

0 uploads
{ "uploads": [] }
Effect runtime outside the store

No pending work.

Actions reaching the reducer

0
  1. No actions yet.
Full pipeline trace 0 events
    02

    Engine

    No interception point in its interface.

    Action→Store⇄Engine · send

    read · subscribe · dispatch — no next.

    Original action: not dispatched

    Upload widget reads the storeNo upload in state

    Central store

    0 uploads
    { "uploads": [] }
    Effect runtime outside the store

    No pending work.

    Actions reaching the reducer

    0
    1. No actions yet.
    Full pipeline trace 0 events

      Another view, same state.

      This compact status bar reads each store independently. No upload-specific wiring to either widget.

      Middleware Nothing queuedEngine Nothing queued

      A deterministic simulation: both paths share the same transfer implementation and two-tick delay. No file is uploaded. Each visitor gets an independent run; reset or refresh starts over.

      What I would change

      Constrain the interface.
      Keep the behavior traceable.

      01 / The mistake

      Giving side-effect code control over dispatch meant an action could be delayed, renamed, or swallowed before the reducer saw it. Tracing a name was no longer enough.

      02 / The change

      Remove the interception interface. Dispatch goes straight to the reducer. Engines observe committed state and dispatch separate actions to report their work.

      03 / The payoff

      Side-effects stay flexible: timers, uploads, retries, and result actions. Pending intent and progress can live in shared state, while the original action remains traceable.

      The implementationRead the functions running this demo ↗

      These are the running functions, displayed from the module itself. The middleware chain receives next and the action. The engine receives only state access, subscription, and dispatch. Its dispatch is the store’s own function; an observer cannot replace or withhold the action it is reacting to.

      Middleware

      Engine

      The direct store dispatch

      The shared transfer

      Open the full model source · Open the view source