Skip to content

Instantly share code, notes, and snippets.

@christianalfoni
christianalfoni / transition.js
Created August 26, 2015 18:27
transition group problems
import React from 'react';
import {Decorator as Cerebral} from 'cerebral-react';
import {CSSTransitionGroup} from 'react-addons';
import Home from './Home.js';
import Admin from './Admin.js';
@Cerebral({
title: ['title'],
currentPage: ['currentPage']
import Store from 'immutable-store';
// Any mutations to an immutable-store returns the new mutated store as a result of the operation.
// More info at: https://github.com/christianalfoni/immutable-store
export default function (state = Store({todos: []}), action) {
switch (action.type) {
case ADD_TODO:
return state.todos.push(action.payload);
case REMOVE_TODO:
@christianalfoni
christianalfoni / App.js
Last active August 29, 2015 14:25
How to nest with reactive router
import React from 'react';
import {Decorator as State} from 'cerebral-react-immutable-store';
import {views} from './constants.js';
import Home from './Home.js';
import Messages from './Messages.js';
@State({view: ['view']})
class App extends React.Component {
render() {
@christianalfoni
christianalfoni / context.js
Created February 5, 2016 08:46
FAQ: Why Cerebral does not provide context
/*
IT WAS SO NICE TO USE THE MODULE ARG
*/
// With context
function action ({module}) {
module.state.set('foo', 'bar');
}
// Now
var React = require('react')
var callbacks = []
var listener = false
module.exports = {
contextTypes: {
controller: React.PropTypes.object
},
componentWillMount: function () {
this.signals = this.context.controller.isServer ? {} : this.context.controller.getSignals()
var React = require('react')
var mixin = require('./mixin.js')
module.exports = function (Component, paths) {
return React.createClass({
displayName: Component.name + 'Container',
mixins: [mixin],
componentWillReceiveProps: function (nextProps) {
this._update(null, nextProps);
},
var React = require('react')
var callbacks = []
var listener = false
var currentUpdateLoopId = 0
module.exports = {
contextTypes: {
controller: React.PropTypes.object
},
var React = require('react')
var callbacks = []
var listener = false
var currentUpdateLoopId = 0
module.exports = {
contextTypes: {
controller: React.PropTypes.object
},
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),