Skip to content

Instantly share code, notes, and snippets.

View baetheus's full-sized avatar

Brandon Blaylock baetheus

View GitHub Profile
@baetheus
baetheus / maxCountDuringPeriod.ts
Last active May 26, 2019 20:30
rxjs: maxCountDuringPeriod
/**
* maxCountDuringPeriod
*/
export const maxCountDuringPeriod = (count: number, period: number) => (obs: Observable<any>) => {
if (count < 2) {
throw new Error('maxCountDuringPeriod count must be greater than or equal to 2');
}
if (period < 0) {
throw new Error('maxCountDuringPeriod period must be positive');

Keybase proof

I hereby claim:

  • I am baetheus on github.
  • I am baetheus (https://keybase.io/baetheus) on keybase.
  • I have a public key ASCazPD8JqHVme4Inlk1UFORaPUcRKxU-XNuMjjhClrJfwo

To claim this, I am signing this object:

@baetheus
baetheus / input-interfaces.ts
Created January 24, 2019 21:36
Potential Input State Interfaces
export interface InputState<ValueType, MaskType> {
value: ValueType;
mask: MaskType; // TODO Decide on masking implementation
touched: boolean;
invalid: boolean;
focused: boolean;
disabled: boolean;
}
export enum InputEvents {
@baetheus
baetheus / router.tsx
Last active January 20, 2019 01:35
React Redux Router POC
import * as React from 'react';
import { SFC } from 'react';
import { useRedux } from '~/store';
import { currentRoute, Routes } from '~/stores/routing';
import { Campaign } from './pages/Campaign';
import { Dashboard } from './pages/Dashboard';
export interface RouterProps {}
@baetheus
baetheus / campaigns.ts
Created January 18, 2019 19:46
Example action + reducer + lens + epic
/**
* Get Campaigns
*/
export const getCampaigns = contactStrategyActionFactory.async<number, Campaign[], Error>('GET_CAMPAIGNS');
export const campaignsLens = Lens.fromProp<ContactStrategyStore, 'campaigns'>('campaigns');
const getCampaignsReducer = reducerFactory(getCampaigns, campaignsLens);
const getCampaignsEpic: Epic = a$ =>
a$.pipe(
filterSwitchAsync(getCampaigns, companyId => from(GetCampaigns({ companyId }).then(({ campaigns }) => campaigns)))
@baetheus
baetheus / tasks.json
Created January 17, 2019 01:25
vscode tasks for schematics-react
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
// Run npm start as default build script (cmd + shift + b)
{
"label": "start",
"type": "npm",
"script": "start",
@baetheus
baetheus / app.tsx
Last active December 12, 2022 19:13
Preact Hooks Experiment for Typescript
import { h, FunctionalComponent, render, options } from 'preact';
import { handleVnode } from './hooks';
// Wireup experimental hooks
options.vnode = handleVnode;
import Test from './component';
export const Main: FunctionalComponent<any> = () => (
@baetheus
baetheus / map.pipe.ts
Created January 8, 2019 09:01
Method Overload Issues
import { Pipe, PipeTransform } from '@angular/core';
import { map } from 'lodash';
import { tryCatchEither } from '@loda/utils';
interface MapTransform {
<T, D>(value: T, iteratee: (t: T) => D): D | T;
<T, D>(value: T[], iteratee: (t: T) => D): D[] | T[];
}
@baetheus
baetheus / rollup.config.js
Last active January 14, 2019 23:50
Rollup + Typescript + Serve + Preact
import del from 'rollup-plugin-delete';
import typescript from 'rollup-plugin-typescript';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import htmlTemplate from 'rollup-plugin-generate-html-template';
import copy from 'rollup-plugin-copy';
import serve from 'rollup-plugin-serve';
import { terser } from 'rollup-plugin-terser';
const createHash = () =>
@baetheus
baetheus / index.html
Last active November 21, 2018 21:49
Parcel React Typescript Setup
npm i @nll/{css,rx-fsa} lodash react react-dom redux
npm i -D @nll/schematics-react @types/{lodash,node,react,react-dom,redux} parcel-bundler typescript