made with esnextbin
This file contains hidden or 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
function toRanges<T>(items: T[], comparator: (a: T, b: T) => boolean): T[][] { | |
return items.reduce<T[][]>( | |
(acc, item) => { | |
const previousItem = R.last(R.last(acc)); | |
if (R.isNil(previousItem)) { | |
acc[acc.length - 1].push(item); | |
return acc; | |
} |
This file contains hidden or 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 pipeLog = <T>(x: T): T => { | |
console.log(x); | |
return x; | |
}; | |
const pipeDebug = <T>(x: T): T => { | |
debugger; | |
return x; | |
}; |
This file contains hidden or 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
/**REMOTE DATA IMPLEMENTATION */ | |
type Idle = { key: "idle", data: null }; | |
type Loading = { key: "loading", data: boolean }; | |
type Success = { key: "success", data: string }; | |
type RemoteDataState = Idle | Loading | Success; |
This file contains hidden or 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
componentWillReceiveProps(nextProps){ | |
console.info("New props, about to render..."); | |
Object.keys(nextProps).forEach((p) => { | |
console.info(`${p} is the same: ${this.props[p] === nextProps[p]}`); | |
}); | |
const shouldIUsePureRender = Object.keys(nextProps).reduce((acc, p) => { | |
if (nextProps[p] !== this.props[p]) { | |
return false; | |
} |
This file contains hidden or 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
declare module "freactal" { | |
interface ProvideStateArg<P, S, C, E> { | |
middleware?: any[]; | |
initialState: (props: P, freactal: {}) => S; | |
computed?: FreactalComputed<C, S>; | |
effects?: FreactalEffectDefinitions<E, S>; | |
} | |
export type InjectStateProps<P, S, C = null, E = null> = P & { state: S & C, effects: FreactalEffectUsages<E, S> }; | |
type InjectStateArg<P, S, C, E> = (p: InjectStateProps<P, S, C, E>) => JSX.Element; |
This file contains hidden or 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 default function hoc<T extends HoCProps>(WrappedComponent): React.ComponentClass<T> { | |
return class extends React.Component<T, null> { | |
... | |
} | |
} |
This file contains hidden or 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
//helpers | |
const getter = R.curry(function (key, obj) { | |
return Iterable.isIterable(obj) | |
? obj.get(key) : obj[key]; | |
}); | |
const setter = R.curry(function (key, val, obj) { | |
return Iterable.isIterable(obj) | |
? obj.set(key, value) : R.assoc(key, val, obj); | |
}); |
This file contains hidden or 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 logFn = R.curry((msg, fn) => { | |
return function () { | |
console.info("Calling " + msg, arguments); | |
const result = fn.apply(this, arguments); | |
console.info("Result " + msg, result); | |
return result; | |
} | |
}); |
made with esnextbin