@khanacademy/wonder-blocks-timing 4.0.1 → 5.0.0
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/components/with-action-scheduler.d.ts +4 -1
- package/dist/es/index.js +93 -105
- 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 +92 -105
- package/dist/util/animation-frame.d.ts +6 -6
- package/dist/util/interval.d.ts +8 -8
- package/dist/util/policies.d.ts +12 -8
- package/dist/util/timeout.d.ts +8 -7
- package/dist/util/types.d.ts +18 -10
- package/package.json +3 -3
- package/src/components/with-action-scheduler.tsx +9 -1
- 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/__tests__/animation-frame.test.ts +9 -10
- package/src/util/animation-frame.ts +12 -16
- package/src/util/interval.ts +13 -18
- package/src/util/policies.ts +13 -8
- package/src/util/timeout.ts +14 -18
- package/src/util/types.ts +19 -11
- package/tsconfig-build.json +2 -4
- package/tsconfig-build.tsbuildinfo +1 -1
- package/dist/components/action-scheduler-provider.js.flow +0 -33
- package/dist/components/with-action-scheduler.js.flow +0 -22
- package/dist/hooks/internal/use-updating-ref.d.ts +0 -13
- package/dist/hooks/internal/use-updating-ref.js.flow +0 -20
- package/dist/hooks/use-interval.js.flow +0 -17
- package/dist/hooks/use-scheduled-interval.d.ts +0 -2
- package/dist/hooks/use-scheduled-interval.js.flow +0 -12
- package/dist/hooks/use-scheduled-timeout.d.ts +0 -2
- package/dist/hooks/use-scheduled-timeout.js.flow +0 -12
- package/dist/hooks/use-timeout.js.flow +0 -17
- package/dist/index.js.flow +0 -31
- package/dist/util/action-scheduler.js.flow +0 -38
- package/dist/util/animation-frame.js.flow +0 -70
- package/dist/util/interval.js.flow +0 -69
- package/dist/util/policies.js.flow +0 -14
- package/dist/util/timeout.js.flow +0 -71
- package/dist/util/types.js.flow +0 -232
- package/dist/util/types.typestest.js.flow +0 -6
- 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
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { IInterval, SchedulePolicy, ClearPolicy } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Encapsulates everything associated with calling setInterval/clearInterval,
|
|
11
|
-
* and managing the lifecycle of that interval. This includes the ability to
|
|
12
|
-
* cancel the interval, and knowing if the interval is active.
|
|
13
|
-
* @export
|
|
14
|
-
* @class Interval
|
|
15
|
-
* @implements
|
|
16
|
-
*/
|
|
17
|
-
declare export default class Interval implements IInterval {
|
|
18
|
-
_intervalId: number | null | void;
|
|
19
|
-
_action: () => mixed;
|
|
20
|
-
_intervalMs: number;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates an interval that will invoke the given action after
|
|
24
|
-
* the given period. The interval does not start until set is called.
|
|
25
|
-
* @param {() => mixed} action The action to be invoked each time the
|
|
26
|
-
* interval period has passed.
|
|
27
|
-
* @param {number} intervalMs The interval period.
|
|
28
|
-
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately,
|
|
29
|
-
* the interval is set immediately on instantiation; otherwise, `set` must be
|
|
30
|
-
* called to set the interval.
|
|
31
|
-
* Defaults to `SchedulePolicy.Immediately`.
|
|
32
|
-
* @memberof Interval
|
|
33
|
-
*/
|
|
34
|
-
constructor(
|
|
35
|
-
action: () => mixed,
|
|
36
|
-
intervalMs: number,
|
|
37
|
-
schedulePolicy?: SchedulePolicy
|
|
38
|
-
): this;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Determine if the interval is active or not.
|
|
42
|
-
* @returns {boolean} true if the interval is active, otherwise false.
|
|
43
|
-
* @memberof Interval
|
|
44
|
-
*/
|
|
45
|
-
isSet: boolean;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Activate the interval.
|
|
49
|
-
*
|
|
50
|
-
* If the interval is active, this cancels that interval and starts the
|
|
51
|
-
* interval afresh. If the interval is not active, this starts it.
|
|
52
|
-
* @memberof Interval
|
|
53
|
-
*/
|
|
54
|
-
set(): void;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Clear the active interval.
|
|
58
|
-
*
|
|
59
|
-
* If the interval is active, this cancels that interval. If no interval is
|
|
60
|
-
* pending, this does nothing.
|
|
61
|
-
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
|
|
62
|
-
* was set when called, the request action is invoked after cancelling
|
|
63
|
-
* the request; otherwise, the pending action is cancelled.
|
|
64
|
-
* Defaults to `ClearPolicy.Cancel`.
|
|
65
|
-
* @returns {void}
|
|
66
|
-
* @memberof Interval
|
|
67
|
-
*/
|
|
68
|
-
clear(policy?: ClearPolicy): void;
|
|
69
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
declare export var SchedulePolicy: {|
|
|
8
|
-
+Immediately: "schedule-immediately",
|
|
9
|
-
+OnDemand: "schedule-on-demand",
|
|
10
|
-
|};
|
|
11
|
-
declare export var ClearPolicy: {|
|
|
12
|
-
+Resolve: "resolve-on-clear",
|
|
13
|
-
+Cancel: "cancel-on-clear",
|
|
14
|
-
|};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { ITimeout, SchedulePolicy, ClearPolicy } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Encapsulates everything associated with calling setTimeout/clearTimeout, and
|
|
11
|
-
* managing the lifecycle of that timer, including the ability to resolve or
|
|
12
|
-
* cancel a pending timeout action.
|
|
13
|
-
* @export
|
|
14
|
-
* @class Timeout
|
|
15
|
-
* @implements
|
|
16
|
-
*/
|
|
17
|
-
declare export default class Timeout implements ITimeout {
|
|
18
|
-
_timeoutId: number | null | void;
|
|
19
|
-
_action: () => mixed;
|
|
20
|
-
_timeoutMs: number;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a timeout that will invoke the given action after
|
|
24
|
-
* the given period. The timeout does not start until set is called.
|
|
25
|
-
* @param {() => mixed} action The action to be invoked when the timeout
|
|
26
|
-
* period has passed.
|
|
27
|
-
* @param {number} timeoutMs The timeout period.
|
|
28
|
-
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately,
|
|
29
|
-
* the timer is set immediately on instantiation; otherwise, `set` must be
|
|
30
|
-
* called to set the timeout.
|
|
31
|
-
* Defaults to `SchedulePolicy.Immediately`.
|
|
32
|
-
* @memberof Timeout
|
|
33
|
-
*/
|
|
34
|
-
constructor(
|
|
35
|
-
action: () => mixed,
|
|
36
|
-
timeoutMs: number,
|
|
37
|
-
schedulePolicy?: SchedulePolicy
|
|
38
|
-
): this;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Determine if the timeout is set or not.
|
|
42
|
-
* @returns {boolean} true if the timeout is set (aka pending), otherwise
|
|
43
|
-
* false.
|
|
44
|
-
* @memberof Timeout
|
|
45
|
-
*/
|
|
46
|
-
isSet: boolean;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Set the timeout.
|
|
50
|
-
*
|
|
51
|
-
* If the timeout is pending, this cancels that pending timeout and
|
|
52
|
-
* sets the timeout afresh. If the timeout is not pending, this
|
|
53
|
-
* sets a new timeout.
|
|
54
|
-
* @memberof Timeout
|
|
55
|
-
*/
|
|
56
|
-
set(): void;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Clear the set timeout.
|
|
60
|
-
*
|
|
61
|
-
* If the timeout is pending, this cancels that pending timeout without
|
|
62
|
-
* invoking the action. If no timeout is pending, this does nothing.
|
|
63
|
-
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
|
|
64
|
-
* was set when called, the request action is invoked after cancelling
|
|
65
|
-
* the request; otherwise, the pending action is cancelled.
|
|
66
|
-
* Defaults to `ClearPolicy.Cancel`.
|
|
67
|
-
* @returns {void}
|
|
68
|
-
* @memberof Timeout
|
|
69
|
-
*/
|
|
70
|
-
clear(policy?: ClearPolicy): void;
|
|
71
|
-
}
|
package/dist/util/types.js.flow
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
export type SchedulePolicy = "schedule-immediately" | "schedule-on-demand";
|
|
8
|
-
export type ClearPolicy = "resolve-on-clear" | "cancel-on-clear";
|
|
9
|
-
/**
|
|
10
|
-
* Encapsulates everything associated with calling setTimeout/clearTimeout, and
|
|
11
|
-
* managing the lifecycle of that timer, including the ability to resolve or
|
|
12
|
-
* cancel a pending timeout action.
|
|
13
|
-
* @export
|
|
14
|
-
* @interface ITimeout
|
|
15
|
-
*/
|
|
16
|
-
export interface ITimeout {
|
|
17
|
-
/**
|
|
18
|
-
* Determine if the timeout is set or not.
|
|
19
|
-
* @returns {boolean} true if the timeout is set (aka pending), otherwise
|
|
20
|
-
* false.
|
|
21
|
-
* @memberof ITimeout
|
|
22
|
-
*/
|
|
23
|
-
isSet: boolean;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Set the timeout.
|
|
27
|
-
*
|
|
28
|
-
* If the timeout is pending, this cancels that pending timeout and
|
|
29
|
-
* starts the timeout afresh. If the timeout is not pending, this
|
|
30
|
-
* starts the timeout.
|
|
31
|
-
* @memberof ITimeout
|
|
32
|
-
*/
|
|
33
|
-
set(): void;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Clear the set timeout.
|
|
37
|
-
*
|
|
38
|
-
* If the timeout is pending, this cancels that pending timeout. If no
|
|
39
|
-
* timeout is pending, this does nothing.
|
|
40
|
-
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
|
|
41
|
-
* was set when called, the request action is invoked after cancelling
|
|
42
|
-
* the request; otherwise, the pending action is cancelled.
|
|
43
|
-
* Defaults to `ClearPolicy.Cancel`.
|
|
44
|
-
* @memberof ITimeout
|
|
45
|
-
*/
|
|
46
|
-
clear(policy?: ClearPolicy): void;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Encapsulates everything associated with calling setInterval/clearInterval,
|
|
50
|
-
* and managing the lifecycle of that interval, including the ability to resolve
|
|
51
|
-
* or cancel an active interval.
|
|
52
|
-
* @export
|
|
53
|
-
* @interface IInterval
|
|
54
|
-
*/
|
|
55
|
-
export interface IInterval {
|
|
56
|
-
/**
|
|
57
|
-
* Determine if the interval is active or not.
|
|
58
|
-
* @returns {boolean} true if the interval is active, otherwise false.
|
|
59
|
-
* @memberof IInterval
|
|
60
|
-
*/
|
|
61
|
-
isSet: boolean;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Set the interval.
|
|
65
|
-
*
|
|
66
|
-
* If the interval is active, this cancels that interval and restarts it
|
|
67
|
-
* afresh. If the interval is not active, this starts the interval.
|
|
68
|
-
* @memberof IInterval
|
|
69
|
-
*/
|
|
70
|
-
set(): void;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Clear the active interval.
|
|
74
|
-
*
|
|
75
|
-
* If the interval is active, this cancels that interval. If the interval
|
|
76
|
-
* is not active, this does nothing.
|
|
77
|
-
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
|
|
78
|
-
* was set when called, the request action is invoked after cancelling
|
|
79
|
-
* the request; otherwise, the pending action is cancelled.
|
|
80
|
-
* Defaults to `ClearPolicy.Cancel`.
|
|
81
|
-
* @memberof IInterval
|
|
82
|
-
*/
|
|
83
|
-
clear(policy?: ClearPolicy): void;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Encapsulates everything associated with calling requestAnimationFrame/
|
|
87
|
-
* cancelAnimationFrame, and managing the lifecycle of that request, including
|
|
88
|
-
* the ability to resolve or cancel a pending request.
|
|
89
|
-
* @export
|
|
90
|
-
* @interface IAnimationFrame
|
|
91
|
-
*/
|
|
92
|
-
export interface IAnimationFrame {
|
|
93
|
-
/**
|
|
94
|
-
* Determine if the request is set or not.
|
|
95
|
-
* @returns {boolean} true if the request is set (aka pending), otherwise
|
|
96
|
-
* false.
|
|
97
|
-
* @memberof IAnimationFrame
|
|
98
|
-
*/
|
|
99
|
-
isSet: boolean;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Set the request.
|
|
103
|
-
*
|
|
104
|
-
* If the request is pending, this cancels that pending request and
|
|
105
|
-
* starts a request afresh. If the request is not pending, this
|
|
106
|
-
* starts the request.
|
|
107
|
-
* @memberof IAnimationFrame
|
|
108
|
-
*/
|
|
109
|
-
set(): void;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Clear the set request.
|
|
113
|
-
*
|
|
114
|
-
* If the request is pending, this cancels that pending request. If no
|
|
115
|
-
* request is pending, this does nothing.
|
|
116
|
-
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
|
|
117
|
-
* was set when called, the request action is invoked after cancelling
|
|
118
|
-
* the request; otherwise, the pending action is cancelled.
|
|
119
|
-
* Defaults to `ClearPolicy.Cancel`.
|
|
120
|
-
* @memberof IAnimationFrame
|
|
121
|
-
*/
|
|
122
|
-
clear(policy?: ClearPolicy): void;
|
|
123
|
-
}
|
|
124
|
-
export type Options = {|
|
|
125
|
-
schedulePolicy?: SchedulePolicy,
|
|
126
|
-
clearPolicy?: ClearPolicy,
|
|
127
|
-
|};
|
|
128
|
-
/**
|
|
129
|
-
* Provides means to request timeouts, intervals, and animation frames, with
|
|
130
|
-
* additional support for clearing all requested actions.
|
|
131
|
-
*
|
|
132
|
-
* This interface describes a replacement for the `setTimeout`/`clearTimeout`,
|
|
133
|
-
* `setInterval`/`clearInterval` and `requestAnimationFrame`/`cancelAnimationFrame`
|
|
134
|
-
* APIs that supports the ability to easily clear all pending actions.
|
|
135
|
-
* @export
|
|
136
|
-
* @interface IScheduleActions
|
|
137
|
-
*/
|
|
138
|
-
export interface IScheduleActions {
|
|
139
|
-
/**
|
|
140
|
-
* Request a timeout.
|
|
141
|
-
*
|
|
142
|
-
* A timeout will wait for a given period and then invoke a given action.
|
|
143
|
-
* @param {() => void} action The action to be invoked when the timeout
|
|
144
|
-
* period is reached.
|
|
145
|
-
* @param {number} period The timeout period in milliseconds. The action
|
|
146
|
-
* will be invoked after this period has passed since the timeout was set.
|
|
147
|
-
* This value must be greater than or equal to zero.
|
|
148
|
-
* @param {boolean} [autoSchedule] Whether or not to set the timeout as soon
|
|
149
|
-
* as this call is made, or wait until `set` is explicitly called. Defaults
|
|
150
|
-
* to `true`.
|
|
151
|
-
* @param {boolean} [resolveOnClear] Whether or not the associated action
|
|
152
|
-
* will be invoked if it is still pending at the point the timeout is
|
|
153
|
-
* cleared. Defaults to `false`.
|
|
154
|
-
* @returns {ITimeout} A interface for manipulating the created timeout.
|
|
155
|
-
* @memberof IScheduleActions
|
|
156
|
-
*/
|
|
157
|
-
timeout(action: () => mixed, period: number, options?: Options): ITimeout;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Request an interval.
|
|
161
|
-
*
|
|
162
|
-
* An interval will invoke a given action each time the given period has
|
|
163
|
-
* passed until the interval is cleared.
|
|
164
|
-
* @param {() => void} action The action to be invoked when the interval
|
|
165
|
-
* period occurs.
|
|
166
|
-
* @param {number} period The interval period in milliseconds. The action
|
|
167
|
-
* will be invoked each time this period has passed since the interval was
|
|
168
|
-
* set or last occurred.
|
|
169
|
-
* This value must be greater than zero.
|
|
170
|
-
* @param {boolean} [autoSchedule] Whether or not to set the interval as soon
|
|
171
|
-
* as this call is made, or wait until `set` is explicitly called. Defaults
|
|
172
|
-
* to `true`.
|
|
173
|
-
* @param {boolean} [resolveOnClear] Whether or not the associated action
|
|
174
|
-
* will be invoked at the point the interval is cleared if the interval
|
|
175
|
-
* is running at that time. Defaults to `false`.
|
|
176
|
-
* @returns {IInterval} An interface for manipulating the created interval.
|
|
177
|
-
* @memberof IScheduleActions
|
|
178
|
-
*/
|
|
179
|
-
interval(action: () => mixed, period: number, options?: Options): IInterval;
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Request an animation frame.
|
|
183
|
-
*
|
|
184
|
-
* An animation frame request tells the browser that you wish to perform an
|
|
185
|
-
* animation and requests that the browser call a specified function to
|
|
186
|
-
* update an animation before the next repaint.
|
|
187
|
-
* @param {(time: DOMHighResTimeStamp) => void} action The action to be invoked before the repaint.
|
|
188
|
-
* @param {boolean} [autoSchedule] Whether or not to make the request as soon
|
|
189
|
-
* as this call is made, or wait until `set` is explicitly called. Defaults
|
|
190
|
-
* to `true`.
|
|
191
|
-
* @param {boolean} [resolveOnClear] Whether or not the associated action
|
|
192
|
-
* will be invoked at the point the request is cleared if it has not yet
|
|
193
|
-
* executed. Defaults to `false`.
|
|
194
|
-
* @returns {IAnimationFrame} An interface for manipulating the created
|
|
195
|
-
* request.
|
|
196
|
-
* @memberof IScheduleActions
|
|
197
|
-
*/
|
|
198
|
-
animationFrame(
|
|
199
|
-
action: (time: DOMHighResTimeStamp) => void,
|
|
200
|
-
options?: Options
|
|
201
|
-
): IAnimationFrame;
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Clears all timeouts, intervals, and animation frame requests that were
|
|
205
|
-
* made with this scheduler.
|
|
206
|
-
* @memberof IScheduleActions
|
|
207
|
-
*/
|
|
208
|
-
clearAll(): void;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* A props object type that can be spread into the a componenet wrapped with
|
|
212
|
-
* the `withActionScheduler` higher order component.
|
|
213
|
-
*/
|
|
214
|
-
export type WithActionSchedulerProps = $ReadOnly<{|
|
|
215
|
-
/**
|
|
216
|
-
* An instance of the `IScheduleActions` API to use for scheduling
|
|
217
|
-
* intervals, timeouts, and animation frame requests.
|
|
218
|
-
*/
|
|
219
|
-
schedule: IScheduleActions,
|
|
220
|
-
|}>;
|
|
221
|
-
export type WithoutActionScheduler<TProps: { ... }> = $Diff<
|
|
222
|
-
TProps,
|
|
223
|
-
{ schedule: any }
|
|
224
|
-
>;
|
|
225
|
-
/**
|
|
226
|
-
* Extends the given props with props that the `withActionScheduler` higher
|
|
227
|
-
* order component will inject.
|
|
228
|
-
*/
|
|
229
|
-
export type WithActionScheduler<TOwnProps: { ... }> = {|
|
|
230
|
-
...TOwnProps,
|
|
231
|
-
...WithActionSchedulerProps,
|
|
232
|
-
|};
|