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 { 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 |
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 model = { | |
todos: { | |
items: [], | |
// 👇 an action | |
add: (state, payload) => { | |
state.items.push(payload); | |
} | |
}, | |
session: { | |
user: 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
const model = { | |
todos: { | |
items: [], | |
}, | |
session: { | |
user: 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
npm install easy-peasy |
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 { 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) |
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 { 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`; |
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
// This is a basic demonstration of using mockery alongside mocha/chai | |
// for unit testing in node. |
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
// 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 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 { 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. | |
* |
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
/* This is intentionally blank just and exists to secure a decent gist name */ |
NewerOlder