Skip to content

Commit

Permalink
Adding statics hoisting to HOCs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Gensler committed Aug 3, 2016
1 parent aff817f commit 7aa0cac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"disposables": "^1.0.1",
"dnd-core": "^2.0.1",
"hoist-non-react-statics": "^1.2.0",
"invariant": "^2.1.0",
"lodash": "^4.2.0"
},
Expand Down
9 changes: 6 additions & 3 deletions src/DragDropContext.js
Expand Up @@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react';
import { DragDropManager } from 'dnd-core';
import invariant from 'invariant';
import checkDecoratorArguments from './utils/checkDecoratorArguments';
import hoistStatics from 'hoist-non-react-statics';

export default function DragDropContext(backendOrModule) {
checkDecoratorArguments('DragDropContext', 'backend', ...arguments);
Expand Down Expand Up @@ -30,7 +31,7 @@ export default function DragDropContext(backendOrModule) {
DecoratedComponent.name ||
'Component';

return class DragDropContextContainer extends Component {
class DragDropContextContainer extends Component {
static DecoratedComponent = DecoratedComponent;

static displayName = `DragDropContext(${displayName})`;
Expand All @@ -57,6 +58,8 @@ export default function DragDropContext(backendOrModule) {
ref='child' />
);
}
};
}

return hoistStatics(DragDropContextContainer, DecoratedComponent);
};
}
}
7 changes: 5 additions & 2 deletions src/DragLayer.js
Expand Up @@ -4,6 +4,7 @@ import shallowEqualScalar from './utils/shallowEqualScalar';
import isPlainObject from 'lodash/isPlainObject';
import invariant from 'invariant';
import checkDecoratorArguments from './utils/checkDecoratorArguments';
import hoistStatics from 'hoist-non-react-statics';

export default function DragLayer(collect, options = {}) {
checkDecoratorArguments('DragLayer', 'collect[, options]', ...arguments);
Expand Down Expand Up @@ -31,7 +32,7 @@ export default function DragLayer(collect, options = {}) {
DecoratedComponent.name ||
'Component';

return class DragLayerContainer extends Component {
class DragLayerContainer extends Component {
static DecoratedComponent = DecoratedComponent;

static displayName = `DragLayer(${displayName})`;
Expand Down Expand Up @@ -110,6 +111,8 @@ export default function DragLayer(collect, options = {}) {
ref='child' />
);
}
};
}

return hoistStatics(DragLayerContainer, DecoratedComponent);
};
}
7 changes: 5 additions & 2 deletions src/decorateHandler.js
Expand Up @@ -4,6 +4,7 @@ import shallowEqual from './utils/shallowEqual';
import shallowEqualScalar from './utils/shallowEqualScalar';
import isPlainObject from 'lodash/isPlainObject';
import invariant from 'invariant';
import hoistStatics from 'hoist-non-react-statics';

export default function decorateHandler({
DecoratedComponent,
Expand All @@ -22,7 +23,7 @@ export default function decorateHandler({
DecoratedComponent.name ||
'Component';

return class DragDropContainer extends Component {
class DragDropContainer extends Component {
static DecoratedComponent = DecoratedComponent;

static displayName = `${containerDisplayName}(${displayName})`;
Expand Down Expand Up @@ -177,5 +178,7 @@ export default function decorateHandler({
ref={this.handleChildRef} />
);
}
};
}

return hoistStatics(DragDropContainer, DecoratedComponent);
}

0 comments on commit 7aa0cac

Please sign in to comment.