Skip to content

Commit 1e9809e

Browse files
committed
Revert deprecation in favor of real PR
1 parent ae1aaef commit 1e9809e

File tree

8 files changed

+110
-25
lines changed

8 files changed

+110
-25
lines changed

src/components/createAll.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import createProvider from './createProvider';
2+
import createProvideDecorator from './createProvideDecorator';
23

34
import createConnector from './createConnector';
45
import createConnectDecorator from './createConnectDecorator';
56

67
export default function createAll(React) {
8+
// Wrapper components
79
const Provider = createProvider(React);
8-
const connect = createConnectDecorator(React, createConnector(React));
10+
const Connector = createConnector(React);
911

10-
// provider and Connector are deprecated and removed from public API
11-
return { Provider, connect };
12+
// Higher-order components (decorators)
13+
const provide = createProvideDecorator(React, Provider);
14+
const connect = createConnectDecorator(React, Connector);
15+
16+
return { Provider, Connector, provide, connect };
1217
}

src/components/createConnector.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import shallowEqual from '../utils/shallowEqual';
33
import isPlainObject from '../utils/isPlainObject';
44
import invariant from 'invariant';
55

6-
// Connector is deprecated and removed from public API
76
export default function createConnector(React) {
87
const { Component, PropTypes } = React;
98
const storeShape = createStoreShape(PropTypes);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import getDisplayName from '../utils/getDisplayName';
2+
3+
export default function createProvideDecorator(React, Provider) {
4+
const { Component } = React;
5+
6+
return function provide(store) {
7+
return DecoratedComponent => class ProviderDecorator extends Component {
8+
static displayName = `Provider(${getDisplayName(DecoratedComponent)})`;
9+
static DecoratedComponent = DecoratedComponent;
10+
11+
render() {
12+
return (
13+
<Provider store={store}>
14+
{() => <DecoratedComponent {...this.props} />}
15+
</Provider>
16+
);
17+
}
18+
};
19+
};
20+
}

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
22
import createAll from './components/createAll';
33

4-
// provide and Connector are deprecated and removed from public API
5-
export const { Provider, connect } = createAll(React);
4+
export const { Provider, Connector, provide, connect } = createAll(React);

src/native.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react-native';
22
import createAll from './components/createAll';
33

4-
// provide and Connector are deprecated and removed from public API
5-
export const { Provider, connect } = createAll(React);
4+
export const { Provider, Connector, provide, connect } = createAll(React);

test/components/Connector.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import expect from 'expect';
22
import jsdomReact from './jsdomReact';
33
import React, { PropTypes, Component } from 'react/addons';
44
import { createStore } from 'redux';
5-
import createConnector from '../../src/components/createConnector';
5+
import { Connector } from '../../src/index';
66

7-
const Connector = createConnector(React);
87
const { TestUtils } = React.addons;
98

109
describe('React', () => {

test/components/connect.spec.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import expect from 'expect';
22
import jsdomReact from './jsdomReact';
33
import React, { PropTypes, Component } from 'react/addons';
44
import { createStore } from 'redux';
5-
import { connect } from '../../src/index';
5+
import { connect, Connector } from '../../src/index';
66

77
const { TestUtils } = React.addons;
88

@@ -45,11 +45,9 @@ describe('React', () => {
4545
const div = TestUtils.findRenderedDOMComponentWithTag(container, 'div');
4646
expect(div.props.pass).toEqual('through');
4747
expect(div.props.foo).toEqual('bar');
48-
49-
// Connector is deprecated and removed from public API
50-
// expect(() =>
51-
// TestUtils.findRenderedComponentWithType(container, Connector)
52-
// ).toNotThrow();
48+
expect(() =>
49+
TestUtils.findRenderedComponentWithType(container, Connector)
50+
).toNotThrow();
5351
});
5452

5553
it('should handle additional prop changes in addition to slice', () => {
@@ -120,15 +118,13 @@ describe('React', () => {
120118
{() => <Container pass='through' />}
121119
</Provider>
122120
);
123-
124-
// Connector is deprecated and removed from public API
125-
// const connector = TestUtils.findRenderedComponentWithType(container, Connector);
126-
// expect(connector.props.select({
127-
// foo: 5,
128-
// bar: 7
129-
// })).toEqual({
130-
// foo: 5
131-
// });
121+
const connector = TestUtils.findRenderedComponentWithType(container, Connector);
122+
expect(connector.props.select({
123+
foo: 5,
124+
bar: 7
125+
})).toEqual({
126+
foo: 5
127+
});
132128
});
133129

134130
it('should set the displayName correctly', () => {

test/components/provide.spec.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import expect from 'expect';
2+
import jsdomReact from './jsdomReact';
3+
import React, { PropTypes, Component } from 'react/addons';
4+
import { createStore } from 'redux';
5+
import { provide, Provider } from '../../src/index';
6+
7+
const { TestUtils } = React.addons;
8+
9+
describe('React', () => {
10+
describe('provide', () => {
11+
jsdomReact();
12+
13+
class Child extends Component {
14+
static contextTypes = {
15+
store: PropTypes.object.isRequired
16+
}
17+
18+
render() {
19+
return <div />;
20+
}
21+
}
22+
23+
it('should wrap the component into Provider', () => {
24+
const store = createStore({});
25+
26+
@provide(store)
27+
class Container extends Component {
28+
render() {
29+
return <Child {...this.props} />;
30+
}
31+
}
32+
33+
const container = TestUtils.renderIntoDocument(
34+
<Container pass='through' />
35+
);
36+
const child = TestUtils.findRenderedComponentWithType(container, Child);
37+
expect(child.props.pass).toEqual('through');
38+
expect(() =>
39+
TestUtils.findRenderedComponentWithType(container, Provider)
40+
).toNotThrow();
41+
expect(child.context.store).toBe(store);
42+
});
43+
44+
it('sets the displayName correctly', () => {
45+
@provide(createStore({}))
46+
class Container extends Component {
47+
render() {
48+
return <div />;
49+
}
50+
}
51+
52+
expect(Container.displayName).toBe('Provider(Container)');
53+
});
54+
55+
it('should expose the wrapped component as DecoratedComponent', () => {
56+
class Container extends Component {
57+
render() {
58+
return <div />;
59+
}
60+
}
61+
62+
const decorator = provide(state => state);
63+
const decorated = decorator(Container);
64+
65+
expect(decorated.DecoratedComponent).toBe(Container);
66+
});
67+
});
68+
});

0 commit comments

Comments
 (0)