Skip to content

Instantly share code, notes, and snippets.

const observables = {
count: 1,
computedFunc: () => {
return this.count + 1
}
}
const actions = {
increment: () => {
this.count += 1
import { observable } from 'mobx'
class UIStore {
@observable isSliderOpen = false;
@observable isAccountDropdownOpen = false;
constructor(state) {
Object.assign(this, state)
}
}
import { EditorState, Modifier, Entity, SelectionState } from 'draft-js'
import linkifyIt from 'linkify-it'
import tlds from 'tlds'
const linkify = linkifyIt()
linkify.tlds(tlds)
const linkifyEditorState = (editorState) => {
const contentState = editorState.getCurrentContent()
@jackcallister
jackcallister / Actions.js
Last active October 11, 2015 12:43
Nested Redux Updates
export function updateProp(value, path) {
return {
type: 'UPDATE_PROP',
payload: {
path,
value,
}
}
}
@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 (
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 / personActions.js
Created September 22, 2015 08:06
Validation Pattern
export function mapPersonStateToProps(store) {
const validationErrors = personValidator(store.person.editableResource)
return {
validationErrors: validationErrors,
...restOfPropsFromStore
}
}
@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 / 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 / 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 {