@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.
@@ -1,8 +1,12 @@
1
- export declare const SchedulePolicy: {
2
- readonly Immediately: "schedule-immediately";
3
- readonly OnDemand: "schedule-on-demand";
4
- };
5
- export declare const ClearPolicy: {
6
- readonly Resolve: "resolve-on-clear";
7
- readonly Cancel: "cancel-on-clear";
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
+ }
@@ -1,4 +1,5 @@
1
- import type { ITimeout, SchedulePolicy, ClearPolicy } from "./types";
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 {() => mixed} action The action to be invoked when the timeout
20
+ * @param action The action to be invoked when the timeout
20
21
  * period has passed.
21
- * @param {number} timeoutMs The timeout period.
22
- * @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately,
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 {boolean} true if the timeout is set (aka pending), otherwise
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 {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
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`.
@@ -1,5 +1,4 @@
1
- export type SchedulePolicy = "schedule-immediately" | "schedule-on-demand";
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 {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
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 {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
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 {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
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.0.2",
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.0"
20
+ "@khanacademy/wb-dev-build-settings": "^1.0.1"
21
21
  },
22
22
  "author": "",
23
23
  "license": "MIT"