Skip to content

Commit

Permalink
DragDropContextProvider don't recreate child context (#859)
Browse files Browse the repository at this point in the history
* DragDropContextProvider don't recreate child context

* .
  • Loading branch information
WearyMonkey authored and darthtrevino committed Oct 7, 2017
1 parent c6bf3af commit 0dfa63b
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions packages/react-dnd/src/DragDropContextProvider.js
Expand Up @@ -29,32 +29,40 @@ export default class DragDropContextProvider extends Component {
window: PropTypes.object,
}

constructor(props, context) {
super(props, context)
this.backend = unpackBackendForEs5Users(props.backend)
}
constructor(props, context) {
super(props, context)

getChildContext() {
/**
/**
* This property determines which window global to use for creating the DragDropManager.
* If a window has been injected explicitly via props, that is used first. If it is available
* as a context value, then use that, otherwise use the browser global.
*/
const getWindow = () => {
if (this.props && this.props.window) {
return this.props.window
} else if (this.context && this.context.window) {
return this.context.window
} else if (typeof window !== 'undefined') {
return window
}
return undefined
}

return createChildContext(this.backend, { window: getWindow() })
}
const getWindow = () => {
if (props && props.window) {
return props.window
} else if (context && context.window) {
return context.window
} else if (typeof window !== 'undefined') {
return window
}
return undefined
};

render() {
return Children.only(this.props.children)
}
this.backend = unpackBackendForEs5Users(props.backend)
this.childContext = createChildContext(this.backend, { window: getWindow() })
}

componentWillReceiveProps(nextProps) {
if (nextProps.backend !== this.props.backend || nextProps.window !== this.props.window) {
throw new Error('DragDropContextProvider backend and window props must not change.')
}
}

getChildContext() {
return this.childContext
}

render() {
return Children.only(this.props.children)
}
}

0 comments on commit 0dfa63b

Please sign in to comment.