Skip to content

Mobius Loop

Jens Ayton edited this page Apr 23, 2020 · 2 revisions

A Mobius loop receives Events, which are passed to an Update function. As a result of running the Update function, the Model might change, and Effects might get dispatched. The Model can be observed by the user interface, and the Effects are received and executed by an Effect Handler.

A Mobius loop is what ties everything together in the Mobius framework. It is responsible for sending events to the Update function, keeping track of the current Model, sending Effects to the Effect Handler, and listening to the Event Source.

The normal way to create a loop is by calling Mobius.loop(...) and then starting it from the initial state of the Model:

loop = Mobius.loop(update: update, effectHandler: effectHandler)
    .start(from: Model.default)

You can add an observer if you want to know when the Model changes but the loop will start even if you don't add any:

let disposable = loop.addObserver(onModelChanged)

The returned Disposable can be used to stop observing the loop but normally you can just use loop.dispose() to shut down the loop and remove all observers at once.

Clone this wiki locally