On Github jlongster / strangeloop2015
StrangeLoop, 2015 / James Long (@jlongster)
dispatch({ type: constants.ADD_BREAKPOINT, url: "foo.js", line: 5 })
var initialState = []; function update(state = initialState, action) { switch(action.type) { case constants.ADD_BREAKPOINT: return [...state, { url: action.url, line: action.line }]; case constants.REMOVE_BREAKPOINT: return state.filter(bp => !isEqual(bp, action)); } return state; }
"highlight var initialState = [];" function update("highlight state = initialState", action) { switch(action.type) { case constants.ADD_BREAKPOINT: return [...state, { url: action.url, line: action.line }]; case constants.REMOVE_BREAKPOINT: return state.filter(bp => !isEqual(bp, action)); } return state; }
var initialState = []; function update(state = initialState, action) { switch(action.type) { "highlight case constants.ADD_BREAKPOINT: return [...state, { url: action.url, line: action.line }];" case constants.REMOVE_BREAKPOINT: return state.filter(bp => !isEqual(bp, action)); } return state; }
function update(state, action) { return { sources: sourceUpdate(state.sources, action), breakpoints: bpUpdate(state.breakpoints, action) } }
var initialState = []; function update(state = initialState, action) { switch(action.type) { case constants.ADD_BREAKPOINT: return [...state, { url: action.url, line: action.line }]; case constants.REMOVE_BREAKPOINT: return state.filter(bp => !isEqual(bp, action)); } return state; }
var initialState = []; function update(state = initialState, action) { switch(action.type) { case constants.ADD_BREAKPOINT: "highlight return [...state, { url: action.url, line: action.line }];" case constants.REMOVE_BREAKPOINT: "highlight return state.filter(bp => !isEqual(bp, action));" } return state; }
var initialState = []; function update(state = initialState, action, emit) { switch(action.type) { case constants.ADD_BREAKPOINT: var bp = { url: action.url, line: action.line }; "appear emit('breakpoint-added', bp);" return [...state, bp]; case constants.REMOVE_BREAKPOINT: var bp = { url: action.url, line: action.line }; "appear emit('breakpoint-removed', bp);" return state.filter(_ => !isEqual(_, bp)); } return state; }
Sources.prototype.empty = function() { // ... } Editor.prototype.empty = function() { // ... } Variables.prototype.empty = function() { // ... }
case constants.RELOAD: { Object.keys(state.sources).forEach(k => { emit('source', state.sources[k]); }); emit('sources', state.sources); const selectedSource = state.selectedSource; if(selectedSource && state.sourcesText[selectedSource]) { const source = state.sources[selectedSource]; emit('source-selected', source); emit('source-selected-ready', { source: source, opts: state.selectedSourceOpts }); } }
function addBreakpoint(url, line) { return { type: constants.ADD_BREAKPOINT, url: url, line: line } }
function addBreakpoint(url, line) { return (dispatch, getState) => { dispatch({ type: constants.ADD_BREAKPOINT, url: url, line: line }); }; }
function addBreakpoint(url, line) { return (dispatch, getState) => { const action = { type: constants.ADD_BREAKPOINT, url: url, line: line }; dispatch(merge(action, { status: 'start' })); api.addBreakpoint(bp => { dispatch(merge(action, { status: 'done', value: bp })); }); }; }
function addBreakpoint(url, line) { return (dispatch, getState) => { const action = { type: constants.ADD_BREAKPOINT, url: url, line: line }; "highlight dispatch(merge(action, { status: 'start' }));" api.addBreakpoint(bp => { "highlight dispatch(merge(action, { status: 'done', value: bp }));" }); }; }
function addBreakpoint(url, line) { return (dispatch, getState) => { const action = { type: constants.ADD_BREAKPOINT, url: url, line: line }; dispatch(merge(action, { status: 'start' })); api.addBreakpoint().then(bp => { // Take my life, BUT YOU'LL NEVER TAKE MY ERRORS "highlight setTimeout(() => dispatch(...), 0);" }).catch(...); }; }
state = update(null, { type: 'init' }); assert(state.x, 0); state = update({ x: 5 }, { type: 'increment-x' }); assert(state.x, 6);
var TestUtils = React.addons.TestUtils; var renderer = TestUtils.createRenderer(); var sources = require('source-list'); renderer.render(React.createElement(sources, { sources: ['foo.js', 'bar.js', 'baz.js'] })); var output = renderer.getRenderOutput(); assert(output.type, 'div'); assert(output.props.children.length, 3);