Skip to content

Commit

Permalink
Rename DecoratedComponent => WrappedComponent, getUnderlyingRef() => …
Browse files Browse the repository at this point in the history
…getWrappedInstance()
  • Loading branch information
gaearon committed Aug 9, 2015
1 parent 6178a0a commit b7ef178
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
20 changes: 7 additions & 13 deletions src/components/createConnect.js
Expand Up @@ -66,10 +66,10 @@ export default function createConnect(React) {
return mergedProps;
}

return function wrapWithConnect(DecoratedComponent) {
return function wrapWithConnect(WrappedComponent) {
class Connect extends Component {
static displayName = `Connect(${getDisplayName(DecoratedComponent)})`;
static DecoratedComponent = DecoratedComponent;
static displayName = `Connect(${getDisplayName(WrappedComponent)})`;
static WrappedComponent = WrappedComponent;

static contextTypes = {
store: storeShape.isRequired
Expand All @@ -82,8 +82,6 @@ export default function createConnect(React) {
constructor(props, context) {
super(props, context);
this.version = version;
this.setUnderlyingRef = ::this.setUnderlyingRef;

this.stateProps = computeStateProps(context);
this.dispatchProps = computeDispatchProps(context);
this.state = this.computeNextState();
Expand Down Expand Up @@ -179,18 +177,14 @@ export default function createConnect(React) {
}
}

getUnderlyingRef() {
return this.underlyingRef;
}

setUnderlyingRef(instance) {
this.underlyingRef = instance;
getWrappedInstance() {
return this.refs.wrappedInstance;
}

render() {
return (
<DecoratedComponent ref={this.setUnderlyingRef}
{...this.state} />
<WrappedComponent ref='wrappedInstance'
{...this.state} />
);
}
}
Expand Down
9 changes: 5 additions & 4 deletions test/components/connect.spec.js
Expand Up @@ -285,7 +285,7 @@ describe('React', () => {
expect(div.props.stateThing).toBe('HELLO azbzcZ');
});

it('should merge actionProps into DecoratedComponent', () => {
it('should merge actionProps into WrappedComponent', () => {
const store = createStore(() => ({
foo: 'bar'
}));
Expand Down Expand Up @@ -700,7 +700,7 @@ describe('React', () => {
).displayName).toBe('Connect(Component)');
});

it('should expose the wrapped component as DecoratedComponent', () => {
it('should expose the wrapped component as WrappedComponent', () => {
class Container extends Component {
render() {
return <div />;
Expand All @@ -710,7 +710,7 @@ describe('React', () => {
const decorator = connect(state => state);
const decorated = decorator(Container);

expect(decorated.DecoratedComponent).toBe(Container);
expect(decorated.WrappedComponent).toBe(Container);
});

it('should return the instance of the wrapped component for use in calling child methods', () => {
Expand Down Expand Up @@ -744,7 +744,8 @@ describe('React', () => {
const decorated = TestUtils.findRenderedComponentWithType(tree, Decorated);

expect(() => decorated.someInstanceMethod()).toThrow();
expect(decorated.getUnderlyingRef().someInstanceMethod()).toBe(someData);
expect(decorated.getWrappedInstance().someInstanceMethod()).toBe(someData);
expect(decorated.refs.wrappedInstance.someInstanceMethod()).toBe(someData);
});
});
});

0 comments on commit b7ef178

Please sign in to comment.