react-super-components
Advanced tools
Comparing version 0.3.10 to 0.4.0
@@ -52,2 +52,13 @@ 'use strict'; | ||
_createClass(Image, [{ | ||
key: 'componentWillMount', | ||
value: function componentWillMount() { | ||
var src = this.props.src; | ||
var image = new window.Image(); | ||
image.src = src; | ||
if (image.complete) { | ||
this.setState({ status: 'display' }); | ||
} | ||
} | ||
}, { | ||
key: 'componentDidMount', | ||
@@ -57,4 +68,11 @@ value: function componentDidMount() { | ||
var status = this.state.status; | ||
if (status === 'display') { | ||
var imageDidLoad = this.props.imageDidLoad; | ||
if (imageDidLoad) imageDidLoad(); | ||
return; | ||
} | ||
this.$imageNode = (0, _jquery2.default)(_reactDom2.default.findDOMNode(this)); | ||
this.$imageNode.on('inview', function (event, isInView) { | ||
@@ -65,10 +83,14 @@ _this2.$imageNode.off('inview'); | ||
image.onload = function (e) { | ||
// NOTE: the timeout is meant to exagerate the loading time | ||
window.setTimeout(function () { | ||
_this2.setState({ status: 'display' }); | ||
}, 1000); | ||
_this2.setState({ status: 'display' }); | ||
var imageDidLoad = _this2.props.imageDidLoad; | ||
if (imageDidLoad) imageDidLoad(); | ||
}; | ||
image.onerror = function () { | ||
_this2.setState({ status: 'error' }); | ||
var imageDidLoad = _this2.props.imageDidLoad; | ||
if (imageDidLoad) imageDidLoad(Error('image failed to load')); | ||
}; | ||
image.src = _this2.props.src; | ||
@@ -80,3 +102,3 @@ }); | ||
value: function componentWillUnmount() { | ||
this.$imageNode.off('inview'); | ||
if (this.$imageNode) this.$imageNode.off('inview'); | ||
} | ||
@@ -137,5 +159,6 @@ }, { | ||
errorComponent: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.object]), | ||
wrapperProps: _react.PropTypes.object | ||
wrapperProps: _react.PropTypes.object, | ||
imageDidLoad: _react.PropTypes.func | ||
}; | ||
exports.default = Image; |
@@ -46,3 +46,3 @@ { | ||
}, | ||
"version": "0.3.10" | ||
"version": "0.4.0" | ||
} |
# React Super Components | ||
[![travis][travis-image]][travis-url] | ||
[![npm][npm-image]][npm-url] | ||
@@ -4,0 +5,0 @@ [![semantic-release][semantic-release-image]][semantic-release-url] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
66561
980
41
0