Meiosis: The Big Picture
With the simple counter example from the previous sections, we have seen the basics of using Meiosis. We saw how to use a renderer, how to create a component with meiosis.createComponent
, and how to run the application with meiosis.run
. We passed renderer
, initialModel
, and rootComponent
to run
. We passed view
, receive
, and ready
to createComponent
. Now, let's look at the all the properties that we can use when creating Meiosis components. We'll also see the sequence in which Meiosis calls each function.
Initial Flow
The diagram below shows every property that you can pass to meiosis.createComponent
. Remember that every property is optional. The diagram also shows how every piece of a component is called when you first run your application with meiosis.run
:
If you do not specify a particular property, skip that function in the diagram.
As you can see, this is what happens initially:
- The
initialModel
is passed to thestate
function. - The result of the
state
function (application state) is passed to theview
. If there is nostate
function, theinitialModel
is passed instead. - Meiosis also passes either the
actions
object or thepropose
function to theview
function. - Meiosis passes the model or application state and the root component to the renderer. Specify the
renderer
, theinitialModel
, and therootComponent
when calling themeiosis.run
function. - If there is a
postRender
function, it gets called with the view. - If there is a
ready
function, it gets called with theactions
object or thepropose
function.
Propose/Receive Flow
After running your application, propose/receive are what make things happen. The following diagram illustrates what happens when you call propose
from the view, an event handler, and so on:
When you call propose
:
- The proposal is passed to the
receive
function. Meiosis also passes the latest model as the first parameter. - The model returned by the
receive
function becomes the latest model. - The latest model is passed to the
state
function. The result of thestate
function (application state) is passed to theview
. If there is nostate
function, the lastest model is passed directly to theview
function. - Meiosis also passes the
actions
object or thepropose
function to theview
function. - Meiosis passes the model and the root component to the renderer.
- If there is a
postRender
function, it gets called with the view. - If there is a
nextAction
function, Meiosis calls it with the model, proposal, andactions
object orpropose
function. ThenextAction
function decides whether to trigger another action by callingpropose
.
These diagrams are a cheat-sheet that you can return to for reference. In the following sections, we'll discuss each property that you can pass to meiosis.createComponent
in more detail.