Skip to content

Instantly share code, notes, and snippets.

/** taken from https://aws-amplify.github.io/docs/js/authentication */
import { AsyncStorage } from '@react-native-community/async-storage';
import { Auth } from '@aws-amplify/auth';
const MEMORY_KEY_PREFIX = '@MyStorage:';
let dataMemory = {};
/** @class */
class MyStorage {
static syncPromise = null;
@anthonyjoeseph
anthonyjoeseph / typescript.json
Last active May 15, 2020 21:55
Opaque ADT Snippet
{
"Opaque ADT": {
"prefix": "oadt",
"body": [
"export const $1ADT = makeADT('type')({$2});",
"export type $1ADT = ADTType<typeof $1ADT>",
"export interface $1 extends Newtype<{ readonly $1: unique symbol }, $1ADT> {}",
"export const $1 = iso<$1>()"
],
"description": "Defines an opaque ADT"
@anthonyjoeseph
anthonyjoeseph / history-async.md
Last active May 21, 2020 20:50
Frontend Patterns 2020 - Case Study: Routing

1: rxjs, history-async

  • video
  • repo

2: react

  • video
  • repo

3: redux & react-redux

  • video
@anthonyjoeseph
anthonyjoeseph / SafeReducer.ts
Created June 1, 2020 03:32
Redux Reducer + morphic-ts
import { Reducer, Action } from "redux";
import { ADT } from '@morphic-ts/adt';
export const safeReducer = <A extends Action, S, tag extends keyof A & string>(
curriedReducer: (a: A) => (s: S) => S,
defaultState: S,
adt: ADT<A, tag>
): Reducer<S, A> => (
nullableState,
action
@anthonyjoeseph
anthonyjoeseph / GenerateClient.ts
Last active July 4, 2024 01:00
Typescript React + Express SSR
import serialize from 'serialize-javascript';
import path from 'path';
import fs from 'fs';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
export default <P>(
App: React.ReactElement<P>,
globalState: string | undefined,
): Promise<string> => new Promise((resolve, reject) => {
@anthonyjoeseph
anthonyjoeseph / SeatOptional.ts
Last active July 23, 2020 03:03
Composing Optionals across a Morphic ADT
import { pipe } from 'fp-ts/lib/pipeable'
import * as L from 'monocle-ts/lib/Lens'
import * as Op from 'monocle-ts/lib/Optional'
import { makeADT, ofType, ADTType } from '@morphic-ts/adt'
interface Bicycle {
type: 'Bicycle'
color: string
}
@anthonyjoeseph
anthonyjoeseph / PricingInfoRow.ts
Last active August 22, 2020 14:54
Fun(ctional) Programming in JS
import * as O from 'fp-ts/lib/Option'
import * as A from 'fp-ts/lib/Array'
import { sequenceS } from 'fp-ts/lib/Apply'
import { pipe } from 'fp-ts/lib/pipeable'
interface Money { currency: Currency; amount: number }
type PricingInfo = { effectiveDate: Date; price: Money; ticker: string }
enum Currency { USD = "USD", EUR = "EUR", JPY = "JPY", CHF = "CHF", GBP = "GBP", CAD = "CAD", AUD = "AUD", }
@anthonyjoeseph
anthonyjoeseph / reduxAttempt.ts
Last active October 24, 2020 14:46
Attempt at redux-immutable integration with @morphic-ts/adt
import { makeADT, ADTType, ofType } from '@morphic-ts/adt'
import { combineReducers } from 'redux-immutable';
import { Action, createStore, Reducer } from 'redux';
import * as Immutable from 'immutable'
interface Ignition { type: 'Ignition' }
interface Accelerate { type: 'Accelerate' }
interface Brake { type: 'Brake' }
const AppAction = makeADT('type')({
@anthonyjoeseph
anthonyjoeseph / PromiseLikeAdverb.ts
Created October 3, 2020 20:25
Accidental PromiseLike
interface PrintAdverb<T> {
then: <TResult1>(o: ((value: T) => PrintAdverb<TResult1>)) => PrintAdverb<TResult1>;
absolutely?: string;
positively?: string;
veryvery?: string;
necessary?: string;
}
const pa: PrintAdverb<string> = {
then: <TResult1>(o: ((value: string) => PrintAdverb<TResult1>)) => o('3')
}
@anthonyjoeseph
anthonyjoeseph / FpReduxExample.tsx
Last active April 19, 2022 08:08
Should I Use redux-observable fp-ts Example
import { pipe } from 'fp-ts/pipeable'
import * as O from 'fp-ts/Option'
import * as Op from 'monocle-ts/lib/Optional'
import * as r from 'rxjs'
import * as ro from 'rxjs/operators'
import { createStore, applyMiddleware } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
import React from 'react';
import { Provider, useDispatch, useSelector } from 'react-redux';
import { makeADT, ofType, ADTType } from '@morphic-ts/adt'