Skip to content

Instantly share code, notes, and snippets.

View ShMcK's full-sized avatar

Shawn McKay ShMcK

View GitHub Profile
@ShMcK
ShMcK / thunk.js
Created February 26, 2018 15:37
thunk example
const incrementAsync = (count) => async (dispatch) => {
await delay()
dispatch(increment(count))
}
@ShMcK
ShMcK / simple-reducer.js
Created February 26, 2018 15:35
A simplified reducer
const countReducer = {
INCREMENT: (state, action) => state + action.payload,
DECREMENT: (state, action) => state - action.payload,
}
@ShMcK
ShMcK / reducer.js
Created February 26, 2018 15:34
Reducer Example
const countReducer = (state, action) => {
switch(action.type) {
case INCREMENT:
return state + action.payload
case DECREMENT:
return state - action.payload
default:
return state
}
}
@ShMcK
ShMcK / actionCreators
Created February 26, 2018 15:33
Action Creator Example
const increment = (count) => ({ type: 'INCREMENT', payload: count })
const decrement = (count) => ({ type: 'DECREMENT', payload: count })
@ShMcK
ShMcK / ReduxApiSimple.js
Created February 26, 2018 15:31
Simplified Redux API
const store = new Redux.Store({
initialState: {},
reducers: { count },
middlewares: [api, devTools],
})
@ShMcK
ShMcK / RealWorldRedux.js
Created February 26, 2018 15:28
Example of Redux Setup Complexity
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import api from '../middleware/api'
import rootReducer from '../reducers'
import DevTools from '../containers/DevTools'
const store = (preloadedState) => {
return createStore(
rootReducer,
preloadedState,
@ShMcK
ShMcK / Redux
Created January 16, 2018 17:52
class Store {
constructor(reducers = {}, initialState = {}, middleware = []) {
this.state = initialState
this.reducers = reducers
this.subscriptions = []
this.middlewares = middlewares
}
getState() {
return this.state
}

Button.js

import { connect, actions } from 'mirrorx'

const Button = ({value, handleClick}) => (
  <button onClick={handleClick}>
 {value}
@ShMcK
ShMcK / npm-unfuck.sh
Last active November 9, 2016 00:31
Quick fix for npm dependency issues. Run "bash npm-unfuck.sh"
# NPM Unfuck
# Brought to you by:
# Mackenzie Kieran & Shawn McKay
# remove deps
rm -rf node_modules
npm cache clean
# lock dependencies
@ShMcK
ShMcK / yarnOrNpmInstall.sh
Last active October 18, 2016 04:36
Run `yarn` if it exists, otherwise run `npm install`
if which yarn > /dev/null; then
yarn
else
npm install
fi