Skip to content

Commit 320b0e5

Browse files
committed
Use react-context-toolbox for passing context value into props. Remove fallback and require peerDependency react >=16.3.0. Simplify tests.
1 parent e4332d0 commit 320b0e5

File tree

4 files changed

+37
-59
lines changed

4 files changed

+37
-59
lines changed

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@
5050
]
5151
},
5252
"peerDependencies": {
53-
"react": ">=15.0.0",
54-
"react-dom": ">=15.0.0"
53+
"react": ">=16.3.0",
54+
"react-dom": ">=16.3.0"
5555
},
5656
"dependencies": {
5757
"dom-helpers": "^3.3.1",
5858
"loose-envify": "^1.4.0",
5959
"prop-types": "^15.6.2",
60+
"react-context-toolbox": "^1.2.2",
6061
"react-lifecycles-compat": "^3.0.4"
6162
},
6263
"devDependencies": {
@@ -86,9 +87,9 @@
8687
"husky": "^1.0.0-rc.15",
8788
"jest": "^23.6.0",
8889
"prettier": "^1.14.3",
89-
"react": "^16.5.2",
90-
"react-dom": "^16.5.2",
91-
"react-test-renderer": "^16.5.2",
90+
"react": "^16.6.0",
91+
"react-dom": "^16.6.0",
92+
"react-test-renderer": "^16.6.0",
9293
"release-script": "^1.0.2",
9394
"rimraf": "^2.6.1",
9495
"semantic-release": "^15.9.16",

src/TransitionGroupContext.js

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,15 @@
11
import * as PropTypes from 'prop-types'
22
import React from 'react'
3+
import mapContextToProps from 'react-context-toolbox/lib/mapContextToProps'
34

4-
const TransitionGroupContext = React.createContext && React.createContext(null)
5+
const { Provider, Consumer } = React.createContext(null)
56

67
export const transitionGroupContextPropType = PropTypes.shape({
78
isMounting: PropTypes.bool.isRequired
89
})
910

10-
const Consumer = (TransitionGroupContext && TransitionGroupContext.Consumer) || class Consumer extends React.Component {
11-
static contextTypes = {
12-
transitionGroup: PropTypes.object,
13-
}
14-
render() {
15-
return this.props.children(this.context.transitionGroup)
16-
}
17-
}
18-
19-
const Provider = (TransitionGroupContext && TransitionGroupContext.Provider) || class Provider extends React.Component {
20-
static childContextTypes = {
21-
transitionGroup: transitionGroupContextPropType,
22-
}
23-
static propTypes = {
24-
value: transitionGroupContextPropType
25-
}
26-
getChildContext() {
27-
return { transitionGroup: this.props.value }
28-
}
29-
render() { return this.props.children }
30-
}
31-
3211
export function withTransitionGroup(ComponentToWrap) {
33-
return class WithTransitionGroup extends React.Component {
34-
static displayName = `withTransitionGroup(${ComponentToWrap.displayName || ComponentToWrap.name})`
35-
static __TestingStatefulComponent = ComponentToWrap
36-
render() {
37-
const { __testingRef, ...restProps } = this.props
38-
return (
39-
<Consumer>
40-
{transitionGroup => <ComponentToWrap ref={__testingRef} {...restProps} transitionGroup={transitionGroup} />}
41-
</Consumer>
42-
)
43-
}
44-
}
12+
return mapContextToProps(Consumer, value => ({ transitionGroup: value }), ComponentToWrap)
4513
}
4614

4715
export { Provider }

test/Transition-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jasmine.addMatchers({
2121
})
2222

2323
function findStatefulInstance(wrapper) {
24-
return wrapper.find(Transition.__TestingStatefulComponent).instance()
24+
return wrapper.find('Transition').instance()
2525
}
2626

2727
describe('Transition', () => {
@@ -268,7 +268,7 @@ describe('Transition', () => {
268268

269269
return (
270270
<Transition
271-
__testingRef={transition => this.transition = this.transition || transition}
271+
ref={transition => this.transition = this.transition || transition}
272272
mountOnEnter
273273
in={this.state.in}
274274
timeout={10}
@@ -341,7 +341,7 @@ describe('Transition', () => {
341341

342342
return (
343343
<Transition
344-
__testingRef={transition => this.transition = this.transition || transition}
344+
ref={transition => this.transition = this.transition || transition}
345345
unmountOnExit
346346
in={this.state.in}
347347
timeout={10}

yarn.lock

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9903,6 +9903,10 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.7, rc@^1.2.8:
99039903
minimist "^1.2.0"
99049904
strip-json-comments "~2.0.1"
99059905

9906+
react-context-toolbox@^1.2.2:
9907+
version "1.2.2"
9908+
resolved "https://registry.yarnpkg.com/react-context-toolbox/-/react-context-toolbox-1.2.2.tgz#3fd9a07b0618ae398d232098a04c2b9f0abdbb86"
9909+
99069910
react-dev-utils@^5.0.0:
99079911
version "5.0.1"
99089912
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-5.0.1.tgz#1f396e161fe44b595db1b186a40067289bf06613"
@@ -9938,14 +9942,14 @@ react-docgen@^3.0.0-beta11:
99389942
node-dir "^0.1.10"
99399943
recast "^0.12.6"
99409944

9941-
react-dom@^16.5.2:
9942-
version "16.5.2"
9943-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.5.2.tgz#b69ee47aa20bab5327b2b9d7c1fe2a30f2cfa9d7"
9945+
react-dom@^16.6.0:
9946+
version "16.6.0"
9947+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.6.0.tgz#6375b8391e019a632a89a0988bce85f0cc87a92f"
99449948
dependencies:
99459949
loose-envify "^1.1.0"
99469950
object-assign "^4.1.1"
99479951
prop-types "^15.6.2"
9948-
schedule "^0.5.0"
9952+
scheduler "^0.10.0"
99499953

99509954
react-error-overlay@^4.0.0:
99519955
version "4.0.0"
@@ -9991,6 +9995,10 @@ react-is@^16.5.2:
99919995
version "16.5.2"
99929996
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.5.2.tgz#e2a7b7c3f5d48062eb769fcb123505eb928722e3"
99939997

9998+
react-is@^16.6.0:
9999+
version "16.6.0"
10000+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.6.0.tgz#456645144581a6e99f6816ae2bd24ee94bdd0c01"
10001+
999410002
react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4:
999510003
version "3.0.4"
999610004
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
@@ -10027,14 +10035,14 @@ react-test-renderer@^16.0.0-0:
1002710035
prop-types "^15.6.0"
1002810036
react-is "^16.4.1"
1002910037

10030-
react-test-renderer@^16.5.2:
10031-
version "16.5.2"
10032-
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.5.2.tgz#92e9d2c6f763b9821b2e0b22f994ee675068b5ae"
10038+
react-test-renderer@^16.6.0:
10039+
version "16.6.0"
10040+
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.6.0.tgz#fe490096bed55c3f4e92c023da3b89f9d03fceb3"
1003310041
dependencies:
1003410042
object-assign "^4.1.1"
1003510043
prop-types "^15.6.2"
10036-
react-is "^16.5.2"
10037-
schedule "^0.5.0"
10044+
react-is "^16.6.0"
10045+
scheduler "^0.10.0"
1003810046

1003910047
react-transition-group@^2.0.0:
1004010048
version "2.3.1"
@@ -10055,14 +10063,14 @@ react-treebeard@^2.1.0:
1005510063
shallowequal "^0.2.2"
1005610064
velocity-react "^1.3.1"
1005710065

10058-
react@^16.5.2:
10059-
version "16.5.2"
10060-
resolved "https://registry.yarnpkg.com/react/-/react-16.5.2.tgz#19f6b444ed139baa45609eee6dc3d318b3895d42"
10066+
react@^16.6.0:
10067+
version "16.6.0"
10068+
resolved "https://registry.yarnpkg.com/react/-/react-16.6.0.tgz#b34761cfaf3e30f5508bc732fb4736730b7da246"
1006110069
dependencies:
1006210070
loose-envify "^1.1.0"
1006310071
object-assign "^4.1.1"
1006410072
prop-types "^15.6.2"
10065-
schedule "^0.5.0"
10073+
scheduler "^0.10.0"
1006610074

1006710075
read-cmd-shim@^1.0.1, read-cmd-shim@~1.0.1:
1006810076
version "1.0.1"
@@ -10752,10 +10760,11 @@ sax@^1.2.4, sax@~1.2.1, sax@~1.2.4:
1075210760
version "1.2.4"
1075310761
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
1075410762

10755-
schedule@^0.5.0:
10756-
version "0.5.0"
10757-
resolved "https://registry.yarnpkg.com/schedule/-/schedule-0.5.0.tgz#c128fffa0b402488b08b55ae74bb9df55cc29cc8"
10763+
scheduler@^0.10.0:
10764+
version "0.10.0"
10765+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.10.0.tgz#7988de90fe7edccc774ea175a783e69c40c521e1"
1075810766
dependencies:
10767+
loose-envify "^1.1.0"
1075910768
object-assign "^4.1.1"
1076010769

1076110770
schema-utils@^0.3.0:

0 commit comments

Comments
 (0)