Skip to content

Instantly share code, notes, and snippets.

@10xjs
10xjs / action.js
Created May 4, 2016 21:41
Redux async fetch store enhancer
import {createFetchAction} from './fetch-enhancer';
const API_URL = 'api/v1/projects';
export const fetchProject = createFetchAction(
'FETCH_PROJECT',
'GET',
(id) => `${API_URL}/${id}`
);
import {parse, format} from "url";
import {join} from "path";
export const GET = { method: "GET" };
export const PUT = { method: "PUT" };
export const POST = { method: "POST" };
export const PATCH = { method: "PATCH" };
export const DELETE = { method: "DELETE" };
// -----------------------------------------------------------------------------
// lib code
const liftRequest = ([ req, res ]) => ({ req, res });
const liftError = ([ err, req, res ]) => ({ err, req, res });
const liftUpgrade = ([ req, socket, head ]) => ({ req, socket, head });
const unliftRequest = ({ req, res}) => [ req, res ];
const unliftError = ({ err, req, res }) => [ err, req, res ];
const unliftUpgrade = ({ req, socket, head }) => [ req, socket, head ];
const mapContextToError = ({ err, req, res }) => [ err, req, res ];
var syntax = [
// React
require("babel-plugin-syntax-flow"),
require("babel-plugin-syntax-jsx"),
// Object rest spread
require("babel-plugin-syntax-object-rest-spread"),
// Trailing function commas
require("babel-plugin-syntax-trailing-function-commas"),
@10xjs
10xjs / github.sh
Last active November 2, 2015 21:31
Open the github page for the current git repository in your browser
# Opens the github page for the current git repository in your browser
# Original credit to https://github.com/jasonneylon/
function gh() {
giturl=$(git config --get remote.origin.url)
if [ "$giturl" == "" ]
then
echo "Not a git repository or no remote.origin.url set"
return
fi
@10xjs
10xjs / name.js
Last active November 2, 2015 05:58
export function name(name) {
return enhancer => next => (reducer, initialState) => {
return {
...enhancer(next)(reducer, initialState),
name,
};
};
}
export function normalize(store) {
function ephemeral(
mapSetState = identity,
mapValue = identity,
computeKey = defaultComputeKey
) {
return Wrapped => wrapComponent(Wrapped => {
function retrieveEphemeralValue(state, key) {
return state[key];
}