forked from gaearon/react-transform-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Frame.js
64 lines (48 loc) · 1.35 KB
/
Frame.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { Component, PropTypes } from 'react';
import { findDOMNode, render } from 'react-dom';
// Propagates context to children
class FrameContent extends Component {
static childContextTypes = {
dragDropManager: PropTypes.object.isRequired
};
getChildContext() {
return this.props.context;
}
render() {
return <div>{this.props.children}</div>;
}
}
export default class Frame extends Component {
render() {
return <iframe></iframe>;
}
static contextTypes = {
dragDropManager: PropTypes.object.isRequired
};
renderContent() {
const { body } = findDOMNode(this).contentDocument;
// To avoid React warning when rendering into document.body
body.innerHTML = '<div></div>';
// Passing context as a property otherwise it will be lost
render(
<FrameContent context={this.context}>
{this.props.children}
</FrameContent>,
body.firstChild
);
const { dragDropManager } = this.context;
dragDropManager.backend.addEventListeners(body);
}
componentDidMount() {
this.renderContent();
}
componentDidUpdate() {
this.renderContent();
}
componentWillUnmount() {
const { body } = findDOMNode(this).contentDocument;
unmountComponentAtNode(body);
const { dragDropManager } = this.context;
dragDropManager.backend.removeEventListeners(body);
}
}