Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Remove createEagerFactory and createEagerElement (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsweet authored and istarkov committed Oct 6, 2017
1 parent 5004622 commit c830f18
Show file tree
Hide file tree
Showing 28 changed files with 37 additions and 306 deletions.
27 changes: 0 additions & 27 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ const PureComponent = pure(BaseComponent)
+ [`wrapDisplayName()`](#wrapdisplayname)
+ [`shallowEqual()`](#shallowequal)
+ [`isClassComponent()`](#isclasscomponent)
+ [`createEagerElement()`](#createeagerelement)
+ [`createEagerFactory()`](#createeagerfactory)
+ [`createSink()`](#createsink)
+ [`componentFromProp()`](#componentfromprop)
+ [`nest()`](#nest)
Expand Down Expand Up @@ -628,31 +626,6 @@ isClassComponent(value: any): boolean
Returns true if the given value is a React component class.
### `createEagerElement()`
```js
createEagerElement(
type: ReactClass | ReactFunctionalComponent | string,
props: ?Object,
children: ReactNode
): ReactElement
```
React elements are lazily evaluated. But when a higher-order component renders a functional component, the laziness doesn't have any real benefit. `createEagerElement()` is a replacement for `React.createElement()` that checks if the given component is referentially transparent. If so, rather than returning a React element, it calls the functional component with the given props and returns its output.
### `createEagerFactory()`
```js
createEagerFactory(
type: ReactClass | ReactFunctionalComponent | string,
): (
props: ?Object,
children: ReactNode
) => ReactElement
```
The factory form of `createEagerElement()`. Given a component, it returns a [factory](https://facebook.github.io/react/docs/react-api.html#createfactory).
### `createSink()`
```js
Expand Down
89 changes: 0 additions & 89 deletions src/packages/recompose/__tests__/createElement-test.js

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/packages/recompose/__tests__/treeshake-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const list = [
'wrapDisplayName',
// 'shallowEqual',
'isClassComponent',
'createEagerElement',
'createEagerFactory',
'createSink',
'componentFromProp',
'nest',
Expand Down
6 changes: 3 additions & 3 deletions src/packages/recompose/branch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createFactory } from 'react'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
import createEagerFactory from './createEagerFactory'

const identity = Component => Component

Expand All @@ -9,10 +9,10 @@ const branch = (test, left, right = identity) => BaseComponent => {
let rightFactory
const Branch = props => {
if (test(props)) {
leftFactory = leftFactory || createEagerFactory(left(BaseComponent))
leftFactory = leftFactory || createFactory(left(BaseComponent))
return leftFactory(props)
}
rightFactory = rightFactory || createEagerFactory(right(BaseComponent))
rightFactory = rightFactory || createFactory(right(BaseComponent))
return rightFactory(props)
}

Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/componentFromProp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createElement } from 'react'
import omit from './utils/omit'
import createEagerElement from './createEagerElement'

const componentFromProp = propName => {
const Component = props =>
createEagerElement(props[propName], omit(props, [propName]))
createElement(props[propName], omit(props, [propName]))
Component.displayName = `componentFromProp(${propName})`
return Component
}
Expand Down
20 changes: 0 additions & 20 deletions src/packages/recompose/createEagerElement.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/packages/recompose/createEagerFactory.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/packages/recompose/defaultProps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createFactory } from 'react'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
import createEagerFactory from './createEagerFactory'

const defaultProps = props => BaseComponent => {
const factory = createEagerFactory(BaseComponent)
const factory = createFactory(BaseComponent)
const DefaultProps = ownerProps => factory(ownerProps)
DefaultProps.defaultProps = props
if (process.env.NODE_ENV !== 'production') {
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/flattenProp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createFactory } from 'react'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
import createEagerFactory from './createEagerFactory'

const flattenProp = propName => BaseComponent => {
const factory = createEagerFactory(BaseComponent)
const factory = createFactory(BaseComponent)
const FlattenProp = props =>
factory({
...props,
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/getContext.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createFactory } from 'react'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
import createEagerFactory from './createEagerFactory'

const getContext = contextTypes => BaseComponent => {
const factory = createEagerFactory(BaseComponent)
const factory = createFactory(BaseComponent)
const GetContext = (ownerProps, context) =>
factory({
...ownerProps,
Expand Down
2 changes: 0 additions & 2 deletions src/packages/recompose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export { default as getDisplayName } from './getDisplayName'
export { default as wrapDisplayName } from './wrapDisplayName'
export { default as shallowEqual } from './shallowEqual'
export { default as isClassComponent } from './isClassComponent'
export { default as createEagerElement } from './createEagerElement'
export { default as createEagerFactory } from './createEagerFactory'
export { default as createSink } from './createSink'
export { default as componentFromProp } from './componentFromProp'
export { default as nest } from './nest'
Expand Down

This file was deleted.

5 changes: 2 additions & 3 deletions src/packages/recompose/lifecycle.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable no-console */
import { Component } from 'react'
import { createFactory, Component } from 'react'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
import createEagerFactory from './createEagerFactory'

const lifecycle = spec => BaseComponent => {
const factory = createEagerFactory(BaseComponent)
const factory = createFactory(BaseComponent)

if (process.env.NODE_ENV !== 'production' && spec.hasOwnProperty('render')) {
console.error(
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/mapProps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createFactory } from 'react'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
import createEagerFactory from './createEagerFactory'

const mapProps = propsMapper => BaseComponent => {
const factory = createEagerFactory(BaseComponent)
const factory = createFactory(BaseComponent)
const MapProps = props => factory(propsMapper(props))
if (process.env.NODE_ENV !== 'production') {
return setDisplayName(wrapDisplayName(BaseComponent, 'mapProps'))(MapProps)
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/mapPropsStream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createFactory } from 'react'
import $$observable from 'symbol-observable'
import createEagerFactory from './createEagerFactory'
import { componentFromStreamWithConfig } from './componentFromStream'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
Expand All @@ -13,7 +13,7 @@ export const mapPropsStreamWithConfig = config => {
toESObservable: identity,
})
return transform => BaseComponent => {
const factory = createEagerFactory(BaseComponent)
const factory = createFactory(BaseComponent)
const { fromESObservable, toESObservable } = config
return componentFromStream(props$ => ({
subscribe(observer) {
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/nest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import createEagerFactory from './createEagerFactory'
import { createFactory } from 'react'
import getDisplayName from './getDisplayName'

const nest = (...Components) => {
const factories = Components.map(createEagerFactory)
const factories = Components.map(createFactory)
const Nest = ({ ...props, children }) =>
factories.reduceRight((child, factory) => factory(props, child), children)

Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/renderComponent.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import createEagerFactory from './createEagerFactory'
import { createFactory } from 'react'
import wrapDisplayName from './wrapDisplayName'

const renderComponent = Component => _ => {
const factory = createEagerFactory(Component)
const factory = createFactory(Component)
const RenderComponent = props => factory(props)
if (process.env.NODE_ENV !== 'production') {
RenderComponent.displayName = wrapDisplayName(Component, 'renderComponent')
Expand Down
5 changes: 2 additions & 3 deletions src/packages/recompose/shouldUpdate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Component } from 'react'
import { createFactory, Component } from 'react'
import setDisplayName from './setDisplayName'
import wrapDisplayName from './wrapDisplayName'
import createEagerFactory from './createEagerFactory'

const shouldUpdate = test => BaseComponent => {
const factory = createEagerFactory(BaseComponent)
const factory = createFactory(BaseComponent)
class ShouldUpdate extends Component {
shouldComponentUpdate(nextProps) {
return test(this.props, nextProps)
Expand Down
Loading

0 comments on commit c830f18

Please sign in to comment.