Skip to content

Instantly share code, notes, and snippets.

import Flux from './Flux.js'
import Flux from './components/App.jsx'
// Within document ready
const payload = document.getElementById('payload');
const flux = new AppFlux();
flux.serialize(payload);
import { createAction } from 'redux-actions';
import * as WebUtils from '../webUtils/index';
import {
SELECT_MEAL,
UPDATE_MEAL_PROP,
BEGIN_CREATING_MEAL,
SUCCESS_CREATING_MEAL,
ERROR_CREATING_MEAL,
BEGIN_LOADING_MEALS,
// The Redux Store
{
posts : [{
...stuff,
userId: 1
tagIds: [1,2,3]
}],
users: [{
...stuff,
@jackcallister
jackcallister / App.jsx
Created September 6, 2015 17:13
Redux Router Reducer
import {
updateRouterState
} from '../actions/RouterActions';
function mapStateToProps(store) {
return {}
}
function mapDispatchToProps(dispatch) {
return {
@jackcallister
jackcallister / awesome.jsx
Created September 12, 2015 13:00
Redux Refactor
import React from 'react'
import Header from '../components/people/PeopleHeader'
import Footer from '../components/people/PeopleFooter'
import Filtering from '../components/people/FilteringConnector'
import Toolbar from '../components/people/PeopleToolbarConnector'
import Table from '../components/people/PeopleTableConnector'
import EmptyBar from '../components/people/PeopleEmptyBarConnector'
export default class People {
@jackcallister
jackcallister / connector.js
Created September 12, 2015 13:05
Look ma no state
import React from 'react';
import { connect } from 'react-redux';
import { mapPeopleToolbarStateToProps } from '../../../selectors/peopleSelector';
import PeopleToolbar from './PeopleToolbar';
class PeopleToolbarConnector {
render() {
return (
<PeopleToolbar {...this.props} />
@jackcallister
jackcallister / compiler.js
Created September 12, 2015 13:08
Mocha Local Module CSS Compiler
require('babel/register');
// Extend to use css-modules server compiler.
// This will resolve JS objects rather than nothing, thus fixing
// nested object use - styles.thing.otherThing
require.extensions['.css'] = function (module, filename) {
return {}
}
@jackcallister
jackcallister / personActions.js
Created September 22, 2015 08:06
Validation Pattern
export function mapPersonStateToProps(store) {
const validationErrors = personValidator(store.person.editableResource)
return {
validationErrors: validationErrors,
...restOfPropsFromStore
}
}
export function beginCreatingAttachment(attachment, type) {
return function(dispatch) {
const file = attachment.file
delete attachment.file
return AttachmentWebUtils.postAttachmentForAWSCredentials(attachment).then((response) => {
const s3Data = response.uploadSignature.fields
const url = response.uploadSignature.host
const attachmentId = response.id
@jackcallister
jackcallister / dumb.jsx
Created September 29, 2015 13:43
Smart Dumb Pattern
import React, { PropTypes } from 'react'
export default class Dumb {
static propTypes = {
...
}
render() {
return (