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
export function createStore(reducer, initialState) { | |
let currentState = initialState; | |
function getState() { | |
return currentState; | |
} | |
function dispatch(action) { | |
currentState = reducer(currentState, action); | |
} |
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
describe('#dispatch', () => { | |
const reducer = (state = [ 'hello world' ], action) => { | |
switch(action.type) { | |
case 'ADD_NOTE': | |
return [ ...state, action.payload ]; | |
default: | |
return state; | |
} | |
}; |
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
export function createStore(reducer, initialState) { | |
let currentState = initialState; | |
function getState() { | |
return currentState; | |
} | |
return { getState }; | |
}) |
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
describe('createStore', () => { | |
describe('#getState', () => { | |
it('should return the current state', () => { | |
const state = { notes: [ 'hello world', 'hello' ] }; | |
const store = createStore(x => x, state); | |
expect(store.getState()).to.equal(state); | |
}); | |
}); |
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
export function createStore(reducer, initialState) { | |
let currentState = initialState; | |
return {} | |
} |
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
// ## FETCH USERS (read all) | |
// start | |
{ type: 'FETCH_USERS', payload: { loading: true } } | |
{ | |
users: { | |
1: { user: { id: 1, name: 'Fred' } } | |
2: { user: { id: 2, name: 'Bob' } }, | |
3: { user: { id: 3, name: 'Sandra' } }, | |
loading: true, |
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
class fetch { | |
init(_ url: String, cb: (data: String) -> ()) { | |
NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: url)!) {(data, response, error) in | |
cb(data: NSString(data: data, encoding: NSUTF8StringEncoding) as! String) | |
}.resume() | |
} | |
} | |
fetch("http://www.google.com") {(data: String) in | |
println(data); |
NewerOlder