Skip to content

Instantly share code, notes, and snippets.

function ModulesProvider(context, execution, controller) {
var modules = controller.getModules();
var services = controller.getServices();
context.modules = Object.keys(modules).reduce(function (contextModules, key) {
var modulePath = key.split('.');
var module = modulePath.reduce(function (contextModules, pathKey) {
contextModules[pathKey] = contextModules[pathKey] || {};
return contextModules[pathKey];
}, contextModules);
module.meta = modules[key];
@christianalfoni
christianalfoni / appMounted.js
Last active May 6, 2016 12:29
Redux ActionTree middleware
import {signal, dispatch} from 'redux-action-tree';
import {SET_LOADING, SET_DATA, UNSET_LOADING, SET_ERROR} from 'constants';
import getData from 'actions/getData';
// Use a signal factory to create a signal
export default signal([
// The dispatch factory allows you to easily dispatch actions. The current payload is always passed.
// Giving {type: "SET_LOADING", payload: {}} as action
dispatch(SET_LOADING),
[
someAction,
someOtherAction,
[
async1, {
success: [],
error: []
},
async2, {
success: [],
const Container = React.createClass({
displayName: 'CerebralContainer',
childContextTypes: {
state: React.PropTypes.object.isRequired,
signals: React.PropTypes.object.isRequired
},
getChildContext: function () {
return {
state: this.props.controller.getModel().tree,
signals: this.props.controller.getSignals()
import React from 'react';
export default React.createClass({
displayName: 'CerebralContainer',
childContextTypes: {
tree: React.PropTypes.object.isRequired
},
getChildContext: function () {
return {
tree: this.props.tree

Why we dropped immutability

In this article I will talk about the story of why Cerebral went from using immutability and then later decided to drop it.

So lets first align our thoughts on what immutability is. JavaScript has no concept of immutability. Any object or array is passed around the code by reference and you can mutate them wherever you want. That means any objects or arrays you create and pass around will look the same in any part of your code, because it is the same object/array.

With immutability you can still pass objects and arrays around your code by reference, but when you make a change to them you will always create a new object or array.

/*
# OPERATORS
copy
toggle
set
unset
when
throttle
debounce
filter
var inquirer = require('inquirer');
var currentView = 'React';
var currentModel = 'Immutable';
var currentModules = ['Devtools']
function main() {
inquirer.prompt([{
type: 'list',
name: 'main',
  • Initially Cerebral was using arrays to point to paths. We have now come to the conclusion that ES2015 template literals strings are more clean and efficient.
// Recommended
state.set('some.path', 'foo')

// Will be deprecated in later version
state.set(['some', 'path'], 'foo')

cerebral-module-whatever

Go to official README to read more technical details.

Concept

This module lets you create rainbows and butterflies in your signals.

Use module

...