Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Hagen nhagen

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am nhagen on github.
  • I am nhagen (https://keybase.io/nhagen) on keybase.
  • I have a public key ASBq0n5tlOT263WnjQOqQD7--GmLYw3AhR3e0ynWLowlRwo

To claim this, I am signing this object:

@nhagen
nhagen / createReducer.js
Created October 25, 2015 20:34
Export reducer instead of switch
View createReducer.js
export default function(initialState, handlers) {
return function(state = initialState, action) {
const handler = handlers[action.type];
return typeof hander === 'function' ? handler(state, action) : state;
}
}
@nhagen
nhagen / PromisAllWithFails.js
Last active November 15, 2022 18:11
Wait until all promises have completed even when some reject, with Promise.all
View PromisAllWithFails.js
var a = ["sdfdf", "http://oooooolol"],
handleNetErr = function(e) { return e };
Promise.all(fetch('sdfdsf').catch(handleNetErr), fetch('http://invalidurl').catch(handleNetErr))
.then(function(sdf, invalid) {
console.log(sdf, invalid) // [Response, TypeError]
})
.catch(function(err) {
console.log(err);
})