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

Commit

Permalink
Use eager factory optimization only in production env (close #442) (#473
Browse files Browse the repository at this point in the history
)

* Use eager factory optimization only in production env (close #442)

* Refactor using env check in createEagerElementUtil

* Remove check for propTypes
  • Loading branch information
deepsweet authored and istarkov committed Aug 15, 2017
1 parent 084a259 commit 4b37008
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/packages/recompose/__tests__/createElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import React, { Component } from 'react'
import { shallow } from 'enzyme'
import createEagerElement from '../createEagerElement'

const origNodeEnv = process.env.NODE_ENV

afterEach(() => {
process.env.NODE_ENV = origNodeEnv
})

test('createEagerElement treats class components normally', () => {
class InnerDiv extends Component {
render() {
Expand Down Expand Up @@ -31,6 +37,7 @@ test('createEagerElement treats class components normally', () => {
})

test('createEagerElement calls stateless function components instead of creating an intermediate React element', () => {
process.env.NODE_ENV = 'production'
const InnerDiv = () => <div data-bar="baz" />
const OuterDiv = () =>
createEagerElement(
Expand Down Expand Up @@ -64,6 +71,7 @@ test('createEagerElement handles keyed elements correctly', () => {
})

test('createEagerElement passes children correctly', () => {
process.env.NODE_ENV = 'production'
const Div = props => <div {...props} />
const InnerDiv = () => <div data-bar="baz" />
const OuterDiv = () =>
Expand Down
4 changes: 2 additions & 2 deletions src/packages/recompose/__tests__/hoistStatics-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { shallow } from 'enzyme'
import { mount } from 'enzyme'
import sinon from 'sinon'
import { hoistStatics, mapProps } from '../'

Expand All @@ -13,6 +13,6 @@ test('copies non-React static properties from base component to new component',

expect(EnhancedComponent.foo).toBe(BaseComponent.foo)

shallow(<EnhancedComponent n={3} />)
mount(<EnhancedComponent n={3} />)
expect(BaseComponent.firstCall.args[0].n).toBe(15)
})
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ test('isReferentiallyTransparentFunctionComponent returns false for functions th
expect(isReferentiallyTransparentFunctionComponent(Foo)).toBe(false)
})

test('isReferentiallyTransparentFunctionComponent returns false for functions that use propTypes', () => {
test('isReferentiallyTransparentFunctionComponent returns true for functions that use propTypes', () => {
const Foo = (props, context) => <div {...props} {...context} />
Foo.propTypes = { store: PropTypes.object }

expect(isReferentiallyTransparentFunctionComponent(Foo)).toBe(false)
expect(isReferentiallyTransparentFunctionComponent(Foo)).toBe(true)
})
4 changes: 2 additions & 2 deletions src/packages/recompose/__tests__/renameProp-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { shallow } from 'enzyme'
import { mount } from 'enzyme'
import { withProps, renameProp, compose } from '../'

test('renameProp renames a single prop', () => {
Expand All @@ -10,6 +10,6 @@ test('renameProp renames a single prop', () => {

expect(StringConcat.displayName).toBe('withProps(renameProp(div))')

const div = shallow(<StringConcat />).find('div')
const div = mount(<StringConcat />).find('div')
expect(div.props()).toEqual({ 'data-do': 123, 'data-la': 456 })
})
4 changes: 2 additions & 2 deletions src/packages/recompose/__tests__/renameProps-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { shallow } from 'enzyme'
import { mount } from 'enzyme'
import { withProps, renameProps, compose } from '../'

test('renameProps renames props', () => {
Expand All @@ -10,7 +10,7 @@ test('renameProps renames props', () => {

expect(StringConcat.displayName).toBe('withProps(renameProps(div))')

const div = shallow(<StringConcat />).find('div')
const div = mount(<StringConcat />).find('div')

expect(div.prop('data-do')).toBe(123)
expect(div.prop('data-fa')).toBe(456)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const isReferentiallyTransparentFunctionComponent = Component =>
typeof Component === 'function' &&
!isClassComponent(Component) &&
!Component.defaultProps &&
!Component.contextTypes &&
(process.env.NODE_ENV === 'production' || !Component.propTypes)
!Component.contextTypes
)

export default isReferentiallyTransparentFunctionComponent
6 changes: 5 additions & 1 deletion src/packages/recompose/utils/createEagerElementUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const createEagerElementUtil = (
props,
children
) => {
if (!hasKey && isReferentiallyTransparent) {
if (
process.env.NODE_ENV === 'production' &&
!hasKey &&
isReferentiallyTransparent
) {
if (children) {
return type({ ...props, children })
}
Expand Down

0 comments on commit 4b37008

Please sign in to comment.