Skip to content

Instantly share code, notes, and snippets.

class MyForm extends Component {
constructor() {
super();
this.state = {
value: "Hello!"
}
//bindings here
}
// action types
const ADD_ACCOUNT = "ADD_ACCOUNT";
// action
const addAccountAction = {
type: ADD_ACCOUNT,
title: "Account title",
createdBy: "admin"
};
// action types
// import types from 'actionTypes.js'
function accounts(state = [], action) {
switch(action.type) {
case types.ADD_ACCOUNT:
return [
...state,
{
id: getNewId(), //fake method that returns new ID
/*
expected state:
{
accounts: {
items: []
isFetching: boolean
fetchingErrorMessage: string
}
}
// import { createStore, applyMiddleware, compose } from 'redux';
// import rootReducer from '../rootReducer';
// import createLogger from "redux-logger";
// import thunkMiddleware from "redux-thunk";
const loggerMiddleware = createLogger();
const initialState = {
someProperty: []
};
export const fetchAllStart = () => {
return {
type: constants.FETCH_ALL
};
};
export const fetchAllSuccess = (items) => {
return {
type: constants.FETCH_ALL_SUCCESS,
items
class MyComponent extends Component {
render() {
return <input ref={(element) => this._input = element} />;
}
componentDidMount() {
this._input.focus();
}
class Button extends React.Component {
render() {
return <button style={{background: this.context.color}}> {this.props.children}</button>;
}
}
Button.contextTypes = {
color: React.PropTypes.string
};
/*
import {connect} from "react-redux";
import * as actions from "./actions";
import LoginForm from "./components/LoginForm";
*/
export class Login extends Component {
render() {
return (
const restify = require("restify");
// create server instance
const server = restify.createServer();
// use plugins to parse body and query string of incoming requests
server.use(restify.plugins.queryParser());
server.use(restify.plugins.bodyParser());
// start listening