👍 - +1
👎 - -1
🆎 - ab
🔤 - abc
// 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 |
export * as moduleA from './moduleA' | |
// should be a shorthand for: | |
import * as _moduleA from './moduleA' | |
export const moduleA = _moduleA |
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 |
👍 - +1
👎 - -1
🆎 - ab
🔤 - abc
// @flow | |
type Task<T> = (...args: any[]) => Promise<?T> | |
type Options<T> = { | |
args?: any[], | |
initial?: T, | |
isEmpty?: (value: ?T) => boolean | |
} | |
export default <T> ( |
// @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) |
const firstResult = (services) => { /* … */ } | |
firstResult([ | |
() => Promise.resolve([]), | |
() => Promise.resolve(['Berlin']), | |
() => console.error('Do not call me!') | |
]) | |
.then((result) => | |
console.assert(result[0] === 'Berlin', 'Test1 failed!') | |
) |
export default (tasks, { | |
args = [], | |
initial, | |
isEmpty = (x) => !x | |
} = {}) => | |
tasks.reduce( | |
(prev, next) => prev.then((value) => | |
isEmpty(value) ? next(...args) : value | |
), | |
Promise.resolve(initial) |
See also 📰 Dead simple tweetable JavaScript PubSub pattern module using Set (ES2015) which this package uses.
Chrome* | Edge | FF | IE | Opera | Safari | iOS |
---|---|---|---|---|---|---|
38 | 12 | 13 | -* | 25 | 7.1 | 8 |
Notes:
const iconList = [ | |
{ name: 'star', code: 7807, size: 20 /* ... */ }, | |
{ name: 'heart', code: 7897, size: 10 /* ... */ }, | |
{ name: 'arrow', code: 7822, size: 25 /* ... */ }, | |
{ name: 'home', code: 7901, size: 20 /* ... */ } | |
] | |
const entries = iconList.map(({ name, ...rest }) => [ name, rest ]) | |
const icons = new Map(entries) |