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
})
Returns state from the state tree
const someState = app.getState('some.state')
Returns sequence from Cerebral
const someSequence = app.getSequence('some.sequence')
// Run sequence
someSequence({ foo: 'bar' })
Returns the model (state tree) of Cerebral
const model = app.getModel()
Flushes out changes to UI based on recent state changes, can be forced
app.flush()
Allows you to run an arbitrary function tree definition
app.runSequence('someSequence', [actionA, actionB], { foo: 'bar' })
Allows you to add modules to the app after instantiation (lazy)
app.addModule('someModule', module)
Allows you to remove modules from the app
app.removeModule('someModule')
Triggers when Cerebral model has initialized.
app.on('initialized:model', () => {})
Triggers when Cerebral app has initialized.
app.on('initialized', () => {})
Triggers when Cerebral adds a module is added.
app.on('moduleAdded', (path, module) => {})
Triggers when Cerebral removes a module.
app.on('moduleRemoved', (path, module) => {})
Triggered whenever Cerebral flushes out changes to the UI. Passes a map of changes.
app.on('flush', (changes) => {})
Triggered whenever Cerebral starts a sequence execution.
app.on('start', (execution, payload) => {})
Triggered whenever Cerebral ends a sequence execution.
app.on('end', (execution, payload) => {})
Triggered whenever Cerebral starts execution a path in a sequence
app.on('pathStart', (execution, payload) => {})
Triggered whenever Cerebral ends execution a path in a sequence
app.on('pathEnd', (execution, payload) => {})
Triggered whenever Cerebral starts executing an action.
app.on('functionStart', (execution, functionDetails, payload) => {})
Triggered whenever Cerebral ends executing an action.
app.on(
'functionEnd',
(execution, functionDetails, payload, result) => {}
)
Triggered whenever Cerebral executed an async action.
app.on('asyncFunction', (execution, functionDetails, payload) => {})
Triggered whenever Cerebral executes actions in parallel.
app.on(
'parallelStart',
(execution, payload, functionsToResolveCount) => {}
)
Triggered whenever Cerebral executes actions in parallel.
app.on(
'parallelProgress',
(execution, payload, functionsStillResolvingCount) => {}
)
Triggered whenever Cerebral ends executing actions in parallel.
app.on('parallelEnd', (execution, payload, functionsExecutedCount) => {})
Triggered whenever Cerebral travels back in time. Passes the timestamp it travelled to.
app.on('remember', (datetime) => {})
Triggered whenever Cerebral mutated the state
app.on('mutation', (mutation) => {})