This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const glob = require('glob'); | |
const express = require('express'); | |
const Bottle = require('bottlejs'); | |
const bottle = new Bottle(); | |
// traverse the file system, passing this bottle to every javascript file we find | |
glob.sync(path.join(path.resolve(__dirname), 'app/**/*.js')).forEach((match) => { | |
require(match)(bottle); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chai = require('chai'); | |
chai.use(require('sinon-chai')); | |
const sinon = require('sinon'); | |
describe('controller.Pdfs', () => { | |
var bottle, generate, res; | |
beforeEach(() => { | |
res = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Factory | |
function createPdfsController(PdfService) { | |
return { | |
create: function(req, res, next) { | |
const content_id = req.params.content_id; | |
const pdf_id = PdfService.generate(content_id); | |
res.json({ pdf_id: pdf_id }); | |
} | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fetchSomething(thingId) { | |
return (dispatch) => { | |
// update call metadata | |
dispatch(startRequest(thingId)) | |
return fetch(`https://api.example.com/things/${thingId}`) | |
.then((response) => response.json()) | |
// send the result of the call, probably updating the request metadata as well | |
.then((json) => dispatch(receiveAThing(json))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { takeLatest } from 'redux-saga' | |
import { call, put } from 'redux-saga/effects' | |
function* fetchThing(action) { | |
try { | |
const thing = yield call(fetch, `https://api.example.com/things/${action.payload.thingId}`); | |
yield put({ type: "THING_RECEIVED", thing }); | |
} catch(err) { | |
yield put({ type: "THING_GETTING_FAILED", message: err.message}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make sure not to bind this function before passing it as onUpdate | |
// to Router below since it will be called with this set to the Router | |
// instance. | |
function onLocationChange() { | |
doSomethingInterestingWithPath(this.state.location.pathname); | |
} | |
... | |
<Router routes={routes} onUpdate={onLocationChange} /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.config = { | |
framework: 'custom', | |
frameworkPath: './lib/protractor-require-framework.js', | |
seleniumAddress: 'http://localhost:4444/wd/hub', | |
specs: ['automation/some-protractor-script.js'], | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Ruby has these nice case expressions, but switches are statements in JS. | |
* Here's a little convention to make switch statements look a little more like expressions. | |
* | |
* This uses ES6, but of course you could do it with ES5 as well. This pattern is especially | |
* nice in ES6, however, especially when you want to use const instead of let or var. | |
*/ | |
const output = (() => { | |
switch(input) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const foo = (a) => { | |
// x will stay 1 forevar | |
const x = 1 | |
if (a === 1) { | |
// this declaration of y is scoped only to this block | |
const y = 3 | |
// both x and y are defined here, as you'd expect | |
console.log('x', x) // x 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assignLater = (a) => { | |
const x | |
if (a === 1) { | |
x = 1 // XXX nope, must assign at declaration time | |
} else { | |
x = 2 // XXX nope, must assign at declaration time | |
} | |
} |