How to use the cerebral.Controller function in cerebral

To help you get started, we’ve selected a few cerebral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cerebral / cerebral / packages / codemods / 1.x-2.x / __testfixtures__ / controller.output.js View on Github external
/* eslint-disable */
import {Controller} from 'cerebral'

import Home from './modules/Home'
import Admin from './modules/Admin'
import doSomething from './chains/doSomething'

const controller = Controller({
  state: {
    // You can add some initial state here if you want
    foo: 'bar'
  },

  modules: {
    home: Home(),
    admin: Admin()
  },

  signals: {
    buttonClicked: doSomething
  }
})

export default controller
github cerebral / cerebral / packages / codemods / 1.x-2.x / __testfixtures__ / controller.input.js View on Github external
/* eslint-disable */
import {Controller} from 'cerebral'
import Model from 'cerebral/models/immutable'

import Home from './modules/Home'
import Admin from './modules/Admin'
import doSomething from './chains/doSomething'

const controller = Controller(Model({
  // You can add some initial state here if you want
  foo: 'bar'
}))

controller.addModules({
  home: Home,
  admin: Admin
})

controller.addSignals({
  buttonClicked: doSomething
})

export default controller
github zeit / next.js / examples / with-cerebral / pages / other.js View on Github external
constructor(props) {
    super(props)
    // The controller will be instantiated for every page change and we only
    // add the devtools if we indeed are running in the browser
    this.controller = Controller({
      devtools:
        process.env.NODE_ENV === 'production' || typeof window === 'undefined'
          ? null
          : Devtools({ host: 'localhost:8787' }),
      modules: { clock },
      stateChanges: props.stateChanges,
    })
  }
  render() {
github zeit / next.js / examples / with-cerebral / pages / index.js View on Github external
constructor(props) {
    super(props)
    // The controller will be instantiated for every page change and we only
    // add the devtools if we indeed are running in the browser
    this.controller = Controller({
      devtools:
        process.env.NODE_ENV === 'production' || typeof window === 'undefined'
          ? null
          : Devtools({ host: 'localhost:8787' }),
      modules: { clock },
      stateChanges: props.stateChanges,
    })
  }
  render() {
github cerebral-legacy / cerebral-addons / test / helpers / controller.js View on Github external
import { Controller } from 'cerebral'
import Model from 'cerebral/models/immutable'

const model = Model({})
const controller = Controller(model)
controller.model = model
controller.reset = () => {
  model.tree.set({})
  model.tree.commit()
}

export default controller
github cerebral-legacy / cerebral-module-router / tests / browser.js View on Github external
setUp: function (cb) {
    var controller = this.controller = Controller(Model({}))
    addressbar.value = '/'

    this.createRouteTest = function createRouteTest (options) {
      if (this.router) {
        throw new Error('Router instance must be detached by `tearDown` script. Do not call `createRouteTest` twice inside one test.')
      }

      var doesMatch = false
      var defaultPrevented = false
      var routerOptions = options.options || {}
      routerOptions.preventAutostart = true

      controller.addSignals({
        match: {
          chain: [ function setMatch () { doesMatch = true } ],
          immediate: true
github cerebral-legacy / cerebral-module-router / tests / node.js View on Github external
module.exports['should work in node.js'] = function (test) {
  var controller = Controller(Model({}))
  controller.addSignals({
    'test': {
      chain: [ function checkAction (input) { test.ok(true) } ],
      immediate: true
    }
  })

  controller.addModules({
    router: Router({
      '/test': 'test'
    })
  })

  var router = controller.getServices().router

  router.trigger()
github christianalfoni / cerebral-react-immutable-store / index.js View on Github external
var Factory = function (state, defaultArgs) {

  var eventEmitter = new EventEmitter();
  var initialState = Store(state);

  state = initialState;

  var controller = cerebral.Controller({
    defaultArgs: defaultArgs,
    onReset: function () {
      state = initialState;
    },
    onGetRecordingState: function () {
      return state.export();
    },
    onSeek: function (seek, isPlaying, currentRecording) {
      state = state.import(currentRecording.initialState);
      eventEmitter.emit('change', state);
    },
    onUpdate: function () {
      eventEmitter.emit('change', state);
    },
    onRemember: function () {
      eventEmitter.emit('remember', state);
github cerebral / cerebral-debugger / src / components / Debugger / index.js View on Github external
apps: ports.reduce((apps, port) => {
          apps[port] = Object.assign(storedApps[port], {
            controller: Controller(
              app({
                port,
                type: storedApps[port].type,
                ssl: storedApps[port].ssl,
              })
            ),
          })

          return apps
        }, {}),
        currentPort: currentPort || ports[0] || null,
github cerebral / cerebral / packages / tutorial / DO_NOT_TOUCH / 02 / src / index.js View on Github external
import React from 'react'
import {render} from 'react-dom'
import {Controller} from 'cerebral'
import {Container} from 'cerebral/react'
import Devtools from 'cerebral/devtools'
import App from './components/App'

const controller = Controller({
  devtools: Devtools(),
  state: {
    title: 'Hello from Cerebral!'
  }
})

render((
  
    
  
  ), document.querySelector('#root'))

cerebral

A state controller with its own debugger

MIT
Latest version published 5 years ago

Package Health Score

48 / 100
Full package analysis

Popular cerebral functions