Skip to content

Instantly share code, notes, and snippets.

View istarkov's full-sized avatar
💭
I need snow, now!

Ivan Starkov istarkov

💭
I need snow, now!
View GitHub Profile
/* @flow */
import React from 'react'
import { compose, defaultProps, withProps } from 'recompose'
import type { HOC } from 'recompose';
// type of Enhanced component props
type EnhancedComponentProps = {
text?: string,
};
// change output type of withProps
// from `HOC<A & B, B>` to `HOC<{ ...$Exact<B>, ...A }, B>`
type EnhancedCompProps = { b: number }
const enhancer2: HOC<*, EnhancedCompProps> = compose(
withProps(({ b }) => ({
b: `${b}`,
})),
withProps(({ b }) => ({
// $ExpectError The operand of an arithmetic operation must be a number
// no string get
const get = (fn, def) => {
try {
return fn();
} catch (e) {
return def;
}
};
// usage example
@istarkov
istarkov / unknown.md
Last active September 19, 2016 17:06
  • insist - настаивать
  • apart - кроме
  • posess - обладать
  • considerably - изрядно, конкретно
  • disclose раскрыть (секрет)
  • complain жаловаца
  • urgent срочный
// How to check array access
const arr = [];
const proxiedArr = new Proxy(arr, {
set(target, name, value) {
console.log(target, name, value);
// console.trace();
target[name] = value;
return value;
},

Similar js toExponential method, but returns result in power format, instead of Xe-1 it returns X⋅10⁻¹

Usage example:

console.log(toPower(3, 111)); // out 1.110⋅10²
console.log(toPower(3, 0.00000000000000123)); //out 1.230⋅10⁻¹⁵