-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This update adjusts the create-emotion-styled HOC to create React.PureComponent styled components, by default. This is for an overall performance boost, as PureComponent classes perform faster than default Component classes. This should be safe, as we've been using PureComponents exclusively, at the library level, for a while now. Not to mention, React Redux also defaults to PureComponents. This behaviour can be customized by defining `{ pure: false }` in a new argument for `create-emotion-styled`.
- Loading branch information
Jon Quach
committed
Dec 3, 2018
1 parent
8bd98d1
commit 952152b
Showing
5 changed files
with
57 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import {mount} from 'enzyme' | ||
import createStyled from '../index' | ||
|
||
test('Creates a React.PureComponent instance, by default', () => { | ||
const Comp = createStyled()('div')`` | ||
const wrapper = mount(<Comp />) | ||
const el = wrapper.getNodes()[0] | ||
|
||
expect(el instanceof React.PureComponent).toBe(true) | ||
}) | ||
|
||
test('Can create a React.Component instance, if defined', () => { | ||
const Comp = createStyled({pure: false})('div')`` | ||
const wrapper = mount(<Comp />) | ||
const el = wrapper.getNodes()[0] | ||
|
||
expect(el instanceof React.Component).toBe(true) | ||
}) | ||
|
||
test('Can create a React.PureComponent instance, if defined', () => { | ||
const Comp = createStyled({pure: true})('div')`` | ||
const wrapper = mount(<Comp />) | ||
const el = wrapper.getNodes()[0] | ||
|
||
expect(el instanceof React.PureComponent).toBe(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,13 @@ | ||
// @flow | ||
import React from 'react' | ||
import * as emotion from '../emotion/index' | ||
import createEmotionStyled from '../create-emotion-styled' | ||
|
||
/** | ||
* A custom HOC that wraps the default createEmotionStyled to allow | ||
* for options, being passed through a custom argument. | ||
*/ | ||
|
||
export default function createStyled(options) { | ||
return createEmotionStyled(emotion, React, options) | ||
} |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
// @flow | ||
import React from 'react' | ||
import * as emotion from '../emotion/index' | ||
import createEmotionStyled from '../create-emotion-styled' | ||
import createStyled from '../create-styled' | ||
|
||
export default createEmotionStyled(emotion, React) | ||
export default createStyled({pure: true}) | ||
|
||
export * from '../emotion/index' |