@khanacademy/wonder-blocks-timing 6.0.0 → 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 CHANGED
@@ -1,114 +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
+
20
+ ## 6.0.1
21
+
22
+ ### Patch Changes
23
+
24
+ - 11a0f5c6: No functional changes. Adding prepublishOnly script.
25
+
3
26
  ## 6.0.0
4
27
 
5
28
  ### Major Changes
6
29
 
7
- - e6abdd17: Upgrade to React 18
30
+ - e6abdd17: Upgrade to React 18
8
31
 
9
32
  ## 5.0.2
10
33
 
11
34
  ### Patch Changes
12
35
 
13
- - 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
36
+ - 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
14
37
 
15
38
  ## 5.0.1
16
39
 
17
40
  ### Patch Changes
18
41
 
19
- - 559e82d5: Update to build tooling, generating smaller output
42
+ - 559e82d5: Update to build tooling, generating smaller output
20
43
 
21
44
  ## 5.0.0
22
45
 
23
46
  ### Major Changes
24
47
 
25
- - f72f7dd4: - **[BREAKING CHANGE]** Policy types are now using enums across all APIs
26
- - **[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}`.
27
- - **[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}`.
28
- - **[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).
29
- - **[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).
30
- - **[BUGFIX]** `useTimeout` will now correctly reset the timeout when the `set` method is called, as intended.
31
- - **[BUGFIX]** `useInterval` will now correctly reset the interval when the `set` method is called, as intended.
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.
32
55
 
33
56
  ## 4.0.2
34
57
 
35
58
  ### Patch Changes
36
59
 
37
- - 695f2567: Provide a friendly name (for dev tools) for withActionScheduler
60
+ - 695f2567: Provide a friendly name (for dev tools) for withActionScheduler
38
61
 
39
62
  ## 4.0.1
40
63
 
41
64
  ### Patch Changes
42
65
 
43
- - df9a10aa: Update state and props to be readonly in components using getDerivedStateFromProps()
66
+ - df9a10aa: Update state and props to be readonly in components using getDerivedStateFromProps()
44
67
 
45
68
  ## 4.0.0
46
69
 
47
70
  ### Major Changes
48
71
 
49
- - 0c2607e6: Remove ref-forwarding from withActionScheduler
72
+ - 0c2607e6: Remove ref-forwarding from withActionScheduler
50
73
 
51
74
  ## 3.0.3
52
75
 
53
76
  ### Patch Changes
54
77
 
55
- - a6164ed0: Don't use React.FC<> for functional components
78
+ - a6164ed0: Don't use React.FC<> for functional components
56
79
 
57
80
  ## 3.0.2
58
81
 
59
82
  ### Patch Changes
60
83
 
61
- - c20f48f3: Don't transpile classes when building bundles
84
+ - c20f48f3: Don't transpile classes when building bundles
62
85
 
63
86
  ## 3.0.1
64
87
 
65
88
  ### Patch Changes
66
89
 
67
- - ccb6fe00: Miscellaneous TS type fixes
68
- - d4c2b18c: Fix a variety of issues with Flow types generated by flowgen
90
+ - ccb6fe00: Miscellaneous TS type fixes
91
+ - d4c2b18c: Fix a variety of issues with Flow types generated by flowgen
69
92
 
70
93
  ## 3.0.0
71
94
 
72
95
  ### Major Changes
73
96
 
74
- - 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)
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)
75
98
 
76
99
  ### Minor Changes
77
100
 
78
- - ef661acf: Export ActionScheduler
101
+ - ef661acf: Export ActionScheduler
79
102
 
80
103
  ## 2.1.3
81
104
 
82
105
  ### Patch Changes
83
106
 
84
- - b5ba5568: Ensure that flow lib defs use React.ElementConfig<> isntead of JSX.LibraryManagedAttributes<>
107
+ - b5ba5568: Ensure that flow lib defs use React.ElementConfig<> isntead of JSX.LibraryManagedAttributes<>
85
108
 
86
109
  ## 2.1.2
87
110
 
88
111
  ### Patch Changes
89
112
 
90
- - d816af08: Update build and test configs use TypeScript
91
- - 3891f544: Update babel config to include plugins that Storybook needed
92
- - 0d28bb1c: Configured TypeScript
93
- - 3d05f764: Fix HOCs and other type errors
94
- - c2ec4902: Update eslint configuration, fix lint
95
- - 2983c05b: Include 'types' field in package.json
96
- - 77ff6a66: Generate Flow types from TypeScript types
97
- - ec8d4b7f: Fix miscellaneous TypeScript errors
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
98
121
 
99
122
  ## 2.1.1
100
123
 
101
124
  ### Patch Changes
102
125
 
103
- - 91cb727c: Remove file extensions from imports
126
+ - 91cb727c: Remove file extensions from imports
104
127
 
105
128
  ## 2.1.0
106
129
 
107
130
  ### Minor Changes
108
131
 
109
- - 029b4810: Adds `useInterval()` hook that mimics the behavior of `ActionScheduler`'s
110
- `interval()` method.
111
- - c57cd770: Rename `useInterval` and `useTimeout` to `useScheduledInterval`
112
- and `useScheduledTimeout` respectively.
113
- - 29766c8e: Add `useInterval` and `useTimeout` hooks to provide an API for
114
- using intervals and timeouts.
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 = void 0;
23
- this._action = void 0;
24
- this._timeoutMs = void 0;
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 = void 0;
62
- this._action = void 0;
63
- this._intervalMs = void 0;
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 = void 0;
101
- this._action = void 0;
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 ? void 0 : options.schedulePolicy);
142
- this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
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 ? void 0 : options.schedulePolicy);
150
- this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
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 ? void 0 : options.schedulePolicy);
158
- this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
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 (target) {
197
- for (var i = 1; i < arguments.length; i++) {
198
- var source = arguments[i];
199
- for (var key in source) {
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 target;
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 ? void 0 : _intervalRef$current.set();
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 ? void 0 : actionProxyRef.current();
234
+ actionProxyRef.current == null || actionProxyRef.current();
240
235
  }, intervalMs, schedulePolicy);
241
236
  return () => {
242
237
  var _intervalRef$current2;
243
- (_intervalRef$current2 = intervalRef.current) == null ? void 0 : _intervalRef$current2.clear(clearPolicy);
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 ? void 0 : _intervalRef$current3.set();
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 ? void 0 : _intervalRef$current4.clear(policy);
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 ? void 0 : _intervalRef$current5.isSet) != null ? _intervalRef$current$ : false;
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 ? void 0 : _timeoutRef$current.set();
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 ? void 0 : actionProxyRef.current();
279
+ actionProxyRef.current == null || actionProxyRef.current();
285
280
  }, timeoutMs, schedulePolicy);
286
281
  return () => {
287
282
  var _timeoutRef$current2;
288
- (_timeoutRef$current2 = timeoutRef.current) == null ? void 0 : _timeoutRef$current2.clear(clearPolicy);
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 ? void 0 : _timeoutRef$current3.set();
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 ? void 0 : _timeoutRef$current4.clear(policy);
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 ? void 0 : _timeoutRef$current5.isSet) != null ? _timeoutRef$current$i : false;
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 _interopNamespace(e) {
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["default"] = e;
18
+ n.default = e;
22
19
  return Object.freeze(n);
23
20
  }
24
21
 
25
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
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 = void 0;
46
- this._action = void 0;
47
- this._timeoutMs = void 0;
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 = void 0;
85
- this._action = void 0;
86
- this._intervalMs = void 0;
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 = void 0;
124
- this._action = void 0;
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 ? void 0 : options.schedulePolicy);
165
- this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
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 ? void 0 : options.schedulePolicy);
173
- this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
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 ? void 0 : options.schedulePolicy);
181
- this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
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 (target) {
220
- for (var i = 1; i < arguments.length; i++) {
221
- var source = arguments[i];
222
- for (var key in source) {
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 target;
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 ? void 0 : _intervalRef$current.set();
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 ? void 0 : actionProxyRef.current();
254
+ actionProxyRef.current == null || actionProxyRef.current();
263
255
  }, intervalMs, schedulePolicy);
264
256
  return () => {
265
257
  var _intervalRef$current2;
266
- (_intervalRef$current2 = intervalRef.current) == null ? void 0 : _intervalRef$current2.clear(clearPolicy);
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 ? void 0 : _intervalRef$current3.set();
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 ? void 0 : _intervalRef$current4.clear(policy);
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 ? void 0 : _intervalRef$current5.isSet) != null ? _intervalRef$current$ : false;
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 ? void 0 : _timeoutRef$current.set();
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 ? void 0 : actionProxyRef.current();
299
+ actionProxyRef.current == null || actionProxyRef.current();
308
300
  }, timeoutMs, schedulePolicy);
309
301
  return () => {
310
302
  var _timeoutRef$current2;
311
- (_timeoutRef$current2 = timeoutRef.current) == null ? void 0 : _timeoutRef$current2.clear(clearPolicy);
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 ? void 0 : _timeoutRef$current3.set();
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 ? void 0 : _timeoutRef$current4.clear(policy);
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 ? void 0 : _timeoutRef$current5.isSet) != null ? _timeoutRef$current$i : false;
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": "6.0.0",
4
+ "version": "7.0.0",
5
5
  "design": "v1",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,16 +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
- },
16
13
  "peerDependencies": {
17
14
  "react": "18.2.0"
18
15
  },
19
16
  "devDependencies": {
20
- "@khanacademy/wb-dev-build-settings": "^2.0.0",
21
- "@khanacademy/wonder-blocks-testing-core": "^2.0.0"
17
+ "@khanacademy/wb-dev-build-settings": "2.1.0",
18
+ "@khanacademy/wonder-blocks-testing-core": "2.1.0"
22
19
  },
23
20
  "author": "",
24
- "license": "MIT"
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "test": "echo \"Error: no test specified\" && exit 1"
24
+ }
25
25
  }