@khanacademy/wonder-blocks-timing 6.0.1 → 7.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 +53 -36
- package/LICENSE +21 -0
- package/dist/es/index.js +36 -41
- package/dist/hooks/use-interval.d.ts +3 -1
- package/dist/hooks/use-timeout.d.ts +3 -1
- package/dist/index.js +39 -47
- package/package.json +7 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,120 +1,137 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-timing
|
|
2
2
|
|
|
3
|
+
## 7.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- ae9b619: Fix bug with `useTimeout` and `useInterval` `clear` function where it didn't use the provided ClearPolicy
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- f03298f: Tooling:
|
|
12
|
+
|
|
13
|
+
- Switching to `pnpm`.
|
|
14
|
+
- Upgrading `rollup` to v4 and `@babel/runtime` to match the current webapp version.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- bb2a026: pnpm: Switch to workspace protocol to handle dependency versions with changesets on monorepo setup"
|
|
19
|
+
|
|
3
20
|
## 6.0.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
6
23
|
|
|
7
|
-
-
|
|
24
|
+
- 11a0f5c6: No functional changes. Adding prepublishOnly script.
|
|
8
25
|
|
|
9
26
|
## 6.0.0
|
|
10
27
|
|
|
11
28
|
### Major Changes
|
|
12
29
|
|
|
13
|
-
-
|
|
30
|
+
- e6abdd17: Upgrade to React 18
|
|
14
31
|
|
|
15
32
|
## 5.0.2
|
|
16
33
|
|
|
17
34
|
### Patch Changes
|
|
18
35
|
|
|
19
|
-
-
|
|
36
|
+
- 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
|
|
20
37
|
|
|
21
38
|
## 5.0.1
|
|
22
39
|
|
|
23
40
|
### Patch Changes
|
|
24
41
|
|
|
25
|
-
-
|
|
42
|
+
- 559e82d5: Update to build tooling, generating smaller output
|
|
26
43
|
|
|
27
44
|
## 5.0.0
|
|
28
45
|
|
|
29
46
|
### Major Changes
|
|
30
47
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
48
|
+
- f72f7dd4: - **[BREAKING CHANGE]** Policy types are now using enums across all APIs
|
|
49
|
+
- **[BREAKING CHANGE]** `useScheduledTimeout` has been renamed to `useTimeout` and the original `useTimeout` has been removed. To update existing uses of `useTimeout` to the new API: if `active` was `true` just delete that argument or replace it with `{schedulingPolicy: SchedulingPolicy.Immediately}`; if `active` was `false` replace it with `{schedulingPolicy: SchedulingPolicy.OnDemand}`.
|
|
50
|
+
- **[BREAKING CHANGE]** `useScheduledInterval` has been renamed to `useInterval` and the original `useInterval` has been removed. To update existing uses of `useInterval` to the new API: if `active` was `true` just delete that argument or replace it with `{schedulingPolicy: SchedulingPolicy.Immediately}`; if `active` was `false` replace it with `{schedulingPolicy: SchedulingPolicy.OnDemand}`.
|
|
51
|
+
- **[NEW]** `useTimeout` now supports an optional `ActionPolicy` in the options. The default is to not reset the timeout when the `action` callback changes. This can be changed to `ActionPolicy.Reset` to reset the timeout when the `action` callback changes (it is recommended that you use `useCallback` on your `action` callback to avoid resetting the timeout everytime a component renders when using the `Reset` policy).
|
|
52
|
+
- **[NEW]** `useInterval` now supports an optional `ActionPolicy` in the options. The default is to not reset the interval when the `action` callback changes. This can be changed to `ActionPolicy.Reset` to reset the interval when the `action` callback changes (it is recommended that you use `useCallback` on your `action` callback to avoid resetting the interval everytime a component renders when using the `Reset` policy).
|
|
53
|
+
- **[BUGFIX]** `useTimeout` will now correctly reset the timeout when the `set` method is called, as intended.
|
|
54
|
+
- **[BUGFIX]** `useInterval` will now correctly reset the interval when the `set` method is called, as intended.
|
|
38
55
|
|
|
39
56
|
## 4.0.2
|
|
40
57
|
|
|
41
58
|
### Patch Changes
|
|
42
59
|
|
|
43
|
-
-
|
|
60
|
+
- 695f2567: Provide a friendly name (for dev tools) for withActionScheduler
|
|
44
61
|
|
|
45
62
|
## 4.0.1
|
|
46
63
|
|
|
47
64
|
### Patch Changes
|
|
48
65
|
|
|
49
|
-
-
|
|
66
|
+
- df9a10aa: Update state and props to be readonly in components using getDerivedStateFromProps()
|
|
50
67
|
|
|
51
68
|
## 4.0.0
|
|
52
69
|
|
|
53
70
|
### Major Changes
|
|
54
71
|
|
|
55
|
-
-
|
|
72
|
+
- 0c2607e6: Remove ref-forwarding from withActionScheduler
|
|
56
73
|
|
|
57
74
|
## 3.0.3
|
|
58
75
|
|
|
59
76
|
### Patch Changes
|
|
60
77
|
|
|
61
|
-
-
|
|
78
|
+
- a6164ed0: Don't use React.FC<> for functional components
|
|
62
79
|
|
|
63
80
|
## 3.0.2
|
|
64
81
|
|
|
65
82
|
### Patch Changes
|
|
66
83
|
|
|
67
|
-
-
|
|
84
|
+
- c20f48f3: Don't transpile classes when building bundles
|
|
68
85
|
|
|
69
86
|
## 3.0.1
|
|
70
87
|
|
|
71
88
|
### Patch Changes
|
|
72
89
|
|
|
73
|
-
-
|
|
74
|
-
-
|
|
90
|
+
- ccb6fe00: Miscellaneous TS type fixes
|
|
91
|
+
- d4c2b18c: Fix a variety of issues with Flow types generated by flowgen
|
|
75
92
|
|
|
76
93
|
## 3.0.0
|
|
77
94
|
|
|
78
95
|
### Major Changes
|
|
79
96
|
|
|
80
|
-
-
|
|
97
|
+
- 1ca4d7e3: Fix minor issue with generate Flow types (this is a major bump b/c I forgot to do one after doing the TS conversion)
|
|
81
98
|
|
|
82
99
|
### Minor Changes
|
|
83
100
|
|
|
84
|
-
-
|
|
101
|
+
- ef661acf: Export ActionScheduler
|
|
85
102
|
|
|
86
103
|
## 2.1.3
|
|
87
104
|
|
|
88
105
|
### Patch Changes
|
|
89
106
|
|
|
90
|
-
-
|
|
107
|
+
- b5ba5568: Ensure that flow lib defs use React.ElementConfig<> isntead of JSX.LibraryManagedAttributes<>
|
|
91
108
|
|
|
92
109
|
## 2.1.2
|
|
93
110
|
|
|
94
111
|
### Patch Changes
|
|
95
112
|
|
|
96
|
-
-
|
|
97
|
-
-
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
113
|
+
- d816af08: Update build and test configs use TypeScript
|
|
114
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
115
|
+
- 0d28bb1c: Configured TypeScript
|
|
116
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
117
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
118
|
+
- 2983c05b: Include 'types' field in package.json
|
|
119
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
120
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
104
121
|
|
|
105
122
|
## 2.1.1
|
|
106
123
|
|
|
107
124
|
### Patch Changes
|
|
108
125
|
|
|
109
|
-
-
|
|
126
|
+
- 91cb727c: Remove file extensions from imports
|
|
110
127
|
|
|
111
128
|
## 2.1.0
|
|
112
129
|
|
|
113
130
|
### Minor Changes
|
|
114
131
|
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
-
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
|
|
132
|
+
- 029b4810: Adds `useInterval()` hook that mimics the behavior of `ActionScheduler`'s
|
|
133
|
+
`interval()` method.
|
|
134
|
+
- c57cd770: Rename `useInterval` and `useTimeout` to `useScheduledInterval`
|
|
135
|
+
and `useScheduledTimeout` respectively.
|
|
136
|
+
- 29766c8e: Add `useInterval` and `useTimeout` hooks to provide an API for
|
|
137
|
+
using intervals and timeouts.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Khan Academy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/es/index.js
CHANGED
|
@@ -19,9 +19,9 @@ let ActionPolicy = function (ActionPolicy) {
|
|
|
19
19
|
|
|
20
20
|
class Timeout {
|
|
21
21
|
constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
22
|
-
this._timeoutId =
|
|
23
|
-
this._action =
|
|
24
|
-
this._timeoutMs =
|
|
22
|
+
this._timeoutId = undefined;
|
|
23
|
+
this._action = undefined;
|
|
24
|
+
this._timeoutMs = undefined;
|
|
25
25
|
if (typeof action !== "function") {
|
|
26
26
|
throw new Error("Action must be a function");
|
|
27
27
|
}
|
|
@@ -58,9 +58,9 @@ class Timeout {
|
|
|
58
58
|
|
|
59
59
|
class Interval {
|
|
60
60
|
constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
61
|
-
this._intervalId =
|
|
62
|
-
this._action =
|
|
63
|
-
this._intervalMs =
|
|
61
|
+
this._intervalId = undefined;
|
|
62
|
+
this._action = undefined;
|
|
63
|
+
this._intervalMs = undefined;
|
|
64
64
|
if (typeof action !== "function") {
|
|
65
65
|
throw new Error("Action must be a function");
|
|
66
66
|
}
|
|
@@ -97,8 +97,8 @@ class Interval {
|
|
|
97
97
|
|
|
98
98
|
class AnimationFrame {
|
|
99
99
|
constructor(action, schedulePolicy = SchedulePolicy.Immediately) {
|
|
100
|
-
this._animationFrameId =
|
|
101
|
-
this._action =
|
|
100
|
+
this._animationFrameId = undefined;
|
|
101
|
+
this._action = undefined;
|
|
102
102
|
if (typeof action !== "function") {
|
|
103
103
|
throw new Error("Action must be a function");
|
|
104
104
|
}
|
|
@@ -138,24 +138,24 @@ class ActionScheduler {
|
|
|
138
138
|
if (this._disabled) {
|
|
139
139
|
return ActionScheduler.NoopAction;
|
|
140
140
|
}
|
|
141
|
-
const timeout = new Timeout(action, period, options == null ?
|
|
142
|
-
this._registeredActions.push(() => timeout.clear(options == null ?
|
|
141
|
+
const timeout = new Timeout(action, period, options == null ? undefined : options.schedulePolicy);
|
|
142
|
+
this._registeredActions.push(() => timeout.clear(options == null ? undefined : options.clearPolicy));
|
|
143
143
|
return timeout;
|
|
144
144
|
}
|
|
145
145
|
interval(action, period, options) {
|
|
146
146
|
if (this._disabled) {
|
|
147
147
|
return ActionScheduler.NoopAction;
|
|
148
148
|
}
|
|
149
|
-
const interval = new Interval(action, period, options == null ?
|
|
150
|
-
this._registeredActions.push(() => interval.clear(options == null ?
|
|
149
|
+
const interval = new Interval(action, period, options == null ? undefined : options.schedulePolicy);
|
|
150
|
+
this._registeredActions.push(() => interval.clear(options == null ? undefined : options.clearPolicy));
|
|
151
151
|
return interval;
|
|
152
152
|
}
|
|
153
153
|
animationFrame(action, options) {
|
|
154
154
|
if (this._disabled) {
|
|
155
155
|
return ActionScheduler.NoopAction;
|
|
156
156
|
}
|
|
157
|
-
const animationFrame = new AnimationFrame(action, options == null ?
|
|
158
|
-
this._registeredActions.push(() => animationFrame.clear(options == null ?
|
|
157
|
+
const animationFrame = new AnimationFrame(action, options == null ? undefined : options.schedulePolicy);
|
|
158
|
+
this._registeredActions.push(() => animationFrame.clear(options == null ? undefined : options.clearPolicy));
|
|
159
159
|
return animationFrame;
|
|
160
160
|
}
|
|
161
161
|
clearAll() {
|
|
@@ -193,18 +193,13 @@ class ActionSchedulerProvider extends React.Component {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
function _extends() {
|
|
196
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
|
197
|
-
for (var
|
|
198
|
-
var
|
|
199
|
-
for (var
|
|
200
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
201
|
-
target[key] = source[key];
|
|
202
|
-
}
|
|
203
|
-
}
|
|
196
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
197
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
198
|
+
var t = arguments[e];
|
|
199
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
204
200
|
}
|
|
205
|
-
return
|
|
206
|
-
};
|
|
207
|
-
return _extends.apply(this, arguments);
|
|
201
|
+
return n;
|
|
202
|
+
}, _extends.apply(null, arguments);
|
|
208
203
|
}
|
|
209
204
|
|
|
210
205
|
function withActionScheduler(WrappedComponent) {
|
|
@@ -231,33 +226,33 @@ function useInterval(action, intervalMs, options = {}) {
|
|
|
231
226
|
actionProxyRef.current = action;
|
|
232
227
|
if (actionPolicy === ActionPolicy.Reset) {
|
|
233
228
|
var _intervalRef$current;
|
|
234
|
-
(_intervalRef$current = intervalRef.current) == null
|
|
229
|
+
(_intervalRef$current = intervalRef.current) == null || _intervalRef$current.set();
|
|
235
230
|
}
|
|
236
231
|
}
|
|
237
232
|
useEffect(() => {
|
|
238
233
|
intervalRef.current = new Interval(() => {
|
|
239
|
-
actionProxyRef.current == null
|
|
234
|
+
actionProxyRef.current == null || actionProxyRef.current();
|
|
240
235
|
}, intervalMs, schedulePolicy);
|
|
241
236
|
return () => {
|
|
242
237
|
var _intervalRef$current2;
|
|
243
|
-
(_intervalRef$current2 = intervalRef.current) == null
|
|
238
|
+
(_intervalRef$current2 = intervalRef.current) == null || _intervalRef$current2.clear(clearPolicy);
|
|
244
239
|
intervalRef.current = null;
|
|
245
240
|
};
|
|
246
241
|
}, [intervalMs, clearPolicy, schedulePolicy]);
|
|
247
242
|
const externalApi = useMemo(() => ({
|
|
248
243
|
set: () => {
|
|
249
244
|
var _intervalRef$current3;
|
|
250
|
-
(_intervalRef$current3 = intervalRef.current) == null
|
|
245
|
+
(_intervalRef$current3 = intervalRef.current) == null || _intervalRef$current3.set();
|
|
251
246
|
},
|
|
252
|
-
clear: policy => {
|
|
247
|
+
clear: (policy = clearPolicy) => {
|
|
253
248
|
var _intervalRef$current4;
|
|
254
|
-
(_intervalRef$current4 = intervalRef.current) == null
|
|
249
|
+
(_intervalRef$current4 = intervalRef.current) == null || _intervalRef$current4.clear(policy);
|
|
255
250
|
},
|
|
256
251
|
get isSet() {
|
|
257
252
|
var _intervalRef$current$, _intervalRef$current5;
|
|
258
|
-
return (_intervalRef$current$ = (_intervalRef$current5 = intervalRef.current) == null ?
|
|
253
|
+
return (_intervalRef$current$ = (_intervalRef$current5 = intervalRef.current) == null ? undefined : _intervalRef$current5.isSet) != null ? _intervalRef$current$ : false;
|
|
259
254
|
}
|
|
260
|
-
}), []);
|
|
255
|
+
}), [clearPolicy]);
|
|
261
256
|
return externalApi;
|
|
262
257
|
}
|
|
263
258
|
|
|
@@ -276,33 +271,33 @@ function useTimeout(action, timeoutMs, options = {}) {
|
|
|
276
271
|
actionProxyRef.current = action;
|
|
277
272
|
if (actionPolicy === ActionPolicy.Reset) {
|
|
278
273
|
var _timeoutRef$current;
|
|
279
|
-
(_timeoutRef$current = timeoutRef.current) == null
|
|
274
|
+
(_timeoutRef$current = timeoutRef.current) == null || _timeoutRef$current.set();
|
|
280
275
|
}
|
|
281
276
|
}
|
|
282
277
|
useEffect(() => {
|
|
283
278
|
timeoutRef.current = new Timeout(() => {
|
|
284
|
-
actionProxyRef.current == null
|
|
279
|
+
actionProxyRef.current == null || actionProxyRef.current();
|
|
285
280
|
}, timeoutMs, schedulePolicy);
|
|
286
281
|
return () => {
|
|
287
282
|
var _timeoutRef$current2;
|
|
288
|
-
(_timeoutRef$current2 = timeoutRef.current) == null
|
|
283
|
+
(_timeoutRef$current2 = timeoutRef.current) == null || _timeoutRef$current2.clear(clearPolicy);
|
|
289
284
|
timeoutRef.current = null;
|
|
290
285
|
};
|
|
291
286
|
}, [timeoutMs, clearPolicy, schedulePolicy]);
|
|
292
287
|
const externalApi = useMemo(() => ({
|
|
293
288
|
set: () => {
|
|
294
289
|
var _timeoutRef$current3;
|
|
295
|
-
(_timeoutRef$current3 = timeoutRef.current) == null
|
|
290
|
+
(_timeoutRef$current3 = timeoutRef.current) == null || _timeoutRef$current3.set();
|
|
296
291
|
},
|
|
297
|
-
clear: policy => {
|
|
292
|
+
clear: (policy = clearPolicy) => {
|
|
298
293
|
var _timeoutRef$current4;
|
|
299
|
-
(_timeoutRef$current4 = timeoutRef.current) == null
|
|
294
|
+
(_timeoutRef$current4 = timeoutRef.current) == null || _timeoutRef$current4.clear(policy);
|
|
300
295
|
},
|
|
301
296
|
get isSet() {
|
|
302
297
|
var _timeoutRef$current$i, _timeoutRef$current5;
|
|
303
|
-
return (_timeoutRef$current$i = (_timeoutRef$current5 = timeoutRef.current) == null ?
|
|
298
|
+
return (_timeoutRef$current$i = (_timeoutRef$current5 = timeoutRef.current) == null ? undefined : _timeoutRef$current5.isSet) != null ? _timeoutRef$current$i : false;
|
|
304
299
|
}
|
|
305
|
-
}), []);
|
|
300
|
+
}), [clearPolicy]);
|
|
306
301
|
return externalApi;
|
|
307
302
|
}
|
|
308
303
|
|
|
@@ -25,6 +25,8 @@ import type { IInterval, HookOptions } from "../util/types";
|
|
|
25
25
|
* scheduling the interval, use `SchedulePolicy.OnDemand`.
|
|
26
26
|
* @returns An `IInterval` API for interacting with the given interval. This
|
|
27
27
|
* API is a no-op if called when not mounted. This means that any calls prior
|
|
28
|
-
* to mounting or after unmounting will not have any effect.
|
|
28
|
+
* to mounting or after unmounting will not have any effect. This API is
|
|
29
|
+
* not reactive, so do not deconstruct the return value, but instead
|
|
30
|
+
* dereference it at the time of use.
|
|
29
31
|
*/
|
|
30
32
|
export declare function useInterval(action: () => unknown, intervalMs: number, options?: HookOptions): IInterval;
|
|
@@ -25,6 +25,8 @@ import type { ITimeout, HookOptions } from "../util/types";
|
|
|
25
25
|
* scheduling the timeout, use `SchedulePolicy.OnDemand`.
|
|
26
26
|
* @returns An `ITimeout` API for interacting with the given timeout. This
|
|
27
27
|
* API is a no-op if called when not mounted. This means that any calls prior
|
|
28
|
-
* to mounting or after unmounting will not have any effect.
|
|
28
|
+
* to mounting or after unmounting will not have any effect. This API is
|
|
29
|
+
* not reactive, so do not deconstruct the return value, but instead
|
|
30
|
+
* dereference it at the time of use.
|
|
29
31
|
*/
|
|
30
32
|
export declare function useTimeout(action: () => unknown, timeoutMs: number, options?: HookOptions): ITimeout;
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var React = require('react');
|
|
6
4
|
|
|
7
|
-
function
|
|
8
|
-
if (e && e.__esModule) return e;
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
9
6
|
var n = Object.create(null);
|
|
10
7
|
if (e) {
|
|
11
8
|
Object.keys(e).forEach(function (k) {
|
|
@@ -18,11 +15,11 @@ function _interopNamespace(e) {
|
|
|
18
15
|
}
|
|
19
16
|
});
|
|
20
17
|
}
|
|
21
|
-
n
|
|
18
|
+
n.default = e;
|
|
22
19
|
return Object.freeze(n);
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
var React__namespace = /*#__PURE__*/
|
|
22
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
26
23
|
|
|
27
24
|
let SchedulePolicy = function (SchedulePolicy) {
|
|
28
25
|
SchedulePolicy["Immediately"] = "schedule-immediately";
|
|
@@ -42,9 +39,9 @@ let ActionPolicy = function (ActionPolicy) {
|
|
|
42
39
|
|
|
43
40
|
class Timeout {
|
|
44
41
|
constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
45
|
-
this._timeoutId =
|
|
46
|
-
this._action =
|
|
47
|
-
this._timeoutMs =
|
|
42
|
+
this._timeoutId = undefined;
|
|
43
|
+
this._action = undefined;
|
|
44
|
+
this._timeoutMs = undefined;
|
|
48
45
|
if (typeof action !== "function") {
|
|
49
46
|
throw new Error("Action must be a function");
|
|
50
47
|
}
|
|
@@ -81,9 +78,9 @@ class Timeout {
|
|
|
81
78
|
|
|
82
79
|
class Interval {
|
|
83
80
|
constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
84
|
-
this._intervalId =
|
|
85
|
-
this._action =
|
|
86
|
-
this._intervalMs =
|
|
81
|
+
this._intervalId = undefined;
|
|
82
|
+
this._action = undefined;
|
|
83
|
+
this._intervalMs = undefined;
|
|
87
84
|
if (typeof action !== "function") {
|
|
88
85
|
throw new Error("Action must be a function");
|
|
89
86
|
}
|
|
@@ -120,8 +117,8 @@ class Interval {
|
|
|
120
117
|
|
|
121
118
|
class AnimationFrame {
|
|
122
119
|
constructor(action, schedulePolicy = SchedulePolicy.Immediately) {
|
|
123
|
-
this._animationFrameId =
|
|
124
|
-
this._action =
|
|
120
|
+
this._animationFrameId = undefined;
|
|
121
|
+
this._action = undefined;
|
|
125
122
|
if (typeof action !== "function") {
|
|
126
123
|
throw new Error("Action must be a function");
|
|
127
124
|
}
|
|
@@ -161,24 +158,24 @@ class ActionScheduler {
|
|
|
161
158
|
if (this._disabled) {
|
|
162
159
|
return ActionScheduler.NoopAction;
|
|
163
160
|
}
|
|
164
|
-
const timeout = new Timeout(action, period, options == null ?
|
|
165
|
-
this._registeredActions.push(() => timeout.clear(options == null ?
|
|
161
|
+
const timeout = new Timeout(action, period, options == null ? undefined : options.schedulePolicy);
|
|
162
|
+
this._registeredActions.push(() => timeout.clear(options == null ? undefined : options.clearPolicy));
|
|
166
163
|
return timeout;
|
|
167
164
|
}
|
|
168
165
|
interval(action, period, options) {
|
|
169
166
|
if (this._disabled) {
|
|
170
167
|
return ActionScheduler.NoopAction;
|
|
171
168
|
}
|
|
172
|
-
const interval = new Interval(action, period, options == null ?
|
|
173
|
-
this._registeredActions.push(() => interval.clear(options == null ?
|
|
169
|
+
const interval = new Interval(action, period, options == null ? undefined : options.schedulePolicy);
|
|
170
|
+
this._registeredActions.push(() => interval.clear(options == null ? undefined : options.clearPolicy));
|
|
174
171
|
return interval;
|
|
175
172
|
}
|
|
176
173
|
animationFrame(action, options) {
|
|
177
174
|
if (this._disabled) {
|
|
178
175
|
return ActionScheduler.NoopAction;
|
|
179
176
|
}
|
|
180
|
-
const animationFrame = new AnimationFrame(action, options == null ?
|
|
181
|
-
this._registeredActions.push(() => animationFrame.clear(options == null ?
|
|
177
|
+
const animationFrame = new AnimationFrame(action, options == null ? undefined : options.schedulePolicy);
|
|
178
|
+
this._registeredActions.push(() => animationFrame.clear(options == null ? undefined : options.clearPolicy));
|
|
182
179
|
return animationFrame;
|
|
183
180
|
}
|
|
184
181
|
clearAll() {
|
|
@@ -216,18 +213,13 @@ class ActionSchedulerProvider extends React__namespace.Component {
|
|
|
216
213
|
}
|
|
217
214
|
|
|
218
215
|
function _extends() {
|
|
219
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
|
220
|
-
for (var
|
|
221
|
-
var
|
|
222
|
-
for (var
|
|
223
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
224
|
-
target[key] = source[key];
|
|
225
|
-
}
|
|
226
|
-
}
|
|
216
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
217
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
218
|
+
var t = arguments[e];
|
|
219
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
227
220
|
}
|
|
228
|
-
return
|
|
229
|
-
};
|
|
230
|
-
return _extends.apply(this, arguments);
|
|
221
|
+
return n;
|
|
222
|
+
}, _extends.apply(null, arguments);
|
|
231
223
|
}
|
|
232
224
|
|
|
233
225
|
function withActionScheduler(WrappedComponent) {
|
|
@@ -254,33 +246,33 @@ function useInterval(action, intervalMs, options = {}) {
|
|
|
254
246
|
actionProxyRef.current = action;
|
|
255
247
|
if (actionPolicy === ActionPolicy.Reset) {
|
|
256
248
|
var _intervalRef$current;
|
|
257
|
-
(_intervalRef$current = intervalRef.current) == null
|
|
249
|
+
(_intervalRef$current = intervalRef.current) == null || _intervalRef$current.set();
|
|
258
250
|
}
|
|
259
251
|
}
|
|
260
252
|
React.useEffect(() => {
|
|
261
253
|
intervalRef.current = new Interval(() => {
|
|
262
|
-
actionProxyRef.current == null
|
|
254
|
+
actionProxyRef.current == null || actionProxyRef.current();
|
|
263
255
|
}, intervalMs, schedulePolicy);
|
|
264
256
|
return () => {
|
|
265
257
|
var _intervalRef$current2;
|
|
266
|
-
(_intervalRef$current2 = intervalRef.current) == null
|
|
258
|
+
(_intervalRef$current2 = intervalRef.current) == null || _intervalRef$current2.clear(clearPolicy);
|
|
267
259
|
intervalRef.current = null;
|
|
268
260
|
};
|
|
269
261
|
}, [intervalMs, clearPolicy, schedulePolicy]);
|
|
270
262
|
const externalApi = React.useMemo(() => ({
|
|
271
263
|
set: () => {
|
|
272
264
|
var _intervalRef$current3;
|
|
273
|
-
(_intervalRef$current3 = intervalRef.current) == null
|
|
265
|
+
(_intervalRef$current3 = intervalRef.current) == null || _intervalRef$current3.set();
|
|
274
266
|
},
|
|
275
|
-
clear: policy => {
|
|
267
|
+
clear: (policy = clearPolicy) => {
|
|
276
268
|
var _intervalRef$current4;
|
|
277
|
-
(_intervalRef$current4 = intervalRef.current) == null
|
|
269
|
+
(_intervalRef$current4 = intervalRef.current) == null || _intervalRef$current4.clear(policy);
|
|
278
270
|
},
|
|
279
271
|
get isSet() {
|
|
280
272
|
var _intervalRef$current$, _intervalRef$current5;
|
|
281
|
-
return (_intervalRef$current$ = (_intervalRef$current5 = intervalRef.current) == null ?
|
|
273
|
+
return (_intervalRef$current$ = (_intervalRef$current5 = intervalRef.current) == null ? undefined : _intervalRef$current5.isSet) != null ? _intervalRef$current$ : false;
|
|
282
274
|
}
|
|
283
|
-
}), []);
|
|
275
|
+
}), [clearPolicy]);
|
|
284
276
|
return externalApi;
|
|
285
277
|
}
|
|
286
278
|
|
|
@@ -299,33 +291,33 @@ function useTimeout(action, timeoutMs, options = {}) {
|
|
|
299
291
|
actionProxyRef.current = action;
|
|
300
292
|
if (actionPolicy === ActionPolicy.Reset) {
|
|
301
293
|
var _timeoutRef$current;
|
|
302
|
-
(_timeoutRef$current = timeoutRef.current) == null
|
|
294
|
+
(_timeoutRef$current = timeoutRef.current) == null || _timeoutRef$current.set();
|
|
303
295
|
}
|
|
304
296
|
}
|
|
305
297
|
React.useEffect(() => {
|
|
306
298
|
timeoutRef.current = new Timeout(() => {
|
|
307
|
-
actionProxyRef.current == null
|
|
299
|
+
actionProxyRef.current == null || actionProxyRef.current();
|
|
308
300
|
}, timeoutMs, schedulePolicy);
|
|
309
301
|
return () => {
|
|
310
302
|
var _timeoutRef$current2;
|
|
311
|
-
(_timeoutRef$current2 = timeoutRef.current) == null
|
|
303
|
+
(_timeoutRef$current2 = timeoutRef.current) == null || _timeoutRef$current2.clear(clearPolicy);
|
|
312
304
|
timeoutRef.current = null;
|
|
313
305
|
};
|
|
314
306
|
}, [timeoutMs, clearPolicy, schedulePolicy]);
|
|
315
307
|
const externalApi = React.useMemo(() => ({
|
|
316
308
|
set: () => {
|
|
317
309
|
var _timeoutRef$current3;
|
|
318
|
-
(_timeoutRef$current3 = timeoutRef.current) == null
|
|
310
|
+
(_timeoutRef$current3 = timeoutRef.current) == null || _timeoutRef$current3.set();
|
|
319
311
|
},
|
|
320
|
-
clear: policy => {
|
|
312
|
+
clear: (policy = clearPolicy) => {
|
|
321
313
|
var _timeoutRef$current4;
|
|
322
|
-
(_timeoutRef$current4 = timeoutRef.current) == null
|
|
314
|
+
(_timeoutRef$current4 = timeoutRef.current) == null || _timeoutRef$current4.clear(policy);
|
|
323
315
|
},
|
|
324
316
|
get isSet() {
|
|
325
317
|
var _timeoutRef$current$i, _timeoutRef$current5;
|
|
326
|
-
return (_timeoutRef$current$i = (_timeoutRef$current5 = timeoutRef.current) == null ?
|
|
318
|
+
return (_timeoutRef$current$i = (_timeoutRef$current5 = timeoutRef.current) == null ? undefined : _timeoutRef$current5.isSet) != null ? _timeoutRef$current$i : false;
|
|
327
319
|
}
|
|
328
|
-
}), []);
|
|
320
|
+
}), [clearPolicy]);
|
|
329
321
|
return externalApi;
|
|
330
322
|
}
|
|
331
323
|
|
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": "7.0.0",
|
|
5
5
|
"design": "v1",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,17 +10,16 @@
|
|
|
10
10
|
"main": "dist/index.js",
|
|
11
11
|
"module": "dist/es/index.js",
|
|
12
12
|
"types": "dist/index.d.ts",
|
|
13
|
-
"scripts": {
|
|
14
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
|
-
"prepublishOnly": "../../utils/publish/package-pre-publish-check.sh"
|
|
16
|
-
},
|
|
17
13
|
"peerDependencies": {
|
|
18
14
|
"react": "18.2.0"
|
|
19
15
|
},
|
|
20
16
|
"devDependencies": {
|
|
21
|
-
"@khanacademy/wb-dev-build-settings": "
|
|
22
|
-
"@khanacademy/wonder-blocks-testing-core": "
|
|
17
|
+
"@khanacademy/wb-dev-build-settings": "2.1.0",
|
|
18
|
+
"@khanacademy/wonder-blocks-testing-core": "2.1.0"
|
|
23
19
|
},
|
|
24
20
|
"author": "",
|
|
25
|
-
"license": "MIT"
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
|
+
}
|
|
26
25
|
}
|