Skip to content

Instantly share code, notes, and snippets.

@nhagen
nhagen / PromisAllWithFails.js
Last active November 15, 2022 18:11
Wait until all promises have completed even when some reject, with Promise.all
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);
})
@nhagen
nhagen / createReducer.js
Created October 25, 2015 20:34
Export reducer instead of switch
export default function(initialState, handlers) {
return function(state = initialState, action) {
const handler = handlers[action.type];
return typeof hander === 'function' ? handler(state, action) : state;
}
}

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: