promise-react-component
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -35,7 +35,31 @@ "use strict"; | ||
_this.state = { | ||
status: "pending", | ||
result: undefined, | ||
error: undefined | ||
_this.attachPromise = function (promise) { | ||
var onSuccess = function onSuccess(result) { | ||
return new Promise(function (resolve) { | ||
return _this.setState({ status: "resolved", result: result }, resolve); | ||
}); | ||
}; | ||
var onError = function onError(error) { | ||
return new Promise(function (undefined, reject) { | ||
return _this.setState({ status: "rejected", error: error }, function () { | ||
return reject(error); | ||
}); | ||
}); | ||
}; | ||
promise.then(onSuccess).catch(onError); | ||
}; | ||
_this.componentWillReceiveProps = function (_ref) { | ||
var nextPromise = _ref.promise; | ||
if (_this.props.promise === nextPromise) return; | ||
_this.setState({ status: "pending" }, function () { | ||
return _this.attachPromise(nextPromise); | ||
}); | ||
}; | ||
_this.state = { status: "pending", result: undefined, error: undefined }; | ||
return _this; | ||
@@ -47,12 +71,3 @@ } | ||
value: function componentDidMount() { | ||
var _this2 = this; | ||
var promise = this.props.promise; | ||
promise.then(function (result) { | ||
return _this2.setState({ status: "resolved", result: result }); | ||
}).catch(function (error) { | ||
return _this2.setState({ status: "rejected", error: error }); | ||
}); | ||
this.attachPromise(this.props.promise); | ||
} | ||
@@ -59,0 +74,0 @@ }, { |
{ | ||
"name": "promise-react-component", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A utility React component that renders its contents based on lifecycle state of a specified Promise", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
74442
86