parsec-hooks 1.0.11 → 1.0.14

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,6 +1,6 @@
1
1
  declare const _default: () => {
2
2
  countdown: number;
3
- clearCountdownTimer: () => void;
3
+ clearCountdownTimer: () => boolean;
4
4
  stopCountdownTimer: () => void;
5
5
  setCountdown: (s: number) => Promise<unknown>;
6
6
  countdownText: string;
@@ -19,9 +19,9 @@ var _default = function _default() {
19
19
  countdown = _useRefState2[0],
20
20
  setCountdown = _useRefState2[1];
21
21
 
22
- var timer = (0, _react.useRef)();
22
+ var stopRef = (0, _react.useRef)(false);
23
23
  var clearCountdownTimer = (0, _react.useCallback)(function () {
24
- return timer.current && clearInterval(timer.current);
24
+ return stopRef.current = true;
25
25
  }, []);
26
26
  var stopCountdownTimer = (0, _react.useCallback)(function () {
27
27
  clearCountdownTimer();
@@ -33,19 +33,40 @@ var _default = function _default() {
33
33
  stopCountdownTimer: stopCountdownTimer,
34
34
  setCountdown: (0, _react.useCallback)(function (s) {
35
35
  return new Promise(function (resolve) {
36
- clearCountdownTimer();
37
- var countdown = s;
38
- setCountdown(countdown);
39
- timer.current = setInterval(function () {
40
- setCountdown(--countdown);
41
-
42
- if (!countdown) {
43
- clearCountdownTimer();
44
- resolve();
36
+ stopRef.current = false;
37
+ setCountdown(s);
38
+ var startTime = +new Date();
39
+
40
+ var start = function start(prev) {
41
+ var now = +new Date();
42
+
43
+ if (stopRef.current) {
44
+ return;
45
+ }
46
+
47
+ if (now - prev > 1000) {
48
+ var count = s - Math.round((now - startTime) / 1000);
49
+ setCountdown(count);
50
+
51
+ if (count <= 0) {
52
+ resolve();
53
+ } else {
54
+ requestAnimationFrame(function () {
55
+ return start(now);
56
+ });
57
+ }
58
+ } else {
59
+ requestAnimationFrame(function () {
60
+ return start(prev);
61
+ });
45
62
  }
46
- }, 1000);
63
+ };
64
+
65
+ requestAnimationFrame(function () {
66
+ return start(startTime);
67
+ });
47
68
  });
48
- }, [clearCountdownTimer, setCountdown]),
69
+ }, [setCountdown]),
49
70
  countdownText: countdown ? "(".concat(countdown, " s)") : ''
50
71
  };
51
72
  };
@@ -35,13 +35,13 @@ var _default = function _default(name, initState) {
35
35
  (0, _react.useLayoutEffect)(function () {
36
36
  globalObj[name].sets.push(setGlobalState);
37
37
  }, [name]);
38
- return [globalState, function (state) {
38
+ return [globalState, (0, _react.useCallback)(function (state) {
39
39
  globalObj[name].state = state;
40
40
  setGlobalState(state);
41
41
  globalObj[name].sets.forEach(function (fn) {
42
42
  return fn(state);
43
43
  });
44
- }];
44
+ }, [name])];
45
45
  };
46
46
 
47
47
  exports.default = _default;
@@ -5,14 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _wechat = require("remax-rn/src/wechat");
9
-
10
8
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
11
9
  // @ts-ignore
12
- var _default = function _default(pageName) {
13
- (0, _wechat.setNavigationBarTitle)({
14
- title: pageName
15
- });
10
+ // import { setNavigationBarTitle } from 'remax-rn/src/wechat';
11
+ var _default = function _default(pageName) {// setNavigationBarTitle({ title: pageName });
16
12
  };
17
13
 
18
14
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parsec-hooks",
3
- "version": "1.0.11",
3
+ "version": "1.0.14",
4
4
  "description": "秒差距前端常用的hooks工具",
5
5
  "author": "mushan0x0",
6
6
  "license": "MIT",