This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postComments(state = [], action) { | |
switch(action.type) { | |
case 'LOAD_COMMENTS' : | |
return action.comments; | |
case 'ADD_COMMENT': | |
return [...state, { | |
user : { username: action.author }, | |
text : action.comment | |
}]; | |
case 'REMOVE_COMMENT': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mapValues(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
result[key] = fn(obj[key], key); | |
return result; | |
}, {}); | |
} | |
function pick(obj, fn) { | |
return Object.keys(obj).reduce((result, key) => { | |
if (fn(obj[key])) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Written by @iclanzan | |
// All credit goes to him! | |
// You create the reducer like this: | |
// var reducer = createTimelineReducer('someName', someReducer, ['foo', 'bar']); | |
// And then whenever an action of type `foo` or `bar` happens it calls `someReducer` and adds the result to the timeline. | |
// Then to undo/redo you trigger an action of type `someNameUndo`/`someNameRedo`. | |
var defaults = require('lodash/object/defaults'); | |
var capitalize = require('lodash/string/capitalize'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux'; | |
import { provide, connect } from 'react-redux'; | |
import thunk from 'redux-thunk'; | |
const AVAILABLE_SUBREDDITS = ['apple', 'pics']; | |
// ------------ | |
// reducers | |
// ------------ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// App.js | |
import { Provider, Connector } from 'redux/react'; | |
import monitor from './monitor/index'; | |
const store = composeStores(stores); | |
const { dispatcher, ActionLog } = monitor(createDispatcher(store)); | |
const redux = createRedux(dispatcher); | |
export default class App { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------ | |
// counterStore.js | |
// ------------ | |
import { | |
INCREMENT_COUNTER, | |
DECREMENT_COUNTER | |
} from '../constants/ActionTypes'; | |
const initialState = { counter: 0 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Stores are just seed + reduce function. | |
* Notice they are plain objects and don't own the state. | |
*/ | |
const countUpStore = { | |
seed: { | |
counter: 0 | |
}, | |
reduce(state, action) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
// Usage: | |
// | |
// @Stateful({ | |
// initialize(props) { | |
// return { | |
// count: 0 | |
// }; | |
// }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { configureDragDrop, configureDragDropContext } from 'react-dnd'; | |
import HTML5Backend from 'react-dnd/modules/backends/HTML5'; | |
// Note: @configureDragDropContext is called a “decorator”. | |
// This desugars roughly as class App { ... } App = configureDragDropContext(HTML5Backend)(App); | |
// You can enable decorators by putting { "stage": 1 } in your .babelrc. | |
@configureDragDropContext(HTML5Backend) | |
export default class App extends React.Component { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
getInitialState() { | |
const data = {}; | |
this.subscribe(this.props, this.context, (key, value) => { | |
data[key] = value; | |
}); | |
this.unsubscribe(); | |
return { data }; |