@peersyst/react-utils
Advanced tools
Comparing version 2.2.0 to 2.2.1
import { DeepPick, NestedKeys } from "@peersyst/react-types"; | ||
export default function <T extends object, K extends NestedKeys<T>>(obj: T, key: K): DeepPick<T, K>; | ||
export default function <T extends object, K extends NestedKeys<T>>(obj: T, key: K): DeepPick<T, K> | undefined; |
@@ -24,1 +24,3 @@ export { default as capitalize } from "./capitalize"; | ||
export { default as setRef } from "./setRef"; | ||
export { default as timeoutPromise } from "./timeoutPromise"; | ||
export * from "./timeoutPromise"; |
@@ -7,3 +7,4 @@ export declare type Polling<R> = Promise<R> & { | ||
maxIterations?: number; | ||
timeout?: number; | ||
} | ||
export default function <R>(fn: () => Promise<R>, condition: (res: R) => boolean, options?: PollingOptions): Polling<R>; | ||
export default function <R>(fn: () => Promise<R>, condition: (res: R) => boolean, options?: PollingOptions): Polling<R | undefined>; |
@@ -0,1 +1,2 @@ | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
import _toArray from "@babel/runtime/helpers/esm/toArray"; | ||
@@ -7,7 +8,9 @@ export default function (obj, key) { | ||
restKeys = _key$split2.slice(1); | ||
// @ts-ignore | ||
return restKeys.reduce(function (prev, curr) { | ||
return prev[curr]; | ||
}, obj[firstKey]); | ||
var value = obj[firstKey]; | ||
for (var _key in restKeys) { | ||
var _value; | ||
if (_typeof(value) !== "object" || value === null) return undefined; | ||
value = (_value = value) == null ? void 0 : _value[_key]; | ||
} | ||
return value; | ||
} |
@@ -23,2 +23,4 @@ export { default as capitalize } from "./capitalize"; | ||
export { default as rack } from "./rack"; | ||
export { default as setRef } from "./setRef"; | ||
export { default as setRef } from "./setRef"; | ||
export { default as timeoutPromise } from "./timeoutPromise"; | ||
export * from "./timeoutPromise"; |
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import timeoutPromise, { TimeoutPromiseError } from "./timeoutPromise"; | ||
export default function (fn, condition) { | ||
@@ -8,26 +9,63 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var polling = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var _options$delay, delay, maxIterations, i, res; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { | ||
var _options$delay, delay, maxIterations, timeoutMs, i, promiseDidTimeout, res, resolveFn, _resolveFn; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations; | ||
_resolveFn = function _resolveFn3() { | ||
_resolveFn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
promiseDidTimeout = false; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return timeoutMs !== undefined ? timeoutPromise(fn(), timeoutMs) : fn(); | ||
case 4: | ||
return _context2.abrupt("return", _context2.sent); | ||
case 7: | ||
_context2.prev = 7; | ||
_context2.t0 = _context2["catch"](1); | ||
if (!(_context2.t0 instanceof TimeoutPromiseError)) { | ||
_context2.next = 13; | ||
break; | ||
} | ||
promiseDidTimeout = true; | ||
_context2.next = 14; | ||
break; | ||
case 13: | ||
throw _context2.t0; | ||
case 14: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 7]]); | ||
})); | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
resolveFn = function _resolveFn2() { | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations, timeoutMs = options.timeout; | ||
i = 0; | ||
_context2.next = 4; | ||
return fn(); | ||
case 4: | ||
res = _context2.sent; | ||
case 5: | ||
if (!(!abort && condition(res))) { | ||
_context2.next = 12; | ||
promiseDidTimeout = false; | ||
_context3.next = 7; | ||
return resolveFn(); | ||
case 7: | ||
res = _context3.sent; | ||
case 8: | ||
if (!(!abort && (promiseDidTimeout || condition(res)))) { | ||
_context3.next = 15; | ||
break; | ||
} | ||
if (!(i === maxIterations)) { | ||
_context2.next = 8; | ||
_context3.next = 11; | ||
break; | ||
} | ||
throw new Error("Polling executed the maximum number iterations"); | ||
case 8: | ||
_context2.next = 10; | ||
case 11: | ||
_context3.next = 13; | ||
return new Promise(function (resolve) { | ||
@@ -41,3 +79,3 @@ timeout = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
_context.next = 3; | ||
return fn(); | ||
return resolveFn(); | ||
case 3: | ||
@@ -54,13 +92,13 @@ res = _context.sent; | ||
}); | ||
case 10: | ||
_context2.next = 5; | ||
case 13: | ||
_context3.next = 8; | ||
break; | ||
case 12: | ||
return _context2.abrupt("return", res); | ||
case 13: | ||
case 15: | ||
return _context3.abrupt("return", res); | ||
case 16: | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}, _callee3); | ||
})); | ||
@@ -67,0 +105,0 @@ return function polling() { |
@@ -0,1 +1,2 @@ | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
import _toArray from "@babel/runtime/helpers/esm/toArray"; | ||
@@ -7,7 +8,9 @@ export default function (obj, key) { | ||
restKeys = _key$split2.slice(1); | ||
// @ts-ignore | ||
return restKeys.reduce(function (prev, curr) { | ||
return prev[curr]; | ||
}, obj[firstKey]); | ||
var value = obj[firstKey]; | ||
for (var _key in restKeys) { | ||
var _value; | ||
if (_typeof(value) !== "object" || value === null) return undefined; | ||
value = (_value = value) == null ? void 0 : _value[_key]; | ||
} | ||
return value; | ||
} |
@@ -23,2 +23,4 @@ export { default as capitalize } from "./capitalize"; | ||
export { default as rack } from "./rack"; | ||
export { default as setRef } from "./setRef"; | ||
export { default as setRef } from "./setRef"; | ||
export { default as timeoutPromise } from "./timeoutPromise"; | ||
export * from "./timeoutPromise"; |
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import timeoutPromise, { TimeoutPromiseError } from "./timeoutPromise"; | ||
export default function (fn, condition) { | ||
@@ -8,26 +9,63 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var polling = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var _options$delay, delay, maxIterations, i, res; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { | ||
var _options$delay, delay, maxIterations, timeoutMs, i, promiseDidTimeout, res, resolveFn, _resolveFn; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations; | ||
_resolveFn = function _resolveFn3() { | ||
_resolveFn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
promiseDidTimeout = false; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return timeoutMs !== undefined ? timeoutPromise(fn(), timeoutMs) : fn(); | ||
case 4: | ||
return _context2.abrupt("return", _context2.sent); | ||
case 7: | ||
_context2.prev = 7; | ||
_context2.t0 = _context2["catch"](1); | ||
if (!(_context2.t0 instanceof TimeoutPromiseError)) { | ||
_context2.next = 13; | ||
break; | ||
} | ||
promiseDidTimeout = true; | ||
_context2.next = 14; | ||
break; | ||
case 13: | ||
throw _context2.t0; | ||
case 14: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 7]]); | ||
})); | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
resolveFn = function _resolveFn2() { | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations, timeoutMs = options.timeout; | ||
i = 0; | ||
_context2.next = 4; | ||
return fn(); | ||
case 4: | ||
res = _context2.sent; | ||
case 5: | ||
if (!(!abort && condition(res))) { | ||
_context2.next = 12; | ||
promiseDidTimeout = false; | ||
_context3.next = 7; | ||
return resolveFn(); | ||
case 7: | ||
res = _context3.sent; | ||
case 8: | ||
if (!(!abort && (promiseDidTimeout || condition(res)))) { | ||
_context3.next = 15; | ||
break; | ||
} | ||
if (!(i === maxIterations)) { | ||
_context2.next = 8; | ||
_context3.next = 11; | ||
break; | ||
} | ||
throw new Error("Polling executed the maximum number iterations"); | ||
case 8: | ||
_context2.next = 10; | ||
case 11: | ||
_context3.next = 13; | ||
return new Promise(function (resolve) { | ||
@@ -41,3 +79,3 @@ timeout = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
_context.next = 3; | ||
return fn(); | ||
return resolveFn(); | ||
case 3: | ||
@@ -54,13 +92,13 @@ res = _context.sent; | ||
}); | ||
case 10: | ||
_context2.next = 5; | ||
case 13: | ||
_context3.next = 8; | ||
break; | ||
case 12: | ||
return _context2.abrupt("return", res); | ||
case 13: | ||
case 15: | ||
return _context3.abrupt("return", res); | ||
case 16: | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}, _callee3); | ||
})); | ||
@@ -67,0 +105,0 @@ return function polling() { |
@@ -0,1 +1,2 @@ | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
import _toArray from "@babel/runtime/helpers/esm/toArray"; | ||
@@ -7,7 +8,9 @@ export default function (obj, key) { | ||
restKeys = _key$split2.slice(1); | ||
// @ts-ignore | ||
return restKeys.reduce(function (prev, curr) { | ||
return prev[curr]; | ||
}, obj[firstKey]); | ||
var value = obj[firstKey]; | ||
for (var _key in restKeys) { | ||
var _value; | ||
if (_typeof(value) !== "object" || value === null) return undefined; | ||
value = (_value = value) == null ? void 0 : _value[_key]; | ||
} | ||
return value; | ||
} |
@@ -23,2 +23,4 @@ export { default as capitalize } from "./capitalize"; | ||
export { default as rack } from "./rack"; | ||
export { default as setRef } from "./setRef"; | ||
export { default as setRef } from "./setRef"; | ||
export { default as timeoutPromise } from "./timeoutPromise"; | ||
export * from "./timeoutPromise"; |
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import timeoutPromise, { TimeoutPromiseError } from "./timeoutPromise"; | ||
export default function (fn, condition) { | ||
@@ -8,26 +9,63 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var polling = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var _options$delay, delay, maxIterations, i, res; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() { | ||
var _options$delay, delay, maxIterations, timeoutMs, i, promiseDidTimeout, res, resolveFn, _resolveFn; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations; | ||
_resolveFn = function _resolveFn3() { | ||
_resolveFn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
promiseDidTimeout = false; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return timeoutMs !== undefined ? timeoutPromise(fn(), timeoutMs) : fn(); | ||
case 4: | ||
return _context2.abrupt("return", _context2.sent); | ||
case 7: | ||
_context2.prev = 7; | ||
_context2.t0 = _context2["catch"](1); | ||
if (!(_context2.t0 instanceof TimeoutPromiseError)) { | ||
_context2.next = 13; | ||
break; | ||
} | ||
promiseDidTimeout = true; | ||
_context2.next = 14; | ||
break; | ||
case 13: | ||
throw _context2.t0; | ||
case 14: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 7]]); | ||
})); | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
resolveFn = function _resolveFn2() { | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations, timeoutMs = options.timeout; | ||
i = 0; | ||
_context2.next = 4; | ||
return fn(); | ||
case 4: | ||
res = _context2.sent; | ||
case 5: | ||
if (!(!abort && condition(res))) { | ||
_context2.next = 12; | ||
promiseDidTimeout = false; | ||
_context3.next = 7; | ||
return resolveFn(); | ||
case 7: | ||
res = _context3.sent; | ||
case 8: | ||
if (!(!abort && (promiseDidTimeout || condition(res)))) { | ||
_context3.next = 15; | ||
break; | ||
} | ||
if (!(i === maxIterations)) { | ||
_context2.next = 8; | ||
_context3.next = 11; | ||
break; | ||
} | ||
throw new Error("Polling executed the maximum number iterations"); | ||
case 8: | ||
_context2.next = 10; | ||
case 11: | ||
_context3.next = 13; | ||
return new Promise(function (resolve) { | ||
@@ -41,3 +79,3 @@ timeout = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
_context.next = 3; | ||
return fn(); | ||
return resolveFn(); | ||
case 3: | ||
@@ -54,13 +92,13 @@ res = _context.sent; | ||
}); | ||
case 10: | ||
_context2.next = 5; | ||
case 13: | ||
_context3.next = 8; | ||
break; | ||
case 12: | ||
return _context2.abrupt("return", res); | ||
case 13: | ||
case 15: | ||
return _context3.abrupt("return", res); | ||
case 16: | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}, _callee3); | ||
})); | ||
@@ -67,0 +105,0 @@ return function polling() { |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports["default"] = _default; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray")); | ||
@@ -15,7 +16,9 @@ function _default(obj, key) { | ||
restKeys = _key$split2.slice(1); | ||
// @ts-ignore | ||
return restKeys.reduce(function (prev, curr) { | ||
return prev[curr]; | ||
}, obj[firstKey]); | ||
var value = obj[firstKey]; | ||
for (var _key in restKeys) { | ||
var _value; | ||
if ((0, _typeof2["default"])(value) !== "object" || value === null) return undefined; | ||
value = (_value = value) == null ? void 0 : _value[_key]; | ||
} | ||
return value; | ||
} |
@@ -29,3 +29,4 @@ "use strict"; | ||
rack: true, | ||
setRef: true | ||
setRef: true, | ||
timeoutPromise: true | ||
}; | ||
@@ -158,2 +159,8 @@ Object.defineProperty(exports, "capitalize", { | ||
}); | ||
Object.defineProperty(exports, "timeoutPromise", { | ||
enumerable: true, | ||
get: function get() { | ||
return _timeoutPromise["default"]; | ||
} | ||
}); | ||
var _capitalize = _interopRequireDefault(require("./capitalize")); | ||
@@ -202,3 +209,15 @@ var _classify = _interopRequireDefault(require("./classify")); | ||
var _setRef = _interopRequireDefault(require("./setRef")); | ||
var _timeoutPromise = _interopRequireWildcard(require("./timeoutPromise")); | ||
Object.keys(_timeoutPromise).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _timeoutPromise[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _timeoutPromise[key]; | ||
} | ||
}); | ||
}); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,2 +11,5 @@ value: true | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _timeoutPromise = _interopRequireWildcard(require("./timeoutPromise")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _default(fn, condition) { | ||
@@ -16,26 +20,63 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var polling = /*#__PURE__*/function () { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { | ||
var _options$delay, delay, maxIterations, i, res; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() { | ||
var _options$delay, delay, maxIterations, timeoutMs, i, promiseDidTimeout, res, resolveFn, _resolveFn; | ||
return _regenerator["default"].wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations; | ||
_resolveFn = function _resolveFn3() { | ||
_resolveFn = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
promiseDidTimeout = false; | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
return timeoutMs !== undefined ? (0, _timeoutPromise["default"])(fn(), timeoutMs) : fn(); | ||
case 4: | ||
return _context2.abrupt("return", _context2.sent); | ||
case 7: | ||
_context2.prev = 7; | ||
_context2.t0 = _context2["catch"](1); | ||
if (!(_context2.t0 instanceof _timeoutPromise.TimeoutPromiseError)) { | ||
_context2.next = 13; | ||
break; | ||
} | ||
promiseDidTimeout = true; | ||
_context2.next = 14; | ||
break; | ||
case 13: | ||
throw _context2.t0; | ||
case 14: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[1, 7]]); | ||
})); | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
resolveFn = function _resolveFn2() { | ||
return _resolveFn.apply(this, arguments); | ||
}; | ||
_options$delay = options.delay, delay = _options$delay === void 0 ? 1000 : _options$delay, maxIterations = options.maxIterations, timeoutMs = options.timeout; | ||
i = 0; | ||
_context2.next = 4; | ||
return fn(); | ||
case 4: | ||
res = _context2.sent; | ||
case 5: | ||
if (!(!abort && condition(res))) { | ||
_context2.next = 12; | ||
promiseDidTimeout = false; | ||
_context3.next = 7; | ||
return resolveFn(); | ||
case 7: | ||
res = _context3.sent; | ||
case 8: | ||
if (!(!abort && (promiseDidTimeout || condition(res)))) { | ||
_context3.next = 15; | ||
break; | ||
} | ||
if (!(i === maxIterations)) { | ||
_context2.next = 8; | ||
_context3.next = 11; | ||
break; | ||
} | ||
throw new Error("Polling executed the maximum number iterations"); | ||
case 8: | ||
_context2.next = 10; | ||
case 11: | ||
_context3.next = 13; | ||
return new Promise(function (resolve) { | ||
@@ -49,3 +90,3 @@ timeout = setTimeout( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
_context.next = 3; | ||
return fn(); | ||
return resolveFn(); | ||
case 3: | ||
@@ -62,13 +103,13 @@ res = _context.sent; | ||
}); | ||
case 10: | ||
_context2.next = 5; | ||
case 13: | ||
_context3.next = 8; | ||
break; | ||
case 12: | ||
return _context2.abrupt("return", res); | ||
case 13: | ||
case 15: | ||
return _context3.abrupt("return", res); | ||
case 16: | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}, _callee3); | ||
})); | ||
@@ -75,0 +116,0 @@ return function polling() { |
{ | ||
"name": "@peersyst/react-utils", | ||
"author": "Peersyst", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "./node/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
175541
134
3658