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⁻¹⁵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⁻¹⁵| // 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; | |
| }, |
| // no string get | |
| const get = (fn, def) => { | |
| try { | |
| return fn(); | |
| } catch (e) { | |
| return def; | |
| } | |
| }; | |
| // usage example |
| // 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 |
| /* @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, | |
| }; |
| // Extract type from any enhancer | |
| type HOCBase_<A, B, C: HOC<A, B>> = A | |
| type HOCBase<C> = HOCBase_<*, *, C> |
| type MyComponentProps = HOCBase<typeof myEnhancer> | |
| class MyComponent extends React.Component<MyComponentProps> { | |
| render() ... | |
| } | |
| const MyEnhancedComponent = myEnhancer(MyComponent) |
| /* @flow */ | |
| import * as React from 'react' | |
| import { compose, withProps } from 'recompose' | |
| import type { HOC } from 'recompose' | |
| function mapProps<BaseProps: {}, EnhancedProps>( | |
| mapperFn: EnhancedProps => BaseProps | |
| ): (React.ComponentType<BaseProps>) => React.ComponentType<EnhancedProps> { | |
| return Component => props => <Component {...mapperFn(props)} /> | |
| } |
| /* @flow */ | |
| import * as React from 'react' | |
| import { compose, withProps } from 'recompose' | |
| import type { HOC } from 'recompose' | |
| // Example of very dirty written fetcher enhancer | |
| function fetcher<Response: {}, Base: {}>( | |
| dest: string, | |
| nullRespType: ?Response | |
| ): HOC<{ ...$Exact<Base>, data?: Response }, Base> { | |
| return BaseComponent => |