App

import App from 'cerebral'
import main from './main' // The main module

const app = App(main, {
  // The devtools
  devtools: null,
  // Also logs error handling to console.
  throwToConsole: true,
  // Prevent rethrow of errors (useful if you already use an on('error') handler)
  noRethrow: false,
  // A map of state changes to run before instantiation,
  // where the key is the path and value is the state value
  stateChanges: {},
  // Sequence execution returns promises
  returnSequencePromise: false,
  // Enables handling hotReloading. Hot reloading it detected and warned about. When active
  // Cerebral will do a smart merge of any changes hot reloaded and update the devtools
  hotReloading: false
})

Methods 

getState 

Returns state from the state tree

const someState = app.getState('some.state')

getSequence 

Returns sequence from Cerebral

const someSequence = app.getSequence('some.sequence')
// Run sequence
someSequence({ foo: 'bar' })

getModel 

Returns the model (state tree) of Cerebral

const model = app.getModel()

flush 

Flushes out changes to UI based on recent state changes, can be forced

app.flush()

runSequence 

Allows you to run an arbitrary function tree definition

app.runSequence('someSequence', [actionA, actionB], { foo: 'bar' })

addModule 

Allows you to add modules to the app after instantiation (lazy)

app.addModule('someModule', module)

removeModule 

Allows you to remove modules from the app

app.removeModule('someModule')

Events 

initialized:model 

Triggers when Cerebral model has initialized.

app.on('initialized:model', () => {})

initialized 

Triggers when Cerebral app has initialized.

app.on('initialized', () => {})

moduleAdded 

Triggers when Cerebral adds a module is added.

app.on('moduleAdded', (path, module) => {})

moduleRemoved 

Triggers when Cerebral removes a module.

app.on('moduleRemoved', (path, module) => {})

flush 

Triggered whenever Cerebral flushes out changes to the UI. Passes a map of changes.

app.on('flush', (changes) => {})

start 

Triggered whenever Cerebral starts a sequence execution.

app.on('start', (execution, payload) => {})

end 

Triggered whenever Cerebral ends a sequence execution.

app.on('end', (execution, payload) => {})

pathStart 

Triggered whenever Cerebral starts execution a path in a sequence

app.on('pathStart', (execution, payload) => {})

pathEnd 

Triggered whenever Cerebral ends execution a path in a sequence

app.on('pathEnd', (execution, payload) => {})

functionStart 

Triggered whenever Cerebral starts executing an action.

app.on('functionStart', (execution, functionDetails, payload) => {})

functionEnd 

Triggered whenever Cerebral ends executing an action.

app.on(
  'functionEnd',
  (execution, functionDetails, payload, result) => {}
)

asyncFunction 

Triggered whenever Cerebral executed an async action.

app.on('asyncFunction', (execution, functionDetails, payload) => {})

parallelStart 

Triggered whenever Cerebral executes actions in parallel.

app.on(
  'parallelStart',
  (execution, payload, functionsToResolveCount) => {}
)

parallelProgress 

Triggered whenever Cerebral executes actions in parallel.

app.on(
  'parallelProgress',
  (execution, payload, functionsStillResolvingCount) => {}
)

parallelEnd 

Triggered whenever Cerebral ends executing actions in parallel.

app.on('parallelEnd', (execution, payload, functionsExecutedCount) => {})

remember 

Triggered whenever Cerebral travels back in time. Passes the timestamp it travelled to.

app.on('remember', (datetime) => {})

mutation 

Triggered whenever Cerebral mutated the state

app.on('mutation', (mutation) => {})