@khanacademy/wonder-blocks-timing 2.1.1 → 2.1.2

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/components/action-scheduler-provider.d.ts +26 -0
  3. package/dist/components/action-scheduler-provider.js.flow +35 -0
  4. package/dist/components/with-action-scheduler.d.ts +14 -0
  5. package/dist/components/with-action-scheduler.js.flow +26 -0
  6. package/dist/es/index.js +157 -119
  7. package/dist/hooks/internal/use-updating-ref.d.ts +13 -0
  8. package/dist/hooks/internal/use-updating-ref.js.flow +22 -0
  9. package/dist/hooks/use-interval.d.ts +8 -0
  10. package/dist/hooks/use-interval.js.flow +18 -0
  11. package/dist/hooks/use-scheduled-interval.d.ts +2 -0
  12. package/dist/hooks/use-scheduled-interval.js.flow +13 -0
  13. package/dist/hooks/use-scheduled-timeout.d.ts +2 -0
  14. package/dist/hooks/use-scheduled-timeout.js.flow +13 -0
  15. package/dist/hooks/use-timeout.d.ts +8 -0
  16. package/dist/hooks/use-timeout.js.flow +18 -0
  17. package/dist/index.d.ts +8 -0
  18. package/dist/index.js +158 -123
  19. package/dist/index.js.flow +31 -2
  20. package/dist/util/action-scheduler.d.ts +21 -0
  21. package/dist/util/action-scheduler.js.flow +39 -0
  22. package/dist/util/animation-frame.d.ts +62 -0
  23. package/dist/util/animation-frame.js.flow +71 -0
  24. package/dist/util/interval.d.ts +60 -0
  25. package/dist/util/interval.js.flow +70 -0
  26. package/dist/util/policies.d.ts +8 -0
  27. package/dist/util/policies.js.flow +17 -0
  28. package/dist/util/timeout.d.ts +62 -0
  29. package/dist/util/timeout.js.flow +72 -0
  30. package/dist/util/types.d.ts +228 -0
  31. package/dist/util/types.js.flow +235 -0
  32. package/dist/util/types.typestest.d.ts +1 -0
  33. package/dist/util/types.typestest.js.flow +6 -0
  34. package/package.json +3 -3
  35. package/src/components/__tests__/{action-scheduler-provider.test.js → action-scheduler-provider.test.tsx} +0 -2
  36. package/src/components/__tests__/{with-action-scheduler.test.js → with-action-scheduler.test.tsx} +6 -6
  37. package/src/components/{action-scheduler-provider.js → action-scheduler-provider.ts} +4 -5
  38. package/src/components/{with-action-scheduler.js → with-action-scheduler.tsx} +10 -18
  39. package/src/hooks/__tests__/{use-interval.test.js → use-interval.test.ts} +5 -6
  40. package/src/hooks/__tests__/{use-scheduled-interval.test.js → use-scheduled-interval.test.ts} +5 -6
  41. package/src/hooks/__tests__/{use-scheduled-timeout.test.js → use-scheduled-timeout.test.ts} +9 -10
  42. package/src/hooks/__tests__/{use-timeout.test.js → use-timeout.test.ts} +5 -6
  43. package/src/hooks/internal/{use-updating-ref.js → use-updating-ref.ts} +5 -2
  44. package/src/hooks/{use-interval.js → use-interval.ts} +1 -2
  45. package/src/hooks/{use-scheduled-interval.js → use-scheduled-interval.ts} +2 -2
  46. package/src/hooks/{use-scheduled-timeout.js → use-scheduled-timeout.ts} +2 -2
  47. package/src/hooks/{use-timeout.js → use-timeout.ts} +1 -2
  48. package/src/{index.js → index.ts} +0 -1
  49. package/src/util/__tests__/{action-scheduler.test.js → action-scheduler.test.ts} +6 -16
  50. package/src/util/__tests__/{animation-frame.test.js → animation-frame.test.ts} +8 -7
  51. package/src/util/__tests__/{interval.test.js → interval.test.ts} +1 -2
  52. package/src/util/__tests__/{timeout.test.js → timeout.test.ts} +1 -2
  53. package/src/util/{action-scheduler.js → action-scheduler.ts} +13 -6
  54. package/src/util/{animation-frame.js → animation-frame.ts} +4 -4
  55. package/src/util/{interval.js → interval.ts} +5 -4
  56. package/src/util/{policies.js → policies.ts} +2 -3
  57. package/src/util/{timeout.js → timeout.ts} +5 -4
  58. package/src/util/{types.js → types.ts} +21 -28
  59. package/src/util/{types.flowtest.js → types.typestest.tsx} +20 -18
  60. package/tsconfig.json +11 -0
  61. package/tsconfig.tsbuildinfo +1 -0
  62. package/src/components/__docs__/migration.stories.mdx +0 -112
  63. package/src/components/__docs__/types.ischedule-actions.stories.mdx +0 -157
  64. package/src/components/__docs__/with-action-scheduler-examples.js +0 -80
  65. package/src/components/__docs__/with-action-scheduler.stories.mdx +0 -218
  66. package/src/hooks/__docs__/use-interval.stories.mdx +0 -80
  67. package/src/hooks/__docs__/use-scheduled-interval.stories.mdx +0 -147
  68. package/src/hooks/__docs__/use-scheduled-timeout.stories.mdx +0 -148
  69. package/src/hooks/__docs__/use-timeout.stories.mdx +0 -80
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Flowtype definitions for use-timeout
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ /**
9
+ * A simple hook for using `setTimeout`.
10
+ * @param action called after `timeoutMs` when `active` is true
11
+ * @param timeoutMs the duration after which `action` is called
12
+ * @param active whether or not the interval is active
13
+ */
14
+ declare export function useTimeout(
15
+ action: () => mixed,
16
+ timeoutMs: number,
17
+ active: boolean
18
+ ): void;
@@ -0,0 +1,8 @@
1
+ import type { IAnimationFrame, IInterval, IScheduleActions, ITimeout, WithActionScheduler, WithActionSchedulerProps, WithoutActionScheduler } from "./util/types";
2
+ export type { IAnimationFrame, IInterval, IScheduleActions, ITimeout, WithActionScheduler, WithActionSchedulerProps, WithoutActionScheduler, };
3
+ export { SchedulePolicy, ClearPolicy } from "./util/policies";
4
+ export { default as withActionScheduler } from "./components/with-action-scheduler";
5
+ export { useInterval } from "./hooks/use-interval";
6
+ export { useTimeout } from "./hooks/use-timeout";
7
+ export { useScheduledInterval } from "./hooks/use-scheduled-interval";
8
+ export { useScheduledTimeout } from "./hooks/use-scheduled-timeout";
package/dist/index.js CHANGED
@@ -2,11 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _extends = require('@babel/runtime/helpers/extends');
6
5
  var React = require('react');
