Skip to content

Instantly share code, notes, and snippets.

View ctrlplusb's full-sized avatar
📢

Sean Matheson ctrlplusb

📢
View GitHub Profile
/* This is intentionally blank just and exists to secure a decent gist name */
@ctrlplusb
ctrlplusb / tCheck.js
Created January 20, 2016 21:56
Using tcomb to type check your functions without annotations.
import { isType } from 'tcomb';
/**
* (...values) => (...types) => value||[values]
*
* This is a curried function to help with type checking your javascript.
* It is curried in two parts, the first part taking the values that you
* wish to type check, the second part of the curry takes the types you wish
* to validate them with.
*
@ctrlplusb
ctrlplusb / 00_Simple_dependency_management_for_tests_etc
Last active February 24, 2016 11:48
NodeJS simple dependency management for modules.
// This gist illustrates a very simple strategy of declaring and exposing
// dependencies for your modules. Allowing them to be overridden for
// tests (or other), and providing a mechanism to restore the original
// dependencies.
// It's a work in progress, is very simple and naive, but its a simple
// mechanism to achieve required results without having to depend on
// any complex DI frameworks.
// This is a basic demonstration of using mockery alongside mocha/chai
// for unit testing in node.
@ctrlplusb
ctrlplusb / superagent-mock-example.js
Last active July 1, 2020 07:38
Stripped down and basic example of testing superagent based code using superagent-mock and mocha.
import { expect } from 'chai';
import superagent from 'superagent';
import mockSuperagent from 'superagent-mock';
import * as Errors from '../../../common/utils/errors';
// Under test.
import login from './login';
describe(`login api`), () => {
const serverEndPoint = `http://foobar.com/login`;
@ctrlplusb
ctrlplusb / easy-peasy.js
Last active November 5, 2018 20:05
Easy Peasy Primary API
import { StoreProvider, createStore, useStore, useAction } from 'easy-peasy';
// 👇 firstly, create your store by providing your model
const store = createStore({
todos: {
items: ['Install easy-peasy', 'Build app', 'Profit'],
// 👇 define actions
add: (state, payload) => {
state.items.push(payload) // 👈 you mutate state to update (we convert
// to immutable updates)
@ctrlplusb
ctrlplusb / install.sh
Last active November 6, 2018 09:02
Install easy-peasy
npm install easy-peasy
@ctrlplusb
ctrlplusb / model.js
Created November 5, 2018 17:52
Easy peasy model
const model = {
todos: {
items: [],
},
session: {
user: null
}
};
@ctrlplusb
ctrlplusb / model-with-action.js
Created November 5, 2018 17:54
Easy peasy model with action
const model = {
todos: {
items: [],
// 👇 an action
add: (state, payload) => {
state.items.push(payload);
}
},
session: {
user: null
import { createStore } from 'easy-peasy';
// Pass in your model and you get back a Redux store
const store = createStore(model);
// you can query state as normal
store.getState().todos.items;
// ['Install easy-peasy']
// and dispatch actions