Skip to content

Instantly share code, notes, and snippets.

@kofno
kofno / scratch-pad.ts
Created December 15, 2018 16:17
Triggering Alerts
import alertsStore from '../alerts/store';
import { alert } from '../alerts/types';
alertsStore.push(alert("Those aren't valid credentials!", 'error'));
alertsStore.push(alert("You've successfully logged in", 'success'));
@kofno
kofno / content.tsx
Created December 15, 2018 15:41
Alert content for an Alert Snackbar
// -- 1 --
import { IconButton, SnackbarContent } from '@material-ui/core';
import { amber, green } from '@material-ui/core/colors';
import { createStyles, Theme, withStyles } from '@material-ui/core/styles';
import { ClassNameMap } from '@material-ui/core/styles/withStyles';
import CloseIcon from '@material-ui/icons/Close';
import React, { StatelessComponent } from 'react';
import alertsStore from './store';
import { Alert } from './types';
@kofno
kofno / index.tsx
Created December 14, 2018 20:56
Snackbar Alert component that reacts to changes in a MobX store
// -- 1 --
import Snackbar from '@material-ui/core/Snackbar';
import { observer } from 'mobx-react';
import React from 'react';
import AlertContent from './content';
import alertsStore from './store';
const Alerts = () => {
// -- 2 --
return alertsStore.current.cata({
@kofno
kofno / store.ts
Created December 14, 2018 19:46
MobX enhanced logic for Snackbar notifications
// - 1 -
import { just, Maybe, nothing } from 'maybeasy';
import { action, computed, observable } from 'mobx';
import { Alert } from './types';
class AlertsStore {
// - 2 -
@observable
alerts: Alert[] = [];
@kofno
kofno / types.ts
Created December 14, 2018 19:22
Alert types
interface BaseAlert {
message: string;
display: boolean;
}
export interface Success extends BaseAlert {
kind: 'success';
}
export interface Info extends BaseAlert {
@kofno
kofno / store.ts
Created December 14, 2018 16:33
Snackbar Implementation
import { just, Maybe, nothing } from 'maybeasy';
import { action, computed, observable } from 'mobx';
import { Alert } from './types';
class AlertsStore {
@observable
alerts: Alert[] = [];
@computed
get current(): Maybe<Alert> {
Configuring stack-1.7.0...
Preprocessing library for stack-1.7.0..
Building library for stack-1.7.0..
[ 1 of 129] Compiling System.Terminal ( src\windows\System\Terminal.hs, .stack-work\dist\ca59d0ab\build\System\Terminal.o )
[ 2 of 129] Compiling RIO.Prelude ( subs\rio\src\RIO\Prelude.hs, .stack-work\dist\ca59d0ab\build\RIO\Prelude.o )
[ 3 of 129] Compiling RIO.Logger ( subs\rio\src\RIO\Logger.hs, .stack-work\dist\ca59d0ab\build\RIO\Logger.o )
[ 4 of 129] Compiling RIO ( subs\rio\src\RIO.hs, .stack-work\dist\ca59d0ab\build\RIO.o )
[ 5 of 129] Compiling Path.Extra ( subs\rio\src\Path\Extra.hs, .stack-work\dist\ca59d0ab\build\Path\Extra.o )
[ 6 of 129] Compiling RIO.Process ( subs\rio\src\RIO\Process.hs, .stack-work\dist\ca59d0ab\build\RIO\Process.o )
[ 7 of 129] Compiling Stack.Prelude ( src\Stack\Prelude.hs, .stack-work\dist\ca59d0ab\build\Stack\Prelude.o )
@kofno
kofno / example.ts
Created September 25, 2017 13:25
Question about discriminated unions
// Given this
interface One {
kind: 'one';
value: 1;
}
interface Two {
kind: 'two';
value: 2;
@kofno
kofno / some-flow.js
Created August 5, 2017 14:57
leaked any example
// From the flow docs: https://flow.org/en/docs/types/any/#toc-avoid-leaking-any
// @flow
function fn(obj: any) /* (:any) */ {
let foo /* (:any) */ = obj.foo;
let bar /* (:any) */ = foo * 2;
return bar;
}
// returns an any type (implicitly)
@kofno
kofno / andThen.d.ts
Created June 25, 2017 17:21
bind signature
andThen<B>(f: (a: A) => Decoder<B>): Decoder<B>;