7
6
 
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
-
10
7
  function _interopNamespace(e) {
11
8
  if (e && e.__esModule) return e;
12
9
  var n = Object.create(null);
@@ -25,7 +22,6 @@ function _interopNamespace(e) {
25
22
  return Object.freeze(n);
26
23
  }
27
24
 
28
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
29
25
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
30
26
 
31
27
  const SchedulePolicy = {
@@ -37,227 +33,278 @@ const ClearPolicy = {
37
33
  Cancel: "cancel-on-clear"
38
34
  };
39
35
 
40
- class Timeout {
41
- constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
36
+ function _extends() {
37
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
38
+ for (var i = 1; i < arguments.length; i++) {
39
+ var source = arguments[i];
40
+ for (var key in source) {
41
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
42
+ target[key] = source[key];
43
+ }
44
+ }
45
+ }
46
+ return target;
47
+ };
48
+ return _extends.apply(this, arguments);
49
+ }
50
+
51
+ function _setPrototypeOf(o, p) {
52
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
53
+ o.__proto__ = p;
54
+ return o;
55
+ };
56
+ return _setPrototypeOf(o, p);
57
+ }
58
+
59
+ function _inheritsLoose(subClass, superClass) {
60
+ subClass.prototype = Object.create(superClass.prototype);
61
+ subClass.prototype.constructor = subClass;
62
+ _setPrototypeOf(subClass, superClass);
63
+ }
64
+
65
+ function _typeof(obj) {
66
+ "@babel/helpers - typeof";
67
+
68
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
69
+ return typeof obj;
70
+ } : function (obj) {
71
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
72
+ }, _typeof(obj);
73
+ }
74
+
75
+ function _toPrimitive(input, hint) {
76
+ if (_typeof(input) !== "object" || input === null) return input;
77
+ var prim = input[Symbol.toPrimitive];
78
+ if (prim !== undefined) {
79
+ var res = prim.call(input, hint || "default");
80
+ if (_typeof(res) !== "object") return res;
81
+ throw new TypeError("@@toPrimitive must return a primitive value.");
82
+ }
83
+ return (hint === "string" ? String : Number)(input);
84
+ }
85
+
86
+ function _toPropertyKey(arg) {
87
+ var key = _toPrimitive(arg, "string");
88
+ return _typeof(key) === "symbol" ? key : String(key);
89
+ }
90
+
91
+ function _defineProperties(target, props) {
92
+ for (var i = 0; i < props.length; i++) {
93
+ var descriptor = props[i];
94
+ descriptor.enumerable = descriptor.enumerable || false;
95
+ descriptor.configurable = true;
96
+ if ("value" in descriptor) descriptor.writable = true;
97
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
98
+ }
99
+ }
100
+ function _createClass(Constructor, protoProps, staticProps) {
101
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
102
+ if (staticProps) _defineProperties(Constructor, staticProps);
103
+ Object.defineProperty(Constructor, "prototype", {
104
+ writable: false
105
+ });
106
+ return Constructor;
107
+ }
108
+
109
+ let Timeout = function () {
110
+ function Timeout(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
111
+ this._timeoutId = void 0;
112
+ this._action = void 0;
113
+ this._timeoutMs = void 0;
42
114
  if (typeof action !== "function") {
43
115
  throw new Error("Action must be a function");
44
116
  }
45
-
46
117
  if (timeoutMs < 0) {
47
118
  throw new Error("Timeout period must be >= 0");
48
119
  }
49
-
50
120
  this._action = action;
51
121
  this._timeoutMs = timeoutMs;
52
-
53
122
  if (schedulePolicy === SchedulePolicy.Immediately) {
54
123
  this.set();
55
124
  }
56
125
  }
57
-
58
- get isSet() {
59
- return this._timeoutId != null;
60
- }
61
-
62
- set() {
126
+ var _proto = Timeout.prototype;
127
+ _proto.set = function set() {
63
128
  if (this.isSet) {
64
129
  this.clear(ClearPolicy.Cancel);
65
130
  }
66
-
67
131
  this._timeoutId = setTimeout(() => this.clear(ClearPolicy.Resolve), this._timeoutMs);
68
- }
69
-
70
- clear(policy = ClearPolicy.Cancel) {
132
+ };
133
+ _proto.clear = function clear(policy = ClearPolicy.Cancel) {
71
134
  const timeoutId = this._timeoutId;
72
135
  this._timeoutId = null;
73
-
74
136
  if (timeoutId == null) {
75
137
  return;
76
138
  }
77
-
78
139
  clearTimeout(timeoutId);
79
-
80
140
  if (policy === ClearPolicy.Resolve) {
81
141
  this._action();
82
142
  }
83
- }
84
-
85
- }
86
-
87
- class Interval {
88
- constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
143
+ };
144
+ _createClass(Timeout, [{
145
+ key: "isSet",
146
+ get: function () {
147
+ return this._timeoutId != null;
148
+ }
149
+ }]);
150
+ return Timeout;
151
+ }();
152
+
153
+ let Interval = function () {
154
+ function Interval(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
155
+ this._intervalId = void 0;
156
+ this._action = void 0;
157
+ this._intervalMs = void 0;
89
158
  if (typeof action !== "function") {
90
159
  throw new Error("Action must be a function");
91
160
  }
92
-
93
161
  if (intervalMs < 1) {
94
162
  throw new Error("Interval period must be >= 1");
95
163
  }
96
-
97
164
  this._action = action;
98
165
  this._intervalMs = intervalMs;
99
-
100
166
  if (schedulePolicy === SchedulePolicy.Immediately) {
101
167
  this.set();
102
168
  }
103
169
  }
104
-
105
- get isSet() {
106
- return this._intervalId != null;
107
- }
108
-
109
- set() {
170
+ var _proto = Interval.prototype;
171
+ _proto.set = function set() {
110
172
  if (this.isSet) {
111
173
  this.clear(ClearPolicy.Cancel);
112
174
  }
113
-
114
175
  this._intervalId = setInterval(() => this._action(), this._intervalMs);
115
- }
116
-
117
- clear(policy = ClearPolicy.Cancel) {
176
+ };
177
+ _proto.clear = function clear(policy = ClearPolicy.Cancel) {
118
178
  const intervalId = this._intervalId;
119
179
  this._intervalId = null;
120
-
121
180
  if (intervalId == null) {
122
181
  return;
123
182
  }
124
-
125
183
  clearInterval(intervalId);
126
-
127
184
  if (policy === ClearPolicy.Resolve) {
128
185
  this._action();
129
186
  }
130
- }
131
-
132
- }
133
-
134
- class AnimationFrame {
135
- constructor(action, schedulePolicy = SchedulePolicy.Immediately) {
187
+ };
188
+ _createClass(Interval, [{
189
+ key: "isSet",
190
+ get: function () {
191
+ return this._intervalId != null;
192
+ }
193
+ }]);
194
+ return Interval;
195
+ }();
196
+
197
+ let AnimationFrame = function () {
198
+ function AnimationFrame(action, schedulePolicy = SchedulePolicy.Immediately) {
199
+ this._animationFrameId = void 0;
200
+ this._action = void 0;
136
201
  if (typeof action !== "function") {
137
202
  throw new Error("Action must be a function");
138
203
  }
139
-
140
204
  this._action = action;
141
-
142
205
  if (schedulePolicy === SchedulePolicy.Immediately) {
143
206
  this.set();
144
207
  }
145
208
  }
146
-
147
- get isSet() {
148
- return this._animationFrameId != null;
149
- }
150
-
151
- set() {
209
+ var _proto = AnimationFrame.prototype;
210
+ _proto.set = function set() {
152
211
  if (this.isSet) {
153
212
  this.clear(ClearPolicy.Cancel);
154
213
  }
155
-
156
214
  this._animationFrameId = requestAnimationFrame(time => this.clear(ClearPolicy.Resolve, time));
157
- }
158
-
159
- clear(policy = ClearPolicy.Cancel, time) {
215
+ };
216
+ _proto.clear = function clear(policy = ClearPolicy.Cancel, time) {
160
217
  const animationFrameId = this._animationFrameId;
161
218
  this._animationFrameId = null;
162
-
163
219
  if (animationFrameId == null) {
164
220
  return;
165
221
  }
166
-
167
222
  cancelAnimationFrame(animationFrameId);
168
-
169
223
  if (policy === ClearPolicy.Resolve) {
170
224
  this._action(time || performance.now());
171
225
  }
172
- }
173
-
174
- }
226
+ };
227
+ _createClass(AnimationFrame, [{
228
+ key: "isSet",
229
+ get: function () {
230
+ return this._animationFrameId != null;
231
+ }
232
+ }]);
233
+ return AnimationFrame;
234
+ }();
175
235
 
