Socket
Socket
Sign inDemoInstall

promise-react-component

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-react-component - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

43

lib/index.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc