react-frame-component
Advanced tools
Comparing version 0.6.4 to 0.6.5
25
index.js
@@ -65,3 +65,3 @@ var React = require('react'); | ||
var doc = ReactDOM.findDOMNode(this).contentDocument; | ||
var doc = this.getDoc(); | ||
if(doc && doc.readyState === 'complete') { | ||
@@ -87,9 +87,4 @@ var contents = React.createElement('div', | ||
var callback = initialRender ? this.props.contentDidMount : this.props.contentDidUpdate; | ||
var mountTarget; | ||
var mountTarget = this.getMountTarget(); | ||
if(this.props.mountTarget) { | ||
mountTarget = doc.querySelector(this.props.mountTarget); | ||
} else { | ||
mountTarget = doc.body.children[0]; | ||
} | ||
@@ -103,2 +98,14 @@ ReactDOM.unstable_renderSubtreeIntoContainer(this, contents, mountTarget, callback); | ||
}, | ||
getMountTarget: function() { | ||
var doc = this.getDoc(); | ||
if(this.props.mountTarget) { | ||
return doc.querySelector(this.props.mountTarget); | ||
} | ||
return doc.body.children[0]; | ||
}, | ||
getDoc: function() { | ||
return ReactDOM.findDOMNode(this).contentDocument; | ||
}, | ||
componentDidUpdate: function() { | ||
@@ -110,5 +117,5 @@ this.renderFrameContents(); | ||
var doc = ReactDOM.findDOMNode(this).contentDocument; | ||
var doc = this.getDoc(); | ||
if (doc) { | ||
ReactDOM.unmountComponentAtNode(doc.body); | ||
ReactDOM.unmountComponentAtNode(this.getMountTarget()); | ||
} | ||
@@ -115,0 +122,0 @@ } |
{ | ||
"name": "react-frame-component", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"description": "React component to wrap your application or component in an iFrame for encapsulation purposes", | ||
@@ -40,4 +40,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"object-assign": "^3.0.0" | ||
"object-assign": "^4.1.0" | ||
} | ||
} |
@@ -256,2 +256,22 @@ "use strict"; | ||
}); | ||
it("should return first child element of the `body` on call to `this.getMountTarget()` if `props.mountTarget` was not passed in", function () { | ||
div = document.body.appendChild(document.createElement('div')); | ||
var frame = ReactDOM.render(<Frame />, div), | ||
body = ReactDOM.findDOMNode(frame).contentDocument.body; | ||
expect(Frame.prototype.getMountTarget.call(frame)).toEqual(body.children[0]); | ||
}); | ||
it("should return resolved `props.mountTarget` node on call to `this.getMountTarget()` if `props.mountTarget` was passed in", function () { | ||
div = document.body.appendChild(document.createElement('div')); | ||
var initialContent = '<!DOCTYPE html><html><head></head><body><div></div><div id="container"></div></body></html>'; | ||
var frame = ReactDOM.render(<Frame initialContent={initialContent} mountTarget='#container' />, div), | ||
body = ReactDOM.findDOMNode(frame).contentDocument.body; | ||
div = document.body.appendChild(document.createElement('div')); | ||
expect(Frame.prototype.getMountTarget.call(frame)).toEqual(body.querySelector('#container')); | ||
}); | ||
}); |
23535
492
+ Addedobject-assign@4.1.1(transitive)
- Removedobject-assign@3.0.0(transitive)
Updatedobject-assign@^4.1.0