react-usespinner 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/usespinner.js +8 -18
  2. package/package.json +1 -1
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
3
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
4
  if (ar || !(i in from)) {
@@ -22,12 +11,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
22
11
  Object.defineProperty(exports, "__esModule", { value: true });
23
12
  var jsx_runtime_1 = require("react/jsx-runtime");
24
13
  var react_1 = require("react");
25
- var react_2 = require("react");
26
14
  var useSpinner = function (globalOptions) {
27
15
  // store a list of actions
28
- var _a = (0, react_2.useState)([]), actions = _a[0], setActions = _a[1];
16
+ var _a = (0, react_1.useState)([]), actions = _a[0], setActions = _a[1];
29
17
  // set a timer that every second checks if any actions can be closed
30
- (0, react_2.useEffect)(function () {
18
+ (0, react_1.useEffect)(function () {
31
19
  var timer = setTimeout(function () {
32
20
  if (actions) {
33
21
  setActions(function (prev) { return prev.filter(function (item) { return item.endtime > Date.now(); }); });
@@ -54,7 +42,7 @@ var useSpinner = function (globalOptions) {
54
42
  var busy = function () {
55
43
  return actions && actions.length > 0;
56
44
  };
57
- var fetch = (0, react_1.useCallback)(function () {
45
+ var fetch = function () {
58
46
  var params = [];
59
47
  for (var _i = 0; _i < arguments.length; _i++) {
60
48
  params[_i] = arguments[_i];
@@ -62,11 +50,12 @@ var useSpinner = function (globalOptions) {
62
50
  var createUUID = function () {
63
51
  // https://www.arungudelli.com/tutorial/javascript/how-to-create-uuid-guid-in-javascript-with-examples/
64
52
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
65
- var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
53
+ var r = Math.random() * 16 | 0, v = c === 'x' ? r : ((r & 0x3) | 0x8);
66
54
  return v.toString(16);
67
55
  });
68
56
  };
69
57
  var id = createUUID();
58
+ console.log("Start fetch", id, params);
70
59
  start(id);
71
60
  return new Promise(function (resolve, reject) {
72
61
  var config = params[1] || {};
@@ -78,10 +67,11 @@ var useSpinner = function (globalOptions) {
78
67
  reject(err);
79
68
  })
80
69
  .finally(function () {
70
+ console.log("End fetch", id);
81
71
  end(id);
82
72
  });
83
73
  });
84
- }, [end, start]);
74
+ };
85
75
  // JSX component used to wrap spinner of choice
86
76
  var SpinnerContainer = function (_a) {
87
77
  var spinner = _a.spinner, children = _a.children;
@@ -89,7 +79,7 @@ var useSpinner = function (globalOptions) {
89
79
  if (actions && actions.length > 0) {
90
80
  return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: spinner });
91
81
  }
92
- return (0, jsx_runtime_1.jsx)("div", __assign({ className: "useSpinner" }, { children: children }));
82
+ return (0, jsx_runtime_1.jsx)("div", { children: children });
93
83
  };
94
84
  // return hook values
95
85
  return { start: start, end: end, clear: clear, busy: busy, fetch: fetch, SpinnerContainer: SpinnerContainer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-usespinner",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Track actions in progress to know if a spinner should be display. Actions expire within 10 seconds if not expired in code",
5
5
  "private": false,
6
6
  "license": "MIT",