👍 - +1
👎 - -1
🆎 - ab
🔤 - abc
| export default (tasks, { | |
| args = [], | |
| initial, | |
| isEmpty = (x) => !x | |
| } = {}) => | |
| tasks.reduce( | |
| (prev, next) => prev.then((value) => | |
| isEmpty(value) ? next(...args) : value | |
| ), | |
| Promise.resolve(initial) |
| const firstResult = (services) => { /* … */ } | |
| firstResult([ | |
| () => Promise.resolve([]), | |
| () => Promise.resolve(['Berlin']), | |
| () => console.error('Do not call me!') | |
| ]) | |
| .then((result) => | |
| console.assert(result[0] === 'Berlin', 'Test1 failed!') | |
| ) |
| // @flow | |
| // BAD | |
| // Will throw this type error: | |
| // ‘undefined This type is incompatible with some incompatible instantiation of `T`’ | |
| const resolve = <T> (init?: T): Promise<T> => Promise.resolve(init) | |
| // GOOD | |
| // The return promise type is `?T`, i.e. nullable T | |
| const resolve = <T> (init?: T): Promise<?T> => Promise.resolve(init) |
| // @flow | |
| type Task<T> = (...args: any[]) => Promise<?T> | |
| type Options<T> = { | |
| args?: any[], | |
| initial?: T, | |
| isEmpty?: (value: ?T) => boolean | |
| } | |
| export default <T> ( |
👍 - +1
👎 - -1
🆎 - ab
🔤 - abc
| ul.menu--primary | |
| body .menu--primary | |
| #page.item .item--primary .item--secondary | |
| .menu__nav--primary i.item__icon.item__icon--spinning | |
| .menu>.item--bold | |
| a[lang|=cs].item--bold | |
| *:hover .item--disabled+a.item--bold:active |
| export * as moduleA from './moduleA' | |
| // should be a shorthand for: | |
| import * as _moduleA from './moduleA' | |
| export const moduleA = _moduleA |
| // This function isolates the logic | |
| // Its param is number `i` | |
| // It returns 'Fizz', 'Bazz', 'FizzBuzz' or the number | |
| // (This implementation takes advatage of some JavaScript specific features) | |
| const toFizzBuzz = (i) => | |
| // We construct a string | |
| // First part is 'Fizz' if the number is divisible by 3 | |
| // and an empty string otherwise | |
| // `i%3` is 0 iff `i` is divisible by 3 |
See also 📢 Dead simple tweetable JavaScript Emitter pattern module using Map (ES2015) which uses this package.
| Chrome* | Edge | FF | IE | Opera | Safari | iOS |
|---|---|---|---|---|---|---|
| 38 | 12 | 13 | -* | 25 | 7.1 | 8 |
Notes:
| var pokemons = [ | |
| { | |
| "name": "rattata", | |
| "resource_uri": "api/v1/pokemon/19/" | |
| }, | |
| { | |
| "name": "charmander", | |
| "resource_uri": "api/v1/pokemon/4/" | |
| }, | |
| { |