Skip to content

Commit

Permalink
feat: add the target component props to the collector funtion signature
Browse files Browse the repository at this point in the history
this will allow collector functions to encode logic based on incoming props of the component
  • Loading branch information
darthtrevino committed Mar 21, 2019
1 parent 1d7207e commit 2a7a237
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/examples/src/00 Chessboard/BoardSquare.tsx
Expand Up @@ -32,7 +32,7 @@ const squareTarget = {
},
}

const collect: DropTargetCollector<CollectedProps> = (
const collect: DropTargetCollector<CollectedProps, BoardSquareProps> = (
connect: DropTargetConnector,
monitor: DropTargetMonitor,
) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dnd/src/DragSource.ts
Expand Up @@ -27,7 +27,7 @@ const isPlainObject = require('lodash/isPlainObject')
export default function DragSource<Props, CollectedProps = {}, DragObject = {}>(
type: SourceType | ((props: Props) => SourceType),
spec: DragSourceSpec<Props, DragObject>,
collect: DragSourceCollector<CollectedProps>,
collect: DragSourceCollector<CollectedProps, Props>,
options: DndOptions<Props> = {},
) {
checkDecoratorArguments(
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dnd/src/DropTarget.ts
Expand Up @@ -20,7 +20,7 @@ const isPlainObject = require('lodash/isPlainObject')
export default function DropTarget<Props, CollectedProps = {}>(
type: TargetType | ((props: Props) => TargetType),
spec: DropTargetSpec<Props>,
collect: DropTargetCollector<CollectedProps>,
collect: DropTargetCollector<CollectedProps, Props>,
options: DndOptions<Props> = {},
) {
checkDecoratorArguments(
Expand Down
1 change: 1 addition & 0 deletions packages/react-dnd/src/decorateHandler.tsx
Expand Up @@ -178,6 +178,7 @@ export default function decorateHandler<Props, ItemIdType>({
const nextState = collect(
this.handlerConnector.hooks,
this.handlerMonitor,
this.props,
)

if (process.env.NODE_ENV !== 'production') {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dnd/src/interfaces/classApi.ts
Expand Up @@ -171,14 +171,16 @@ export interface DropTargetConnector {
dropTarget(): ConnectDropTarget
}

export type DragSourceCollector<CollectedProps> = (
export type DragSourceCollector<CollectedProps, TargetProps> = (
connect: DragSourceConnector,
monitor: DragSourceMonitor,
props: TargetProps,
) => CollectedProps

export type DropTargetCollector<CollectedProps> = (
export type DropTargetCollector<CollectedProps, TargetProps> = (
connect: DropTargetConnector,
monitor: DropTargetMonitor,
props: TargetProps,
) => CollectedProps

export type DragLayerCollector<TargetProps, CollectedProps> = (
Expand Down

0 comments on commit 2a7a237

Please sign in to comment.