Skip to content

Instantly share code, notes, and snippets.

View slightlytyler's full-sized avatar
💭
🤓 codin'

Tyler Martinez slightlytyler

💭
🤓 codin'
  • Cat City
View GitHub Profile
@slightlytyler
slightlytyler / Filter.js
Created June 7, 2016 15:32
Example of component + container
import React, { Component, PropTypes } from 'react';
import { ALL, ACTIVE, COMPLETED } from 'src/constants';
class Filters extends Component {
static propTypes = {
currentFilter: PropTypes.oneOf([
ALL,
ACTIVE,
COMPLETED,
]).isRequired,
@slightlytyler
slightlytyler / webpack.config.js
Created June 9, 2016 17:57
Example of my prod webpack config
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const autoprefixer = require('autoprefixer');
const argv = require('yargs').argv;
const __src = path.join(__dirname, 'src');
export class SignupControl extends React.Component {
constructor(props) {
super(props)
this.handleSubmit = this.handleSubmit.bind(this)
}
handleSubmit(values) {
return new Promise ((resolve, reject) => {
this.props.actions.signup(values.name,
values.email,
let MAX = 10;
let COUNTER = 0;
export const increment = count => { count += 1 };
const myObject = {
myFn: () => {
increment(COUNTER);
if(condition) helpers.fn();
},
import * as actions from './actions';
const dispatch = spy();
const getState = () => ({
...your mocked state
});
describe('Action A', () => {
it('should dispatch a correctly formatted action', () => {
actions.actionA('first arg', 'second arg')(dispatch, getState);
@slightlytyler
slightlytyler / UserDetail.js
Last active September 20, 2016 20:50
An example of a UserDetail component
import React, { Component, PropTypes } from 'react'
export class UserDetail extends Component {
static propTypes = {
fetchUser: PropTypes.func.isRequired,
record: PropTypes.object,
}
componentWillMount() {
if (!this.props.record) this.props.fetchUser();
export const offerFormSubmitDecorator = Component => {
return connect(
state => ({ offerID: state.offer.get('pk') }),
dispatch => ({ patchOfferCall: (offerId, values) => dispatch(actions.patchOfferCall(offerId, values)) }),
(stateProps, dispatchProps) => ({
...stateProps,
onSubmit: values => dispatchProps.patchOfferCall(stateProps.offerId, values),
})
)
};
import { compliment, compose, get } from 'lodash/fp';
import { connect } from 'react-redux';
import { branch, renderComponent } from 'recompose';
const selectIsAuthenticated = state => ({
isAuthenticated: Boolean(state.currentUser),
});
const withAuth = compose(
connect(selectAuthorizationStatus),
schema {
query: Query
}
type Query {
accounts: AllAccountsConnection!
organizations: AllOrganizationsConnection!
users: AllUsersConnection!
}
// @flow
import { mount, shallow } from 'enzyme';
import enzymeSnapshotSerializer from 'enzyme-to-json/serializer';
import { noop } from 'lodash/fp';
import React from 'react';
import { snapshotSerializer as apolloSnapshotSerializer } from 'core/apollo';
import { snapshotSerializer as graphqlSnapshotSerializer } from 'core/graphql';
import renderApp from 'test/renderApp';
import Client from 'test/client';
import SearchBar, { InnerComponent, SEARCH_BAR_QUERY_DEF } from './SearchBar';