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 page from 'page' | |
| import pathToRegExp from 'path-to-regexp' | |
| import querystring from 'querystring' | |
| import HomePage from './components/HomePage' | |
| import ProfilePage from './components/ProfilePage' | |
| import NotFoundPage from './components/NotFoundPage' | |
| // generate expression for iterating over object keys | |
| function entries(obj) { |
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 fetch, { | |
| Response } from 'node-fetch'; | |
| import qs from 'querystring'; | |
| import WebSocket from 'ws'; | |
| class SimpleSlack { | |
| baseURL = 'https://slack.com/api/'; | |
| eventListeners = {}; | |
| connection = null; |
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
| // vars ending in $ are streams | |
| var flyd = require('flyd') | |
| var botkit = require('botkit') | |
| var controller = botkit.slackbot(/*...*/) | |
| var direct_message$ = flyd.stream() | |
| var conversation$ = flyd.stream() |
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
| findSomething((error, something) => { | |
| if (error) { | |
| throw new Error(error) | |
| } | |
| transformSomething(something, (error, transformed) => { | |
| if (error) { | |
| throw new Error(error) | |
| } | |
| validateTransformed(transformed, (error, validated) => { | |
| if (error) { |
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
| findSomething() | |
| .then((something) => transformSomething(something)) | |
| .then((transformed) => validateTransformed(transformed)) | |
| .then((validated) => console.log('data is valid:', validated) | |
| .catch((error) => console.error(new Error(error)) |
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
| findSomething() | |
| .then(transformSomething) | |
| .then(validateTransformed) | |
| .then((validated) => console.log('data is valid:', validated)) | |
| .catch((error) => console.error(new Error(error)) |
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 getValidatedTransformation = sequentialCallback( | |
| findSomething, | |
| transformSomething, | |
| validateTransformed | |
| ) | |
| getValidatedTransformation((error, validated) => { | |
| if (error) { | |
| console.error(new Error(error)) | |
| } else { |
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 validateTransformation = sequentialCallback( | |
| transformSomething, | |
| validateSomething | |
| ) | |
| const something = { foo: 'bar' } | |
| validateTransformation(something, (error, validated) => { | |
| if (error) { | |
| console.error(new Error(error)) |
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 validateTransformation = sequentialCallback( | |
| transformSomething, | |
| validateTransformed, | |
| (validated, callback) => callback(null, validated, 'data is valid:') | |
| ) | |
| validateTransformation({ foo: 'bar' }, (error, validated, label) => { | |
| if (error) { | |
| console.error(new Error(error)) | |
| } else { |
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 sequentialCallback (...fns) { | |
| return (...args) => { | |
| const done = args.pop() | |
| const next = (error, ...args) => { | |
| if (error) return done(error) | |
| if (fns.length) { | |
| const fn = fns.shift() | |
| return fn(...args, next) | |
| } | |
| return done(null, ...args) |