Skip to content

Commit

Permalink
Remove classic function API, use decorator desugaring instead
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 18, 2015
1 parent 1ad2e11 commit 43c4aa3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
18 changes: 5 additions & 13 deletions modules/configureDragDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import invariant from 'invariant';

const DEFAULT_KEY = '__default__';

function configureDragDrop(InnerComponent, configure, collect, {
export default function configureDragDrop(configure, collect, {
arePropsEqual = shallowEqualScalar,
managerKey = 'dragDropManager'
}: options = {}) {
return class DragDropContainer extends Component {
return DecoratedComponent => class DragDropHandler extends Component {
static contextTypes = {
[managerKey]: PropTypes.object.isRequired
}
Expand Down Expand Up @@ -99,18 +99,10 @@ function configureDragDrop(InnerComponent, configure, collect, {

render() {
return (
<InnerComponent {...this.props}
{...this.state}
ref={this.setComponentRef} />
<DecoratedComponent {...this.props}
{...this.state}
ref={this.setComponentRef} />
);
}
};
}

export default function(...args) {
if (typeof args[2] === 'function') {
return configureDragDrop(...args);
} else {
return (DecoratedComponent) => configureDragDrop(DecoratedComponent, ...args);
}
}
18 changes: 4 additions & 14 deletions modules/configureDragDropContext.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component, PropTypes } from 'react';
import { DragDropManager } from 'dnd-core';

function configureDragDropContext(InnerComponent, backendFactories) {
export default function configureDragDropContext(backendFactories) {
const childContextTypes = {};
const childContext = {};

Expand All @@ -16,25 +16,15 @@ function configureDragDropContext(InnerComponent, backendFactories) {
childContext[key] = new DragDropManager(backendFactories[key]);
});

class DragDropContext extends Component {
return DecoratedComponent => class DragDropContext extends Component {
static childContextTypes = childContextTypes;

getChildContext() {
return childContext;
}

render() {
return <InnerComponent {...this.props} />;
return <DecoratedComponent {...this.props} />;
}
}

return DragDropContext;
}

export default function(...args) {
if (args.length === 1) {
return (DecoratedComponent) => configureDragDropContext(DecoratedComponent, ...args);
} else {
return configureDragDropContext(...args);
}
};
}

0 comments on commit 43c4aa3

Please sign in to comment.