This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const themes = { | |
localhost: () => import('../../styles/themes/default.js'), | |
'client1.local.com': import('../../styles/themes/client1.js'), | |
'client2.local.com': import('../../styles/themes/client2.js') | |
}; | |
const Select = styled.select` | |
position: absolute; | |
bottom: 1em; | |
left: 1em; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const themes = { | |
localhost: () => import('../../styles/themes/default.js'), | |
'client1.local.com': import('../../styles/themes/client1.js'), | |
'client2.local.com': import('../../styles/themes/client2.js') | |
}; | |
const Select = styled.select` | |
position: absolute; | |
bottom: 1em; | |
left: 1em; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const makeGeneratorSnapshot = (gen, params = {}) => { | |
if (!gen) { | |
throw new Error('You must pass a generator function as the first parameter to makeGeratorSnapshot'); | |
} | |
const iter = gen(params[0]); | |
let i = 1; | |
while (true) { | |
// eslint-disable-line no-constant-condition | |
const param = params[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A contrived compose function. | |
const compose = (f1, f2) => (...args) => f1(f2(...args)); | |
// These functions are curried. Instead of the usual (a, b) => a + b, we're supplying each parameter individually | |
// and then returning a function that takes the next param. | |
// This is currying. We're taking a function that normally has 2 params, and turning it into a function that takes 1 param, | |
// then returns another function expecting the second param. | |
const add = a => b => a + b; | |
const multiply = a => b => a * b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compose = (...fns) => { | |
function _compose(funcs, next, ...args) { | |
const n = next(...args); | |
return funcs.length ? _compose(funcs, funcs.pop(), n) : n; | |
} | |
return (...args) => { | |
const funcs = [...fns]; | |
return _compose(funcs, funcs.pop(), ...args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compose = (...fns) => function _compose(arg, funcs = [...fns], next = funcs.pop()) { | |
return funcs.length ? _compose(next(arg), funcs) : next(arg); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const curry = fn => function innerCurry(...args) { | |
return args.length >= fn.length ? fn(...args) : innerCurry.bind(null, ...args); | |
} | |
const foo = curry((a, b, c) => a + b + c); | |
foo(1, 2, 3); // 6 | |
foo(1)(2, 3); // 6 | |
foo(1, 2)(3); // 6 | |
foo(1)(2)(3) // 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const g = z => z + 1; | |
g(0) // 1 | |
const maybeValue = Maybe.of(0); | |
maybeValue.map(g) // Maybe(1) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage example of what I've built so far. | |
// My guess is that this isn't implemented anything like the real RxJS either because | |
// performance concerns would be different, their abstractions would be | |
// fuller and better considered, and unlike me, they know what they're doing. | |
// This has been a project for fun and learning and I feel like I've learned a heck of a lot. | |
// This code logs 5, 6 at an interval of 1000ms before completing. | |
takeWhile(v => v < 7, | |
take(5, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compose = (f, g) => x => f(g(x)); | |
const identity = x => x; | |
const noop = () => {}; | |
function Disposable(fn) { | |
this.dispose = fn; | |
} | |
Disposable.of = fn => new Disposable(fn); |