176
- class ActionScheduler {
177
- constructor() {
236
+ let ActionScheduler = function () {
237
+ function ActionScheduler() {
178
238
  this._disabled = false;
179
239
  this._registeredActions = [];
180
240
  }
181
-
182
- timeout(action, period, options) {
241
+ var _proto = ActionScheduler.prototype;
242
+ _proto.timeout = function timeout(action, period, options) {
183
243
  if (this._disabled) {
184
244
  return ActionScheduler.NoopAction;
185
245
  }
186
-
187
246
  const timeout = new Timeout(action, period, options == null ? void 0 : options.schedulePolicy);
188
-
189
247
  this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
190
-
191
248
  return timeout;
192
- }
193
-
194
- interval(action, period, options) {
249
+ };
250
+ _proto.interval = function interval(action, period, options) {
195
251
  if (this._disabled) {
196
252
  return ActionScheduler.NoopAction;
197
253
  }
198
-
199
254
  const interval = new Interval(action, period, options == null ? void 0 : options.schedulePolicy);
200
-
201
255
  this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
202
-
203
256
  return interval;
204
- }
205
-
206
- animationFrame(action, options) {
257
+ };
258
+ _proto.animationFrame = function animationFrame(action, options) {
207
259
  if (this._disabled) {
208
260
  return ActionScheduler.NoopAction;
209
261
  }
210
-
211
262
  const animationFrame = new AnimationFrame(action, options == null ? void 0 : options.schedulePolicy);
212
-
213
263
  this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
214
-
215
264
  return animationFrame;
216
- }
217
-
218
- clearAll() {
265
+ };
266
+ _proto.clearAll = function clearAll() {
219
267
  const registered = [].concat(this._registeredActions);
220
268
  this._registeredActions = [];
221
269
  registered.forEach(clearFn => clearFn());
222
- }
223
-
224
- disable() {
270
+ };
271
+ _proto.disable = function disable() {
225
272
  this._disabled = true;
226
273
  this.clearAll();
227
- }
228
-
229
- }
274
+ };
275
+ return ActionScheduler;
276
+ }();
230
277
  ActionScheduler.NoopAction = {
231
278
  set: () => {},
232
-
233
279
  get isSet() {
234
280
  return false;
235
281
  },
236
-
237
282
  clear: () => {}
238
283
  };
239
284
 
240
- class ActionSchedulerProvider extends React__namespace.Component {
241
- constructor(...args) {
242
- super(...args);
243
- this._actionScheduler = new ActionScheduler();
285
+ let ActionSchedulerProvider = function (_React$Component) {
286
+ _inheritsLoose(ActionSchedulerProvider, _React$Component);
287
+ function ActionSchedulerProvider(...args) {
288
+ var _this;
289
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
290
+ _this._actionScheduler = new ActionScheduler();
291
+ return _this;
244
292
  }
245
-
246
- componentWillUnmount() {
293
+ var _proto = ActionSchedulerProvider.prototype;
294
+ _proto.componentWillUnmount = function componentWillUnmount() {
247
295
  this._actionScheduler.disable();
248
- }
249
-
250
- render() {
296
+ };
297
+ _proto.render = function render() {
251
298
  const {
252
299
  children
253
300
  } = this.props;
254
301
  return children(this._actionScheduler);
255
- }
256
-
257
- }
302
+ };
303
+ return ActionSchedulerProvider;
304
+ }(React__namespace.Component);
258
305
 
259
306
  function withActionScheduler(WrappedComponent) {
260
- return React__namespace.forwardRef((props, ref) => React__namespace.createElement(ActionSchedulerProvider, null, schedule => React__namespace.createElement(WrappedComponent, _extends__default["default"]({}, props, {
307
+ return React__namespace.forwardRef((props, ref) => React__namespace.createElement(ActionSchedulerProvider, null, schedule => React__namespace.createElement(WrappedComponent, _extends({}, props, {
261
308
  ref: ref,
262
309
  schedule: schedule
263
310
  }))));
@@ -301,28 +348,22 @@ function useTimeout(action, timeoutMs, active) {
301
348
 
302
349
  function useScheduledInterval(action, intervalMs, options) {
303
350
  var _options$schedulePoli;
304
-
305
351
  if (typeof action !== "function") {
306
352
  throw new Error("Action must be a function");
307
353
  }
308
-
309
354
  if (intervalMs < 1) {
310
355
  throw new Error("Interval period must be >= 1");
311
356
  }
312
-
313
357
  const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : SchedulePolicy.Immediately;
314
358
  const [isSet, setIsSet] = React.useState(schedulePolicy === SchedulePolicy.Immediately);
315
359
  const set = React.useCallback(() => setIsSet(true), []);
316
360
  const actionRef = useUpdatingRef(action);
317
361
  const clear = React.useCallback(policy => {
318
362
  var _policy;
319
-
320
363
  policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy;
321
-
322
364
  if (isSet && policy === ClearPolicy.Resolve) {
323
365
  actionRef.current();
324
366
  }
325
-
326
367
  setIsSet(false);
327
368
  }, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]);
328
369
  const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve);
@@ -343,15 +384,12 @@ function useScheduledInterval(action, intervalMs, options) {
343
384
 
344
385
  function useScheduledTimeout(action, timeoutMs, options) {
345
386
  var _options$schedulePoli;
346
-
347
387
  if (typeof action !== "function") {
348
388
  throw new Error("Action must be a function");
349
389
  }
350
-
351
390
  if (timeoutMs < 0) {
352
391
  throw new Error("Timeout period must be >= 0");
353
392
  }
354
-
355
393
  const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : SchedulePolicy.Immediately;
356
394
  const [isSet, setIsSet] = React.useState(schedulePolicy === SchedulePolicy.Immediately);
357
395
  const set = React.useCallback(() => setIsSet(true), []);
@@ -362,13 +400,10 @@ function useScheduledTimeout(action, timeoutMs, options) {
362
400
  const actionRef = useUpdatingRef(wrappedAction);
363
401
  const clear = React.useCallback(policy => {
364
402
  var _policy;
365
-
366
403
  policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy;
367
-
368
404
  if (isSet && policy === ClearPolicy.Resolve) {
369
405
  actionRef.current();
370
406
  }
371
-
372
407
  setIsSet(false);
373
408
  }, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]);
374
409
  const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve);
@@ -1,2 +1,31 @@
1
- // @flow
2
- export * from "../src/index";
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import type {
9
+ IAnimationFrame,
10
+ IInterval,
11
+ IScheduleActions,
12
+ ITimeout,
13
+ WithActionScheduler,
14
+ WithActionSchedulerProps,
15
+ WithoutActionScheduler,
16
+ } from "./util/types";
17
+ export type {
18
+ IAnimationFrame,
19
+ IInterval,
20
+ IScheduleActions,
21
+ ITimeout,
22
+ WithActionScheduler,
23
+ WithActionSchedulerProps,
24
+ WithoutActionScheduler,
25
+ };
26
+ declare export { SchedulePolicy, ClearPolicy } from "./util/policies";
27
+ declare export { default as withActionScheduler } from "./components/with-action-scheduler";
28
+ declare export { useInterval } from "./hooks/use-interval";
29
+ declare export { useTimeout } from "./hooks/use-timeout";
30
+ declare export { useScheduledInterval } from "./hooks/use-scheduled-interval";
31
+ declare export { useScheduledTimeout } from "./hooks/use-scheduled-timeout";
@@ -0,0 +1,21 @@
1
+ import type { IAnimationFrame, IInterval, ITimeout, IScheduleActions, Options } from "./types";
2
+ /**
3
+ * Implements the `IScheduleActions` API to provide timeout, interval, and
4
+ * animation frame support. This is not intended for direct use, but instead
5
+ * is to be used solely by the `ActionSchedulerProvider` to provide an
6
+ * `IScheduleActions` instance.
7
+ */
8
+ export default class ActionScheduler implements IScheduleActions {
9
+ _disabled: boolean;
10
+ _registeredActions: Array<() => void>;
11
+ static readonly NoopAction: ITimeout & IAnimationFrame & IInterval;
12
+ timeout(action: () => unknown, period: number, options?: Options): ITimeout;
13
+ interval(action: () => unknown, period: number, options?: Options): IInterval;
14
+ animationFrame(action: (arg1: DOMHighResTimeStamp) => void, options?: Options): IAnimationFrame;
15
+ clearAll(): void;
16
+ /**
17
+ * Prevents this scheduler from creating any additional actions.
18
+ * This also clears any pending actions.
19
+ */
20
+ disable(): void;
21
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Flowtype definitions for action-scheduler
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import type {
9
+ IAnimationFrame,
10
+ IInterval,
11
+ ITimeout,
12
+ IScheduleActions,
13
+ Options,
14
+ } from "./types";
15
+
16
+ /**
17
+ * Implements the `IScheduleActions` API to provide timeout, interval, and
18
+ * animation frame support. This is not intended for direct use, but instead
19
+ * is to be used solely by the `ActionSchedulerProvider` to provide an
20
+ * `IScheduleActions` instance.
21
+ */
22
+ declare export default class ActionScheduler mixins IScheduleActions {
23
+ _disabled: boolean;
24
+ _registeredActions: Array<() => void>;
25
+ static +NoopAction: { ...ITimeout, ...IAnimationFrame, ...IInterval };
26
+ timeout(action: () => mixed, period: number, options?: Options): ITimeout;
27
+ interval(action: () => mixed, period: number, options?: Options): IInterval;
28
+ animationFrame(
29
+ action: (arg1: DOMHighResTimeStamp) => void,
30
+ options?: Options
31
+ ): IAnimationFrame;
32
+ clearAll(): void;
33
+
34
+ /**
35
+ * Prevents this scheduler from creating any additional actions.
36
+ * This also clears any pending actions.
37
+ */
38
+ disable(): void;
39
+ }
@@ -0,0 +1,62 @@
1
+ import type { IAnimationFrame, SchedulePolicy, ClearPolicy } from "./types";
2
+ /**
3
+ * Encapsulates everything associated with calling requestAnimationFrame/
4
+ * cancelAnimationFrame, and managing the lifecycle of that request, including
5
+ * the ability to resolve or cancel a pending request action.
6
+ *
7
+ * @export
8
+ * @class AnimationFrame
9
+ * @implements {IAnimationFrame}
10
+ */
11
+ export default class AnimationFrame implements IAnimationFrame {
12
+ _animationFrameId: number | null | undefined;
13
+ _action: (arg1: DOMHighResTimeStamp) => unknown;
14
+ /**
15
+ * Creates an animation frame request that will invoke the given action.
16
+ * The request is not made until set is called.
17
+ *
18
+ * @param {DOMHighResTimeStamp => mixed} action The action to be invoked.
19
+ * @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately,
20
+ * the interval is set immediately on instantiation; otherwise, `set` must be
21
+ * called to set the interval.
22
+ * Defaults to `SchedulePolicy.Immediately`.
23
+ * @memberof AnimationFrame
24
+ */
25
+ constructor(action: (arg1: DOMHighResTimeStamp) => unknown, schedulePolicy?: SchedulePolicy);
26
+ /**
27
+ * Determine if the request is pending or not.
28
+ *
29
+ * @returns {boolean} true if the request is pending, otherwise
30
+ * false.
31
+ * @memberof AnimationFrame
32
+ */
33
+ get isSet(): boolean;
34
+ /**
35
+ * Make the animation frame request.
36
+ *
37
+ * If the request is pending, this cancels that pending request and
38
+ * makes the request afresh. If the request is not pending, this
39
+ * makes a new request.
40
+ *
41
+ * @memberof AnimationFrame
42
+ */
43
+ set(): void;
44
+ /**
45
+ * Clear the pending request.
46
+ *
47
+ * If the request is pending, this cancels that pending request without
48
+ * invoking the action. If no request is pending, this does nothing.
49
+ *
50
+ * @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request
51
+ * was set when called, the request action is invoked after cancelling
52
+ * the request; otherwise, the pending action is cancelled.
53
+ * Defaults to `ClearPolicy.Cancel`.
54
+ * @param {DOMHighResTimeStamp} [time] Timestamp to pass to the action when
55
+ * ClearPolicy.Resolve is specified. Ignored when ClearPolicy.Cancel is
56
+ * specified.
57
+ *
58
+ * @returns {void}
59
+ * @memberof AnimationFrame
60
+ */
61
+ clear(policy?: ClearPolicy, time?: DOMHighResTimeStamp): void;
62
+ }