Skip to content

Instantly share code, notes, and snippets.

View morrissinger's full-sized avatar

Morris Singer morrissinger

View GitHub Profile
@morrissinger
morrissinger / index.js
Created March 24, 2017 02:14
Dependency inversion in JavaScript with Curry
// Import actual dependencies
const dependency1 = require('dependency1'),
dependency2 = require('dependency2');
const myExport = require('./my-export.js')(dependency1, dependency2);
/* Do something */
@morrissinger
morrissinger / app.js
Last active February 21, 2016 03:52
Testing behavior in Express
import express from "express"
import {behavior1} from "./behavior.js"
var app = express();
app.use(function (req, res, next) {
behavior1()
.then(res.send.bind(res))
.catch(next);
});
@morrissinger
morrissinger / app.js
Last active February 21, 2016 03:55
Testing behavior in Koa
import koa from "koa"
import {behavior1} from "./behavior.js"
var app = koa();
app.use(function* (next) {
this.body = yield behavior1();
return yield next;
});
@morrissinger
morrissinger / application-controller.js
Created June 3, 2015 00:46
Angular 1 with ECMAScript 6, JSPM, and SystemJS
export class ApplicationController {
constructor() {
this.foo = 'bar';
}
}
@morrissinger
morrissinger / app.js
Last active August 29, 2015 14:06
Structuring Express Applications for Readability, Unit Testability: Promise Behavior; Tie Routes to Promise States; Test Promise Resolutions
//Tie Routes to Promise States
var middleware = require('./middleware.js');
app.get('example/uri', function(req, res, next) {
middleware(req, res)
.then(function() { next(); })
.catch(res.json)
.done();
});