Skip to content

Commit

Permalink
Expose some internals for easier testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed May 18, 2015
1 parent c8ad695 commit 19f6740
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/DragDropContext.js
Expand Up @@ -26,18 +26,29 @@ export default function DragDropContext(backend) {
'Component';

return class DragDropContextContainer extends Component {
static DecoratedComponent = DecoratedComponent;

static displayName = `DragDropContext(${displayName})`;

static childContextTypes = {
dragDropManager: PropTypes.object.isRequired
};

getDecoratedComponentInstance() {
return this.refs.child;
}

getManager() {
return childContext.dragDropManager;
}

getChildContext() {
return childContext;
}

render() {
return <DecoratedComponent {...this.props} />;
return <DecoratedComponent {...this.props}
ref='child' />;
}
};
};
Expand Down
9 changes: 8 additions & 1 deletion src/DragLayer.js
Expand Up @@ -31,12 +31,18 @@ export default function DragLayer(collect, options = {}) {
'Component';

return class DragLayerContainer extends Component {
static DecoratedComponent = DecoratedComponent;

static displayName = `DragLayer(${displayName})`;

static contextTypes = {
dragDropManager: PropTypes.object.isRequired
}

getDecoratedComponentInstance() {
return this.refs.child;
}

shouldComponentUpdate(nextProps, nextState) {
return !arePropsEqual(nextProps, this.props) ||
!shallowEqual(nextState, this.state);
Expand Down Expand Up @@ -83,7 +89,8 @@ export default function DragLayer(collect, options = {}) {
render() {
return (
<DecoratedComponent {...this.props}
{...this.state} />
{...this.state}
ref='child' />
);
}
};
Expand Down
16 changes: 12 additions & 4 deletions src/decorateHandler.js
Expand Up @@ -24,21 +24,27 @@ export default function decorateHandler({
'Component';

return class DragDropContainer extends Component {
static DecoratedComponent = DecoratedComponent;

static displayName = `${containerDisplayName}(${displayName})`;

static contextTypes = {
dragDropManager: PropTypes.object.isRequired
}

getHandlerId() {
return this.handlerId;
}

getDecoratedComponentInstance() {
return this.decoratedComponentInstance;
}

shouldComponentUpdate(nextProps, nextState) {
return !arePropsEqual(nextProps, this.props) ||
!shallowEqual(nextState, this.state);
}

getInstance() {
return this.refs.child;
}

constructor(props, context) {
super(props, context);
this.handleChange = this.handleChange.bind(this);
Expand Down Expand Up @@ -116,6 +122,7 @@ export default function decorateHandler({

this.handlerMonitor.receiveHandlerId(handlerId);
this.handlerConnector = handlerConnector;
this.handlerId = handlerId;
}

handleChange() {
Expand All @@ -126,6 +133,7 @@ export default function decorateHandler({
}

handleChildRef(component) {
this.decoratedComponentInstance = component;
this.handler.receiveComponent(component);
}

Expand Down

0 comments on commit 19f6740

Please sign in to comment.