-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deps): replace
recompose
with inlined version (#1494)
- Loading branch information
Showing
44 changed files
with
617 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# `@nivo/recompose` | ||
|
||
[![version](https://img.shields.io/npm/v/@nivo/recompose.svg?style=flat-square)](https://www.npmjs.com/package/@nivo/recompose) | ||
|
||
## Recompose | ||
|
||
![Recompose](https://raw.githubusercontent.com/plouc/nivo/master/packages/recompose/doc/recompose.png) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@nivo/recompose", | ||
"version": "0.68.0", | ||
"keywords": [ | ||
"nivo", | ||
"react", | ||
"recompose" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/plouc/nivo.git", | ||
"directory": "packages/recompose" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Raphaël Benitte", | ||
"url": "https://github.com/plouc" | ||
}, | ||
"main": "./dist/nivo-recompose.cjs.js", | ||
"module": "./dist/nivo-recompose.es.js", | ||
"typings": "./dist/types/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"LICENSE.md", | ||
"dist/", | ||
"!dist/tsconfig.tsbuildinfo" | ||
], | ||
"dependencies": { | ||
"react-lifecycles-compat": "^3.0.4" | ||
}, | ||
"devDependencies": { | ||
"@types/react-lifecycles-compat": "^3.0.1" | ||
}, | ||
"peerDependencies": { | ||
"react": ">= 16.8.4 < 18.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ComponentClass, ComponentType } from 'react' | ||
|
||
interface ComponentEnhancer<TInner, TOuter> { | ||
(component: ComponentType<TInner>): ComponentClass<TOuter> | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export const compose = <TInner, TOuter>(...funcs: Function[]): ComponentEnhancer<TInner, TOuter> => | ||
funcs.reduce<ComponentEnhancer<TInner, TOuter>>( | ||
(a, b) => (...args) => a(b(...args)), | ||
arg => arg as any | ||
) as ComponentEnhancer<TInner, TOuter> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createFactory } from 'react' | ||
import { setDisplayName } from './setDisplayName' | ||
import { DefaultingInferableComponentEnhancer } from './types' | ||
import { wrapDisplayName } from './wrapDisplayName' | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export const defaultProps = <T = {}>(props: T): DefaultingInferableComponentEnhancer<T> => ( | ||
BaseComponent: any | ||
): any => { | ||
const factory = createFactory(BaseComponent) | ||
const DefaultProps = (ownerProps: any) => factory(ownerProps) | ||
DefaultProps.defaultProps = props | ||
if (process.env.NODE_ENV !== 'production') { | ||
return setDisplayName(wrapDisplayName(BaseComponent, 'defaultProps'))(DefaultProps) | ||
} | ||
return DefaultProps | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ComponentType } from 'react' | ||
|
||
export const getDisplayName = (component: ComponentType<any> | string): string | undefined => { | ||
if (typeof component === 'string') { | ||
return component | ||
} | ||
|
||
if (!component) { | ||
return undefined | ||
} | ||
|
||
return component.displayName || component.name || 'Component' | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export * from './getDisplayName' | ||
export * from './pure' | ||
export * from './setDisplayName' | ||
export * from './setStatic' | ||
export * from './shallowEqual' | ||
export * from './shouldUpdate' | ||
export * from './wrapDisplayName' | ||
export * from './compose' | ||
export * from './withPropsOnChange' | ||
export * from './defaultProps' | ||
export * from './withProps' | ||
export * from './setPropTypes' | ||
export * from './withState' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createFactory } from 'react' | ||
import { setDisplayName } from './setDisplayName' | ||
import { InferableComponentEnhancerWithProps, Mapper } from './types' | ||
import { wrapDisplayName } from './wrapDisplayName' | ||
|
||
export const mapProps = <TInner, TOuter>( | ||
propsMapper: Mapper<TOuter, TInner> | ||
): InferableComponentEnhancerWithProps<TInner, TOuter> => (BaseComponent: any): any => { | ||
const factory = createFactory(BaseComponent) | ||
const MapProps = (props: any) => factory(propsMapper(props)) | ||
if (process.env.NODE_ENV !== 'production') { | ||
return setDisplayName(wrapDisplayName(BaseComponent, 'mapProps'))(MapProps) | ||
} | ||
return MapProps | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ComponentType } from 'react' | ||
import { setDisplayName } from './setDisplayName' | ||
import { shallowEqual } from './shallowEqual' | ||
import { shouldUpdate } from './shouldUpdate' | ||
import { wrapDisplayName } from './wrapDisplayName' | ||
|
||
export const pure = <TProps>(component: ComponentType<TProps>): ComponentType<TProps> => { | ||
const hoc = shouldUpdate((props, nextProps) => !shallowEqual(props, nextProps)) | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
return setDisplayName(wrapDisplayName(component, 'pure'))(hoc(component)) | ||
} | ||
|
||
return hoc(component) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ComponentType } from 'react' | ||
import { setStatic } from './setStatic' | ||
|
||
export const setDisplayName = ( | ||
displayName: string | ||
): (<T extends ComponentType<any>>(component: T) => T) => setStatic('displayName', displayName) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ComponentType, ValidationMap } from 'react' | ||
import { setStatic } from './setStatic' | ||
|
||
export const setPropTypes = <P>( | ||
propTypes: ValidationMap<P> | ||
): (<T extends ComponentType<P>>(component: T) => T) => setStatic('propTypes', propTypes) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ComponentType } from 'react' | ||
|
||
export const setStatic = ( | ||
key: string, | ||
value: any | ||
): (<T extends ComponentType<any>>(component: T) => T) => BaseComponent => { | ||
/* eslint-disable no-param-reassign */ | ||
// @ts-expect-error there's no way to type this | ||
BaseComponent[key] = value | ||
/* eslint-enable no-param-reassign */ | ||
return BaseComponent | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @providesModule shallowEqual | ||
* @typechecks | ||
*/ | ||
|
||
/* eslint-disable no-self-compare */ | ||
|
||
const hasOwnProperty = Object.prototype.hasOwnProperty | ||
|
||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
function is(x: unknown, y: unknown): boolean { | ||
// SameValue algorithm | ||
if (x === y) { | ||
// Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
// Added the nonzero y check to make Flow happy, but it is redundant | ||
return x !== 0 || y !== 0 || 1 / x === 1 / y | ||
} | ||
// Step 6.a: NaN == NaN | ||
return x !== x && y !== y | ||
} | ||
|
||
/** | ||
* Performs equality by iterating through keys on an object and returning false | ||
* when any key has values which are not strictly equal between the arguments. | ||
* Returns true when the values of all keys are strictly equal. | ||
*/ | ||
export function shallowEqual( | ||
objA: Record<string, unknown>, | ||
objB: Record<string, unknown> | ||
): boolean { | ||
if (is(objA, objB)) { | ||
return true | ||
} | ||
|
||
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { | ||
return false | ||
} | ||
|
||
const keysA = Object.keys(objA) | ||
const keysB = Object.keys(objB) | ||
|
||
if (keysA.length !== keysB.length) { | ||
return false | ||
} | ||
|
||
// Test for A's keys different from B. | ||
for (let i = 0; i < keysA.length; i++) { | ||
if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Component, createFactory } from 'react' | ||
import { setDisplayName } from './setDisplayName' | ||
import { InferableComponentEnhancer, PredicateDiff } from './types' | ||
import { wrapDisplayName } from './wrapDisplayName' | ||
|
||
export const shouldUpdate = <TProps extends Record<string, unknown>>( | ||
test: PredicateDiff<TProps> | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
): InferableComponentEnhancer<{}> => (BaseComponent: any): any => { | ||
const factory = createFactory(BaseComponent) | ||
class ShouldUpdate extends Component { | ||
shouldComponentUpdate(nextProps: any) { | ||
// @ts-expect-error not type-able | ||
return test(this.props, nextProps) | ||
} | ||
|
||
render() { | ||
// @ts-expect-error not type-able | ||
return factory(this.props) | ||
} | ||
} | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
return setDisplayName(wrapDisplayName(BaseComponent, 'shouldUpdate'))(ShouldUpdate) | ||
} | ||
return ShouldUpdate | ||
} |
Oops, something went wrong.