Skip to content

Instantly share code, notes, and snippets.

View bfillmer's full-sized avatar

Bryan Fillmer bfillmer

View GitHub Profile
@bfillmer
bfillmer / epic.js
Created August 5, 2016 02:59 — forked from shuhei/epic.js
An idea of side-effect-free epic like redux-saga for redux-observable
// Explicit in-out of side-effect actions.
function epic(action$, store) {
const fooReq$ = action$.ofType('FOO')
.map(action => call('FOO_REQ', webapi.getFoo, action.payload.id));
const foo$ = action$.ofType('FOO_REQ')
.map(foo => ({ type: 'FOO_FETCHED', payload: { foo } }));
return Observable.merge(
fooReq$,
foo$
@bfillmer
bfillmer / index.js
Created August 5, 2016 03:02 — forked from jonahwilliams/index.js
Redux with Rxjs
"use strict";
const Rx = require('rx');
const fetch = require('isomorphic-fetch'); /* use the fetch api on client and server */
/**
* Given a subreddit, pull down post ids. that is, changing the subreddit by calling terms$.onNext(SUBREDDITNAME)
* automatically calls the reddit api and populates the store.
* To try it out, npm install rx and isomorphic-fetch, then
* var S = require('./index.js');
* S.store$.subscribe(x => console.log(x)); // listen to every state change
@bfillmer
bfillmer / Proposal.md
Created August 5, 2016 03:04 — forked from luisherranz/Proposal.md
Proposal for a redux-like API on top of Mobx

I'd got rid of action types and I'd have only actions (action creators). No strings, the function (reference) is used later for comparisons.

export const addTodo = (id, title) => ({ id, title });
export const removeTodo = id => ({ id });
actions({ addTodo, removeTodo }); // Connect it to actions.addTodo & actions.removeTodo.

That's it. They define what your app can do.

@bfillmer
bfillmer / rxjs-saga.js
Created August 5, 2016 03:06 — forked from tomkis/rxjs-saga.js
rxjs-saga.js
import { createStore, applyMiddleware } from 'redux';
import { Observable, Subject } from 'rxjs';
const api = (url, fail) => {
console.log(`Loading API ${url}`);
return new Promise((res, rej) => setTimeout(() => fail ? rej(`data-${url}`) : res('SUCCESS'), 1000));
};
const customSaga = iterable =>
iterable
@bfillmer
bfillmer / standardJS-in-CRA.md
Created February 7, 2017 02:21 — forked from dreamorosi/standardJS-in-CRA.md
Add Standard JS to create-react-app project

Standard JS in create-react-app

I've been using create-react-app lately as I find it very useful to kick things off while starting a project. I almost always follow JavaScript Standard Style and I found myself googling it so I figured out I should write it down.

Get Standard JS

I really like keeping dependencies as local as possible but if you prefer you can install it globally.

yarn add standard -D

or

@bfillmer
bfillmer / .bash_profile
Last active August 1, 2017 16:18
Terminal Spring Cleaning
# ALIASES
# Atom
alias a='open -a "atom"'
# ls -la
alias la="ls -laFG"
# NORD COLORS (https://github.com/arcticicestudio/nord)
export RED="\033[1;31m"
export GREEN="\033[1;32m"
@bfillmer
bfillmer / musings.dockerfile
Last active August 1, 2017 17:05
Wordpress & MySQL Orchestration
# Possible MySQL dockerfile
FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD=<password>
EXPOSE 3306
# Possible WordPress dockerfile
FROM wordpress:latest
@bfillmer
bfillmer / recursive-array-flatten.js
Created January 18, 2018 16:45
Recursively Flatten an Array
// Expected input -> output
// [[1,2,[3]],4] -> [1,2,3,4]
const input = [[1,2,[3]],4]
const flatten = (array, base = []) => array.reduce(
(result, current) => ((Array.isArray(current)) ? flatten(current, result) : [...result, current])
, base)
// -> [1, 2, 3, 4]
console.log(flatten(input))
// Basic auth0 lock functionality written functionally rather than class based.
import auth0 from 'auth0-js'
const config = {
domain: '',
clientID: '',
redirectUri: '',
audience: '',
@bfillmer
bfillmer / machine.js
Last active May 21, 2020 18:10
Generated by XState Viz: https://xstate.js.org/viz
const dashboardMachine = Machine({
id: 'dashboardMachine',
initial: 'idle',
context: {},
states: {
idle: {
on: {
INIT: 'loadPreferences'
}
},