@khanacademy/wonder-blocks-timing 4.0.2 → 5.0.1
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.
- package/CHANGELOG.md +18 -0
- package/dist/es/index.js +89 -104
- package/dist/hooks/use-interval.d.ts +27 -5
- package/dist/hooks/use-timeout.d.ts +27 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +88 -104
- package/dist/util/animation-frame.d.ts +6 -6
- package/dist/util/interval.d.ts +7 -7
- package/dist/util/policies.d.ts +12 -8
- package/dist/util/timeout.d.ts +7 -6
- package/dist/util/types.d.ts +18 -10
- package/package.json +2 -2
- package/src/hooks/__tests__/use-interval.test.ts +453 -56
- package/src/hooks/__tests__/use-timeout.test.ts +412 -58
- package/src/hooks/use-interval.ts +90 -25
- package/src/hooks/use-timeout.ts +90 -25
- package/src/index.ts +4 -14
- package/src/util/animation-frame.ts +12 -16
- package/src/util/interval.ts +12 -16
- package/src/util/policies.ts +13 -8
- package/src/util/timeout.ts +13 -16
- package/src/util/types.ts +19 -11
- package/tsconfig-build.json +2 -4
- package/tsconfig-build.tsbuildinfo +1 -1
- package/dist/hooks/internal/use-updating-ref.d.ts +0 -13
- package/dist/hooks/use-scheduled-interval.d.ts +0 -2
- package/dist/hooks/use-scheduled-timeout.d.ts +0 -2
- package/src/hooks/__tests__/use-scheduled-interval.test.ts +0 -460
- package/src/hooks/__tests__/use-scheduled-timeout.test.ts +0 -478
- package/src/hooks/internal/use-updating-ref.ts +0 -23
- package/src/hooks/use-scheduled-interval.ts +0 -72
- package/src/hooks/use-scheduled-timeout.ts +0 -79
package/dist/util/policies.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export declare
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
export declare enum SchedulePolicy {
|
|
2
|
+
Immediately = "schedule-immediately",
|
|
3
|
+
OnDemand = "schedule-on-demand"
|
|
4
|
+
}
|
|
5
|
+
export declare enum ClearPolicy {
|
|
6
|
+
Resolve = "resolve-on-clear",
|
|
7
|
+
Cancel = "cancel-on-clear"
|
|
8
|
+
}
|
|
9
|
+
export declare enum ActionPolicy {
|
|
10
|
+
Reset = "reset",
|
|
11
|
+
Passive = "passive"
|
|
12
|
+
}
|
package/dist/util/timeout.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SchedulePolicy, ClearPolicy } from "./policies";
|
|
2
|
+
import type { ITimeout } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* Encapsulates everything associated with calling setTimeout/clearTimeout, and
|
|
4
5
|
* managing the lifecycle of that timer, including the ability to resolve or
|
|
@@ -16,10 +17,10 @@ export default class Timeout implements ITimeout {
|
|
|
16
17
|
* Creates a timeout that will invoke the given action after
|
|
17
18
|
* the given period. The timeout does not start until set is called.
|
|
18
19
|
*
|
|
19
|
-
* @param
|
|
20
|
+
* @param action The action to be invoked when the timeout
|
|
20
21
|
* period has passed.
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
22
|
+
* @param timeoutMs The timeout period.
|
|
23
|
+
* @param [schedulePolicy] When SchedulePolicy.Immediately,
|
|
23
24
|
* the timer is set immediately on instantiation; otherwise, `set` must be
|
|
24
25
|
* called to set the timeout.
|
|
25
26
|
* Defaults to `SchedulePolicy.Immediately`.
|
|
@@ -29,7 +30,7 @@ export default class Timeout implements ITimeout {
|
|
|
29
30
|
/**
|
|
30
31
|
* Determine if the timeout is set or not.
|
|
31
32
|
*
|
|
32
|
-
* @returns
|
|
33
|
+
* @returns true if the timeout is set (aka pending), otherwise
|
|
33
34
|
* false.
|
|
34
35
|
* @memberof Timeout
|
|
35
36
|
*/
|
|
@@ -50,7 +51,7 @@ export default class Timeout implements ITimeout {
|
|
|
50
51
|
* If the timeout is pending, this cancels that pending timeout without
|
|
51
52
|
* invoking the action. If no timeout is pending, this does nothing.
|
|
52
53
|
*
|
|
53
|
-
* @param
|
|
54
|
+
* @param [policy] When ClearPolicy.Resolve, if the request
|
|
54
55
|
* was set when called, the request action is invoked after cancelling
|
|
55
56
|
* the request; otherwise, the pending action is cancelled.
|
|
56
57
|
* Defaults to `ClearPolicy.Cancel`.
|
package/dist/util/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export type ClearPolicy = "resolve-on-clear" | "cancel-on-clear";
|
|
1
|
+
import * as Policies from "./policies";
|
|
3
2
|
/**
|
|
4
3
|
* Encapsulates everything associated with calling setTimeout/clearTimeout, and
|
|
5
4
|
* managing the lifecycle of that timer, including the ability to resolve or
|
|
@@ -33,14 +32,14 @@ export interface ITimeout {
|
|
|
33
32
|
* If the timeout is pending, this cancels that pending timeout. If no
|
|
34
33
|
* timeout is pending, this does nothing.
|
|
35
34
|
*
|
|
36
|
-
* @param
|
|
35
|
+
* @param [policy] When ClearPolicy.Resolve, if the request
|
|
37
36
|
* was set when called, the request action is invoked after cancelling
|
|
38
37
|
* the request; otherwise, the pending action is cancelled.
|
|
39
38
|
* Defaults to `ClearPolicy.Cancel`.
|
|
40
39
|
*
|
|
41
40
|
* @memberof ITimeout
|
|
42
41
|
*/
|
|
43
|
-
clear(policy?: ClearPolicy): void;
|
|
42
|
+
clear(policy?: Policies.ClearPolicy): void;
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
46
45
|
* Encapsulates everything associated with calling setInterval/clearInterval,
|
|
@@ -73,14 +72,14 @@ export interface IInterval {
|
|
|
73
72
|
* If the interval is active, this cancels that interval. If the interval
|
|
74
73
|
* is not active, this does nothing.
|
|
75
74
|
*
|
|
76
|
-
* @param
|
|
75
|
+
* @param [policy] When ClearPolicy.Resolve, if the request
|
|
77
76
|
* was set when called, the request action is invoked after cancelling
|
|
78
77
|
* the request; otherwise, the pending action is cancelled.
|
|
79
78
|
* Defaults to `ClearPolicy.Cancel`.
|
|
80
79
|
*
|
|
81
80
|
* @memberof IInterval
|
|
82
81
|
*/
|
|
83
|
-
clear(policy?: ClearPolicy): void;
|
|
82
|
+
clear(policy?: Policies.ClearPolicy): void;
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
86
85
|
* Encapsulates everything associated with calling requestAnimationFrame/
|
|
@@ -115,18 +114,27 @@ export interface IAnimationFrame {
|
|
|
115
114
|
* If the request is pending, this cancels that pending request. If no
|
|
116
115
|
* request is pending, this does nothing.
|
|
117
116
|
*
|
|
118
|
-
* @param
|
|
117
|
+
* @param [policy] When ClearPolicy.Resolve, if the request
|
|
119
118
|
* was set when called, the request action is invoked after cancelling
|
|
120
119
|
* the request; otherwise, the pending action is cancelled.
|
|
121
120
|
* Defaults to `ClearPolicy.Cancel`.
|
|
122
121
|
*
|
|
123
122
|
* @memberof IAnimationFrame
|
|
124
123
|
*/
|
|
125
|
-
clear(policy?: ClearPolicy): void;
|
|
124
|
+
clear(policy?: Policies.ClearPolicy): void;
|
|
126
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Options for the scheduling APIs.
|
|
128
|
+
*/
|
|
127
129
|
export type Options = {
|
|
128
|
-
schedulePolicy?: SchedulePolicy;
|
|
129
|
-
clearPolicy?: ClearPolicy;
|
|
130
|
+
schedulePolicy?: Policies.SchedulePolicy;
|
|
131
|
+
clearPolicy?: Policies.ClearPolicy;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Options for the hook variants of our scheduling APIs.
|
|
135
|
+
*/
|
|
136
|
+
export type HookOptions = Options & {
|
|
137
|
+
actionPolicy?: Policies.ActionPolicy;
|
|
130
138
|
};
|
|
131
139
|
/**
|
|
132
140
|
* Provides means to request timeouts, intervals, and animation frames, with
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-timing",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.1",
|
|
5
5
|
"design": "v1",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"react": "16.14.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@khanacademy/wb-dev-build-settings": "^1.0.
|
|
20
|
+
"@khanacademy/wb-dev-build-settings": "^1.0.1"
|
|
21
21
|
},
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "MIT"
|