Skip to content

Instantly share code, notes, and snippets.

View kylebuildsstuff's full-sized avatar

Kyle kylebuildsstuff

View GitHub Profile
// shared.ts
export const graphqlRequest = async <T>(
query: string,
variables = {},
): Promise<T> => {
const headers = {
...buildContentTypeHeader('application/json'),
};
import * as React from 'react';
import { Field, FormSection } from 'redux-form';
import IntlLink from '../../core/intl/intlLink/intlLink.container';
import { LOCATION } from '../../core/location/location.types';
import { IntlText } from '../../core/intl/intlText/intlText.container';
import { Input, Radio, Button, Icon, Text } from '../../components';
import { Address } from '../address/address.fieldset';
import { Name } from '../name/name.fieldset';
import {
import { createSelector, createStructuredSelector } from 'reselect';
import { getFormValues } from 'redux-form';
import { AppStateT, LoginStateT, FORM_NAMES, LOCATION } from '../../core/types';
import { selectPreviousPageType, selectKind } from '../../core/location/location.selectors';
export const selectLogin = (state: AppStateT) => state.login;
export const selectAuthenticated = createSelector(
selectLogin,
(loginState: LoginStateT) => loginState.authenticated
@kylebuildsstuff
kylebuildsstuff / .js
Created November 14, 2017 21:39
reselect example
import { path, find, propEq } from 'ramda';
import { createSelector } from 'reselect';
import {
AppStateT,
UserProfileT,
BusinessNameSearchesT,
BusinessNameSearchesSearchesT,
UserDetailsT,
PaymentOrderT,
BUSINESS_REGISTRATION_STATUS,
@kylebuildsstuff
kylebuildsstuff / .js
Created November 14, 2017 21:38
form selectors reselect
import { createStructuredSelector, createSelector } from 'reselect';
import { getFormValues } from 'redux-form';
import { FORM_NAMES } from '../../core/types';
export const selectBusinessNameRegistrationFormValues = createSelector(
getFormValues(FORM_NAMES.BUSINESS_NAME_REGISTRATION),
formValues => formValues
);
export const businessNameRegistrationFormConnector = createStructuredSelector({
import React from 'react';
import Link from '../Link.react';
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>
).toJSON();
expect(tree).toMatchSnapshot();
});
describe('loginSuccessEpic', () => {
it('dispatches actions to change location, authenticated, and stopSubmit', () => {
const action = ActionsObservable.of({
type: LOGIN_TYPES.SUCCESS,
payload: [{}, {}]
});
loginSuccessEpic(action, {})
.toArray()
.subscribe((outputActions) => {
expect(outputActions).toEqual([
export const loginSuccessEpic = (
action$,
store
) => action$
.ofType(LOGIN_TYPES.SUCCESS)
.mergeMap(() => {
return Observable.from([
location.createRouteChangeAction(
LOCATION.USER_DASHBOARD
),
// selectors.js
export const selectLogin = (state: AppStateT) => state.login;
export const selectAuthenticated = createSelector(
selectLogin,
(loginState: LoginStateT) => loginState.authenticated
);
// selectors.test.js
import { type } from 'ramda';
import { createSelector } from 'reselect'
const shopItemsSelector = state => state.shop.items
const subtotalSelector = createSelector(
shopItemsSelector,
items => items.reduce((acc, item) => acc + item.value, 0)
)
let exampleState = {