Skip to content

Instantly share code, notes, and snippets.

Kyle Truong KTruong008

Block or report user

Report or block KTruong008

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:17097a1d57c3601744c6979830c401d8
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 {
View gist:09e7839fb22b2f0833a4512ce6d4549c
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
@KTruong008
KTruong008 / .js
Created Nov 14, 2017
reselect example
View .js
import { path, find, propEq } from 'ramda';
import { createSelector } from 'reselect';
import {
AppStateT,
UserProfileT,
BusinessNameSearchesT,
BusinessNameSearchesSearchesT,
UserDetailsT,
PaymentOrderT,
BUSINESS_REGISTRATION_STATUS,
@KTruong008
KTruong008 / .js
Created Nov 14, 2017
form selectors reselect
View .js
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({
View snapshot.example.js
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();
});
View epic.test.js
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([
View epic.js
export const loginSuccessEpic = (
action$,
store
) => action$
.ofType(LOGIN_TYPES.SUCCESS)
.mergeMap(() => {
return Observable.from([
location.createRouteChangeAction(
LOCATION.USER_DASHBOARD
),
View selectors.example.test.js
// 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';
View reselect.example.js
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 = {
View reducer.js
// reducer.js
export const initialState = {
authenticated: false,
authenticating: false,
};
export const loginReducer = (
state = initialState,
action
) => {
You can’t perform that action at this time.