@bigbinary/neeto-commons-frontend 3.1.9 → 3.1.11
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.
|
@@ -1,50 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports["default"] = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
7
|
var _react = require("react");
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setInterval(function () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
8
|
+
var _neetoCist = require("@bigbinary/neeto-cist");
|
|
9
|
+
var subscriptions = [];
|
|
10
|
+
var interval = null;
|
|
11
|
+
var initiateInterval = function initiateInterval() {
|
|
12
|
+
// Create new interval if there are no subscriptions.
|
|
13
|
+
if ((0, _neetoCist.isNotEmpty)(subscriptions)) return;
|
|
14
|
+
interval = setInterval(function () {
|
|
15
|
+
subscriptions.forEach(function (callback) {
|
|
16
|
+
return callback();
|
|
17
|
+
});
|
|
18
|
+
}, 1000);
|
|
19
|
+
};
|
|
20
|
+
var cleanupInterval = function cleanupInterval() {
|
|
21
|
+
// Cleanup existing interval if there are no more subscriptions
|
|
22
|
+
if ((0, _neetoCist.isNotEmpty)(subscriptions)) return;
|
|
23
|
+
clearInterval(interval);
|
|
24
|
+
};
|
|
25
|
+
var subscribe = function subscribe(callback) {
|
|
26
|
+
initiateInterval();
|
|
27
|
+
subscriptions.push(callback);
|
|
28
|
+
return function () {
|
|
29
|
+
subscriptions.splice(subscriptions.indexOf(callback), 1);
|
|
30
|
+
cleanupInterval();
|
|
31
|
+
};
|
|
32
|
+
};
|
|
32
33
|
var useTimer = function useTimer() {
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return function () {
|
|
44
|
-
return useTimerStore.setState((0, _ramda.omit)([key], useTimerStore.getState()), true);
|
|
45
|
-
};
|
|
46
|
-
}, [interval, key]);
|
|
47
|
-
return useTimerStore((0, _ramda.prop)(key));
|
|
34
|
+
var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 60;
|
|
35
|
+
var lastUpdatedRef = (0, _react.useRef)(Date.now());
|
|
36
|
+
return (0, _react.useSyncExternalStore)(subscribe, function () {
|
|
37
|
+
var now = Date.now();
|
|
38
|
+
var lastUpdated = lastUpdatedRef.current;
|
|
39
|
+
if (now - lastUpdated >= delay * 1000) lastUpdated = now;
|
|
40
|
+
lastUpdatedRef.current = lastUpdated;
|
|
41
|
+
return lastUpdated;
|
|
42
|
+
});
|
|
48
43
|
};
|
|
49
44
|
var _default = useTimer;
|
|
50
45
|
exports["default"] = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTimer.js","names":["_react","require","
|
|
1
|
+
{"version":3,"file":"useTimer.js","names":["_react","require","_neetoCist","subscriptions","interval","initiateInterval","isNotEmpty","setInterval","forEach","callback","cleanupInterval","clearInterval","subscribe","push","splice","indexOf","useTimer","delay","arguments","length","undefined","lastUpdatedRef","useRef","Date","now","useSyncExternalStore","lastUpdated","current","_default","exports"],"sources":["../../../../src/react-utils/useTimer/useTimer.js"],"sourcesContent":["import { useRef, useSyncExternalStore } from \"react\";\n\nimport { isNotEmpty } from \"neetocist\";\n\nconst subscriptions = [];\nlet interval = null;\n\nconst initiateInterval = () => {\n // Create new interval if there are no subscriptions.\n if (isNotEmpty(subscriptions)) return;\n interval = setInterval(() => {\n subscriptions.forEach(callback => callback());\n }, 1000);\n};\n\nconst cleanupInterval = () => {\n // Cleanup existing interval if there are no more subscriptions\n if (isNotEmpty(subscriptions)) return;\n clearInterval(interval);\n};\n\nconst subscribe = callback => {\n initiateInterval();\n subscriptions.push(callback);\n\n return () => {\n subscriptions.splice(subscriptions.indexOf(callback), 1);\n cleanupInterval();\n };\n};\n\nconst useTimer = (delay = 60) => {\n const lastUpdatedRef = useRef(Date.now());\n\n return useSyncExternalStore(subscribe, () => {\n const now = Date.now();\n let lastUpdated = lastUpdatedRef.current;\n if (now - lastUpdated >= delay * 1000) lastUpdated = now;\n lastUpdatedRef.current = lastUpdated;\n\n return lastUpdated;\n });\n};\n\nexport default useTimer;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAME,aAAa,GAAG,EAAE;AACxB,IAAIC,QAAQ,GAAG,IAAI;AAEnB,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAA,EAAS;EAC7B;EACA,IAAI,IAAAC,qBAAU,EAACH,aAAa,CAAC,EAAE;EAC/BC,QAAQ,GAAGG,WAAW,CAAC,YAAM;IAC3BJ,aAAa,CAACK,OAAO,CAAC,UAAAC,QAAQ;MAAA,OAAIA,QAAQ,EAAE;IAAA,EAAC;EAC/C,CAAC,EAAE,IAAI,CAAC;AACV,CAAC;AAED,IAAMC,eAAe,GAAG,SAAlBA,eAAeA,CAAA,EAAS;EAC5B;EACA,IAAI,IAAAJ,qBAAU,EAACH,aAAa,CAAC,EAAE;EAC/BQ,aAAa,CAACP,QAAQ,CAAC;AACzB,CAAC;AAED,IAAMQ,SAAS,GAAG,SAAZA,SAASA,CAAGH,QAAQ,EAAI;EAC5BJ,gBAAgB,EAAE;EAClBF,aAAa,CAACU,IAAI,CAACJ,QAAQ,CAAC;EAE5B,OAAO,YAAM;IACXN,aAAa,CAACW,MAAM,CAACX,aAAa,CAACY,OAAO,CAACN,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxDC,eAAe,EAAE;EACnB,CAAC;AACH,CAAC;AAED,IAAMM,QAAQ,GAAG,SAAXA,QAAQA,CAAA,EAAmB;EAAA,IAAfC,KAAK,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAC1B,IAAMG,cAAc,GAAG,IAAAC,aAAM,EAACC,IAAI,CAACC,GAAG,EAAE,CAAC;EAEzC,OAAO,IAAAC,2BAAoB,EAACb,SAAS,EAAE,YAAM;IAC3C,IAAMY,GAAG,GAAGD,IAAI,CAACC,GAAG,EAAE;IACtB,IAAIE,WAAW,GAAGL,cAAc,CAACM,OAAO;IACxC,IAAIH,GAAG,GAAGE,WAAW,IAAIT,KAAK,GAAG,IAAI,EAAES,WAAW,GAAGF,GAAG;IACxDH,cAAc,CAACM,OAAO,GAAGD,WAAW;IAEpC,OAAOA,WAAW;EACpB,CAAC,CAAC;AACJ,CAAC;AAAC,IAAAE,QAAA,GAEaZ,QAAQ;AAAAa,OAAA,cAAAD,QAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.11",
|
|
4
4
|
"description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
|
|
6
6
|
"author": "Amaljith K <amaljith.k@bigbinary.com>",
|
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { useRef, useSyncExternalStore } from "react";
|
|
2
|
+
import { isNotEmpty } from "@bigbinary/neeto-cist";
|
|
3
|
+
var subscriptions = [];
|
|
4
|
+
var interval = null;
|
|
5
|
+
var initiateInterval = function initiateInterval() {
|
|
6
|
+
// Create new interval if there are no subscriptions.
|
|
7
|
+
if (isNotEmpty(subscriptions)) return;
|
|
8
|
+
interval = setInterval(function () {
|
|
9
|
+
subscriptions.forEach(function (callback) {
|
|
10
|
+
return callback();
|
|
11
|
+
});
|
|
12
|
+
}, 1000);
|
|
13
|
+
};
|
|
14
|
+
var cleanupInterval = function cleanupInterval() {
|
|
15
|
+
// Cleanup existing interval if there are no more subscriptions
|
|
16
|
+
if (isNotEmpty(subscriptions)) return;
|
|
17
|
+
clearInterval(interval);
|
|
18
|
+
};
|
|
19
|
+
var subscribe = function subscribe(callback) {
|
|
20
|
+
initiateInterval();
|
|
21
|
+
subscriptions.push(callback);
|
|
22
|
+
return function () {
|
|
23
|
+
subscriptions.splice(subscriptions.indexOf(callback), 1);
|
|
24
|
+
cleanupInterval();
|
|
25
|
+
};
|
|
26
|
+
};
|
|
25
27
|
var useTimer = function useTimer() {
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return function () {
|
|
37
|
-
return useTimerStore.setState(omit([key], useTimerStore.getState()), true);
|
|
38
|
-
};
|
|
39
|
-
}, [interval, key]);
|
|
40
|
-
return useTimerStore(prop(key));
|
|
28
|
+
var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 60;
|
|
29
|
+
var lastUpdatedRef = useRef(Date.now());
|
|
30
|
+
return useSyncExternalStore(subscribe, function () {
|
|
31
|
+
var now = Date.now();
|
|
32
|
+
var lastUpdated = lastUpdatedRef.current;
|
|
33
|
+
if (now - lastUpdated >= delay * 1000) lastUpdated = now;
|
|
34
|
+
lastUpdatedRef.current = lastUpdated;
|
|
35
|
+
return lastUpdated;
|
|
36
|
+
});
|
|
41
37
|
};
|
|
42
38
|
export default useTimer;
|
|
43
39
|
//# sourceMappingURL=useTimer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTimer.js","names":["
|
|
1
|
+
{"version":3,"file":"useTimer.js","names":["useRef","useSyncExternalStore","isNotEmpty","subscriptions","interval","initiateInterval","setInterval","forEach","callback","cleanupInterval","clearInterval","subscribe","push","splice","indexOf","useTimer","delay","arguments","length","undefined","lastUpdatedRef","Date","now","lastUpdated","current"],"sources":["../../../src/react-utils/useTimer/useTimer.js"],"sourcesContent":["import { useRef, useSyncExternalStore } from \"react\";\n\nimport { isNotEmpty } from \"neetocist\";\n\nconst subscriptions = [];\nlet interval = null;\n\nconst initiateInterval = () => {\n // Create new interval if there are no subscriptions.\n if (isNotEmpty(subscriptions)) return;\n interval = setInterval(() => {\n subscriptions.forEach(callback => callback());\n }, 1000);\n};\n\nconst cleanupInterval = () => {\n // Cleanup existing interval if there are no more subscriptions\n if (isNotEmpty(subscriptions)) return;\n clearInterval(interval);\n};\n\nconst subscribe = callback => {\n initiateInterval();\n subscriptions.push(callback);\n\n return () => {\n subscriptions.splice(subscriptions.indexOf(callback), 1);\n cleanupInterval();\n };\n};\n\nconst useTimer = (delay = 60) => {\n const lastUpdatedRef = useRef(Date.now());\n\n return useSyncExternalStore(subscribe, () => {\n const now = Date.now();\n let lastUpdated = lastUpdatedRef.current;\n if (now - lastUpdated >= delay * 1000) lastUpdated = now;\n lastUpdatedRef.current = lastUpdated;\n\n return lastUpdated;\n });\n};\n\nexport default useTimer;\n"],"mappings":"AAAA,SAASA,M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