Skip to content

Instantly share code, notes, and snippets.

@rbinksy
rbinksy / updating-objects.test.ts
Last active July 18, 2021 09:24
Updating nested objects in Typescript
import { Lens } from 'monocle-ts';
import { id, prop, modify } from 'monocle-ts/Lens';
import { pipe } from 'fp-ts/function';
import { merge, set, cloneDeep } from 'lodash/fp';
import produce from 'immer';
interface Street {
num: number;
name: string;
}
@rbinksy
rbinksy / squash-and-merge-cli.md
Created July 15, 2021 09:19 — forked from aortbals/squash-and-merge-cli.md
Squash and Merge on the Command line

With the introduction of GitHub's Squash and Merge feature, this has become less prevelant, however it's still useful in scenarios where GitHub's interface is unavailable.

Let's talk through two ways to do a squash and merge on the command line.

Take 1: Interactive Rebase

When to use it

  • When you have not merged master into your feature branch
  • There are no merge conflicts
import React from 'react';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import { render } from '@testing-library/react';
import reducer from '../../reducers';
export const renderWithRedux = (component, initialState) => {
const store = createStore(reducer, initialState);
return {
...render(<Provider store={store}>{component}</Provider>),
import React from 'react';
import { Status } from './Status';
import renderWithRedux from 'utils/renderWithRedux';
test('When monster takes damage, show success message', () => {
const { getByText } = renderWithRedux(<Status />, {
monster: { damageTaken: 2 }
});
expect(getByText('You hit for 2!'));
});
import React from 'react';
import { Healthbar } from './Healthbar';
import { render } from '@testing-library/react';
test('show current health', () => {
const { getByText } = render(
<Healthbar position="left" playerName="Example Name" health={32} />
);
expect(getByText('32'));
});
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import rollDice from 'utils/rollDice';
import {
initialState,
monsterActions,
monsterReducer,
monsterAttack,
getMonsterIsAttacking,
getMonsterDamage,
requestedAction: ['NOTACTIONED'],
inProgressAction: ['REQUESTED'],
deliveredAction: ['INPROGRESS'],
fulfilledAction: ['DELIVERED'],
notRequiredAction: ['NOTACTIONED'],
cancelledAction: ['REQUESTED', 'INPROGRESS', 'DELIVERED'],
editDatesAction: ['REQUESTED', 'INPROGRESS', 'DELIVERED', 'FULFILLED'],
editRequestDateAction: ['REQUESTED', 'FULFILLED'],
editFulfilledDateAction: ['FULFILLED'],
editRequiredByAction: ['REQUESTED', 'INPROGRESS']
@rbinksy
rbinksy / gist:b50a3d5e9a12569142dcc38c489d083a
Created February 20, 2019 16:12
Higher Order Reducer Example
import {
IAssetRequestRecord,
RequestType
} from 'records/typescript/AssetRequest';
import { createSelector } from 'reselect';
import sortByDate from 'utils/sortByDate';
import sortAlphbeticReverse from 'utils/sortAlphbeticReverse';
import withAssetRequestsReducer, {
getAssetRequests,
initialAssetRequestsState,
export default function withAssetRequestsReducer(originalReducer, reducerName) {
const actionTypes = {
FETCH_START: `${reducerName}/FETCH_START`,
FETCH_SUCCESS: `${reducerName}/FETCH_SUCCESS`,
FETCH_FAILURE: `${reducerName}/FETCH_FAILURE`,
UPDATE_START: `${reducerName}/UPDATE_START`,
UPDATE_SUCCESS: `${reducerName}/UPDATE_SUCCESS`,
UPDATE_FAILURE: `${reducerName}/UPDATE_FAILURE`,
NEXT_PAGE: `${reducerName}/NEXT_PAGE`,
@rbinksy
rbinksy / saga.tsx
Created December 13, 2018 17:54
Front end version of batching.
//usage
yield call(batchLoad, assetRequests.assets);
function* batchLoad(assetReqs, offset = 0) {
yield put({
type: ActionTypes.FETCH_ASSETREQUESTS_SUCCESS,
payload: fromJS(assetReqs)
.slice(offset, offset + 20)
.reduce(convertToMapBy('id'), Map())
.map(AssetRequest)