@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.
- package/CHANGELOG.md +13 -0
- package/dist/components/action-scheduler-provider.d.ts +26 -0
- package/dist/components/action-scheduler-provider.js.flow +35 -0
- package/dist/components/with-action-scheduler.d.ts +14 -0
- package/dist/components/with-action-scheduler.js.flow +26 -0
- package/dist/es/index.js +157 -119
- package/dist/hooks/internal/use-updating-ref.d.ts +13 -0
- package/dist/hooks/internal/use-updating-ref.js.flow +22 -0
- package/dist/hooks/use-interval.d.ts +8 -0
- package/dist/hooks/use-interval.js.flow +18 -0
- package/dist/hooks/use-scheduled-interval.d.ts +2 -0
- package/dist/hooks/use-scheduled-interval.js.flow +13 -0
- package/dist/hooks/use-scheduled-timeout.d.ts +2 -0
- package/dist/hooks/use-scheduled-timeout.js.flow +13 -0
- package/dist/hooks/use-timeout.d.ts +8 -0
- package/dist/hooks/use-timeout.js.flow +18 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +158 -123
- package/dist/index.js.flow +31 -2
- package/dist/util/action-scheduler.d.ts +21 -0
- package/dist/util/action-scheduler.js.flow +39 -0
- package/dist/util/animation-frame.d.ts +62 -0
- package/dist/util/animation-frame.js.flow +71 -0
- package/dist/util/interval.d.ts +60 -0
- package/dist/util/interval.js.flow +70 -0
- package/dist/util/policies.d.ts +8 -0
- package/dist/util/policies.js.flow +17 -0
- package/dist/util/timeout.d.ts +62 -0
- package/dist/util/timeout.js.flow +72 -0
- package/dist/util/types.d.ts +228 -0
- package/dist/util/types.js.flow +235 -0
- package/dist/util/types.typestest.d.ts +1 -0
- package/dist/util/types.typestest.js.flow +6 -0
- package/package.json +3 -3
- package/src/components/__tests__/{action-scheduler-provider.test.js → action-scheduler-provider.test.tsx} +0 -2
- package/src/components/__tests__/{with-action-scheduler.test.js → with-action-scheduler.test.tsx} +6 -6
- package/src/components/{action-scheduler-provider.js → action-scheduler-provider.ts} +4 -5
- package/src/components/{with-action-scheduler.js → with-action-scheduler.tsx} +10 -18
- package/src/hooks/__tests__/{use-interval.test.js → use-interval.test.ts} +5 -6
- package/src/hooks/__tests__/{use-scheduled-interval.test.js → use-scheduled-interval.test.ts} +5 -6
- package/src/hooks/__tests__/{use-scheduled-timeout.test.js → use-scheduled-timeout.test.ts} +9 -10
- package/src/hooks/__tests__/{use-timeout.test.js → use-timeout.test.ts} +5 -6
- package/src/hooks/internal/{use-updating-ref.js → use-updating-ref.ts} +5 -2
- package/src/hooks/{use-interval.js → use-interval.ts} +1 -2
- package/src/hooks/{use-scheduled-interval.js → use-scheduled-interval.ts} +2 -2
- package/src/hooks/{use-scheduled-timeout.js → use-scheduled-timeout.ts} +2 -2
- package/src/hooks/{use-timeout.js → use-timeout.ts} +1 -2
- package/src/{index.js → index.ts} +0 -1
- package/src/util/__tests__/{action-scheduler.test.js → action-scheduler.test.ts} +6 -16
- package/src/util/__tests__/{animation-frame.test.js → animation-frame.test.ts} +8 -7
- package/src/util/__tests__/{interval.test.js → interval.test.ts} +1 -2
- package/src/util/__tests__/{timeout.test.js → timeout.test.ts} +1 -2
- package/src/util/{action-scheduler.js → action-scheduler.ts} +13 -6
- package/src/util/{animation-frame.js → animation-frame.ts} +4 -4
- package/src/util/{interval.js → interval.ts} +5 -4
- package/src/util/{policies.js → policies.ts} +2 -3
- package/src/util/{timeout.js → timeout.ts} +5 -4
- package/src/util/{types.js → types.ts} +21 -28
- package/src/util/{types.flowtest.js → types.typestest.tsx} +20 -18
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/__docs__/migration.stories.mdx +0 -112
- package/src/components/__docs__/types.ischedule-actions.stories.mdx +0 -157
- package/src/components/__docs__/with-action-scheduler-examples.js +0 -80
- package/src/components/__docs__/with-action-scheduler.stories.mdx +0 -218
- package/src/hooks/__docs__/use-interval.stories.mdx +0 -80
- package/src/hooks/__docs__/use-scheduled-interval.stories.mdx +0 -147
- package/src/hooks/__docs__/use-scheduled-timeout.stories.mdx +0 -148
- package/src/hooks/__docs__/use-timeout.stories.mdx +0 -80
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-timing
|
|
2
2
|
|
|
3
|
+
## 2.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d816af08: Update build and test configs use TypeScript
|
|
8
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
9
|
+
- 0d28bb1c: Configured TypeScript
|
|
10
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
11
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
12
|
+
- 2983c05b: Include 'types' field in package.json
|
|
13
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
14
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
15
|
+
|
|
3
16
|
## 2.1.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import ActionScheduler from "../util/action-scheduler";
|
|
3
|
+
import type { IScheduleActions } from "../util/types";
|
|
4
|
+
type Props = {
|
|
5
|
+
/**
|
|
6
|
+
* A function that, when given an instance of `IScheduleActions` will
|
|
7
|
+
* render a `React.Node`.
|
|
8
|
+
*/
|
|
9
|
+
children: (arg1: IScheduleActions) => React.ReactElement;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A provider component that passes our action scheduling API to its children
|
|
13
|
+
* and ensures that all scheduled actions are cleared on unmount.
|
|
14
|
+
*
|
|
15
|
+
* ```jsx
|
|
16
|
+
* <ActionSchedulerProvider>
|
|
17
|
+
* {schedule => this.renderThingThatNeedsTimers(schedule)}
|
|
18
|
+
* </ActionSchedulerProvider>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export default class ActionSchedulerProvider extends React.Component<Props> {
|
|
22
|
+
componentWillUnmount(): void;
|
|
23
|
+
_actionScheduler: ActionScheduler;
|
|
24
|
+
render(): React.ReactElement;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for action-scheduler-provider
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import ActionScheduler from "../util/action-scheduler";
|
|
10
|
+
import type { IScheduleActions } from "../util/types";
|
|
11
|
+
declare type Props = {
|
|
12
|
+
/**
|
|
13
|
+
* A function that, when given an instance of `IScheduleActions` will
|
|
14
|
+
* render a `React.Node`.
|
|
15
|
+
*/
|
|
16
|
+
children: (arg1: IScheduleActions) => React.Element<>,
|
|
17
|
+
...
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A provider component that passes our action scheduling API to its children
|
|
21
|
+
* and ensures that all scheduled actions are cleared on unmount.
|
|
22
|
+
*
|
|
23
|
+
* ```jsx
|
|
24
|
+
* <ActionSchedulerProvider>
|
|
25
|
+
* {schedule => this.renderThingThatNeedsTimers(schedule)}
|
|
26
|
+
* </ActionSchedulerProvider>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare export default class ActionSchedulerProvider
|
|
30
|
+
mixins React.Component<Props>
|
|
31
|
+
{
|
|
32
|
+
componentWillUnmount(): void;
|
|
33
|
+
_actionScheduler: ActionScheduler;
|
|
34
|
+
render(): React.Element<>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { WithActionSchedulerProps } from "../util/types";
|
|
3
|
+
type WithoutActionScheduler<T> = Omit<T, "schedule">;
|
|
4
|
+
/**
|
|
5
|
+
* A higher order component that attaches the given component to an
|
|
6
|
+
* `IScheduleActions` instance. Any actions scheduled will automatically be
|
|
7
|
+
* cleared on unmount.
|
|
8
|
+
*
|
|
9
|
+
* @template TOwnProps The own props of the component being rendered, without
|
|
10
|
+
* the additional action scheduler prop. To attach the additional prop to
|
|
11
|
+
* these props use the `WithActionScheduler` type.
|
|
12
|
+
*/
|
|
13
|
+
export default function withActionScheduler<Props extends WithActionSchedulerProps>(WrappedComponent: React.ComponentType<Props>): React.ForwardRefExoticComponent<React.PropsWithoutRef<WithoutActionScheduler<Props>> & React.RefAttributes<unknown>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for with-action-scheduler
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { WithActionSchedulerProps } from "../util/types";
|
|
10
|
+
declare type WithoutActionScheduler<T> = $Diff<T, { schedule: any }>;
|
|
11
|
+
/**
|
|
12
|
+
* A higher order component that attaches the given component to an
|
|
13
|
+
* `IScheduleActions` instance. Any actions scheduled will automatically be
|
|
14
|
+
* cleared on unmount.
|
|
15
|
+
* @template The own props of the component being rendered, without
|
|
16
|
+
* the additional action scheduler prop. To attach the additional prop to
|
|
17
|
+
* these props use the `WithActionScheduler` type.
|
|
18
|
+
*/
|
|
19
|
+
declare export default function withActionScheduler<
|
|
20
|
+
Props: WithActionSchedulerProps
|
|
21
|
+
>(
|
|
22
|
+
WrappedComponent: React.ComponentType<Props>
|
|
23
|
+
): React.ForwardRefExoticComponent<{
|
|
24
|
+
...React.PropsWithoutRef<WithoutActionScheduler<Props>>,
|
|
25
|
+
...React.RefAttributes<mixed>,
|
|
26
|
+
}>;
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useRef, useEffect, useState, useCallback } from 'react';
|
|
4
3
|
|
|
@@ -11,224 +10,275 @@ const ClearPolicy = {
|
|
|
11
10
|
Cancel: "cancel-on-clear"
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
function _extends() {
|
|
14
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
15
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
16
|
+
var source = arguments[i];
|
|
17
|
+
for (var key in source) {
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
19
|
+
target[key] = source[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return target;
|
|
24
|
+
};
|
|
25
|
+
return _extends.apply(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _setPrototypeOf(o, p) {
|
|
29
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
30
|
+
o.__proto__ = p;
|
|
31
|
+
return o;
|
|
32
|
+
};
|
|
33
|
+
return _setPrototypeOf(o, p);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function _inheritsLoose(subClass, superClass) {
|
|
37
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
38
|
+
subClass.prototype.constructor = subClass;
|
|
39
|
+
_setPrototypeOf(subClass, superClass);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _typeof(obj) {
|
|
43
|
+
"@babel/helpers - typeof";
|
|
44
|
+
|
|
45
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
46
|
+
return typeof obj;
|
|
47
|
+
} : function (obj) {
|
|
48
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
49
|
+
}, _typeof(obj);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _toPrimitive(input, hint) {
|
|
53
|
+
if (_typeof(input) !== "object" || input === null) return input;
|
|
54
|
+
var prim = input[Symbol.toPrimitive];
|
|
55
|
+
if (prim !== undefined) {
|
|
56
|
+
var res = prim.call(input, hint || "default");
|
|
57
|
+
if (_typeof(res) !== "object") return res;
|
|
58
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
59
|
+
}
|
|
60
|
+
return (hint === "string" ? String : Number)(input);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function _toPropertyKey(arg) {
|
|
64
|
+
var key = _toPrimitive(arg, "string");
|
|
65
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function _defineProperties(target, props) {
|
|
69
|
+
for (var i = 0; i < props.length; i++) {
|
|
70
|
+
var descriptor = props[i];
|
|
71
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
72
|
+
descriptor.configurable = true;
|
|
73
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
74
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
78
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
79
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
80
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
81
|
+
writable: false
|
|
82
|
+
});
|
|
83
|
+
return Constructor;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let Timeout = function () {
|
|
87
|
+
function Timeout(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
88
|
+
this._timeoutId = void 0;
|
|
89
|
+
this._action = void 0;
|
|
90
|
+
this._timeoutMs = void 0;
|
|
16
91
|
if (typeof action !== "function") {
|
|
17
92
|
throw new Error("Action must be a function");
|
|
18
93
|
}
|
|
19
|
-
|
|
20
94
|
if (timeoutMs < 0) {
|
|
21
95
|
throw new Error("Timeout period must be >= 0");
|
|
22
96
|
}
|
|
23
|
-
|
|
24
97
|
this._action = action;
|
|
25
98
|
this._timeoutMs = timeoutMs;
|
|
26
|
-
|
|
27
99
|
if (schedulePolicy === SchedulePolicy.Immediately) {
|
|
28
100
|
this.set();
|
|
29
101
|
}
|
|
30
102
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return this._timeoutId != null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set() {
|
|
103
|
+
var _proto = Timeout.prototype;
|
|
104
|
+
_proto.set = function set() {
|
|
37
105
|
if (this.isSet) {
|
|
38
106
|
this.clear(ClearPolicy.Cancel);
|
|
39
107
|
}
|
|
40
|
-
|
|
41
108
|
this._timeoutId = setTimeout(() => this.clear(ClearPolicy.Resolve), this._timeoutMs);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
clear(policy = ClearPolicy.Cancel) {
|
|
109
|
+
};
|
|
110
|
+
_proto.clear = function clear(policy = ClearPolicy.Cancel) {
|
|
45
111
|
const timeoutId = this._timeoutId;
|
|
46
112
|
this._timeoutId = null;
|
|
47
|
-
|
|
48
113
|
if (timeoutId == null) {
|
|
49
114
|
return;
|
|
50
115
|
}
|
|
51
|
-
|
|
52
116
|
clearTimeout(timeoutId);
|
|
53
|
-
|
|
54
117
|
if (policy === ClearPolicy.Resolve) {
|
|
55
118
|
this._action();
|
|
56
119
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
120
|
+
};
|
|
121
|
+
_createClass(Timeout, [{
|
|
122
|
+
key: "isSet",
|
|
123
|
+
get: function () {
|
|
124
|
+
return this._timeoutId != null;
|
|
125
|
+
}
|
|
126
|
+
}]);
|
|
127
|
+
return Timeout;
|
|
128
|
+
}();
|
|
129
|
+
|
|
130
|
+
let Interval = function () {
|
|
131
|
+
function Interval(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
132
|
+
this._intervalId = void 0;
|
|
133
|
+
this._action = void 0;
|
|
134
|
+
this._intervalMs = void 0;
|
|
63
135
|
if (typeof action !== "function") {
|
|
64
136
|
throw new Error("Action must be a function");
|
|
65
137
|
}
|
|
66
|
-
|
|
67
138
|
if (intervalMs < 1) {
|
|
68
139
|
throw new Error("Interval period must be >= 1");
|
|
69
140
|
}
|
|
70
|
-
|
|
71
141
|
this._action = action;
|
|
72
142
|
this._intervalMs = intervalMs;
|
|
73
|
-
|
|
74
143
|
if (schedulePolicy === SchedulePolicy.Immediately) {
|
|
75
144
|
this.set();
|
|
76
145
|
}
|
|
77
146
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return this._intervalId != null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
set() {
|
|
147
|
+
var _proto = Interval.prototype;
|
|
148
|
+
_proto.set = function set() {
|
|
84
149
|
if (this.isSet) {
|
|
85
150
|
this.clear(ClearPolicy.Cancel);
|
|
86
151
|
}
|
|
87
|
-
|
|
88
152
|
this._intervalId = setInterval(() => this._action(), this._intervalMs);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
clear(policy = ClearPolicy.Cancel) {
|
|
153
|
+
};
|
|
154
|
+
_proto.clear = function clear(policy = ClearPolicy.Cancel) {
|
|
92
155
|
const intervalId = this._intervalId;
|
|
93
156
|
this._intervalId = null;
|
|
94
|
-
|
|
95
157
|
if (intervalId == null) {
|
|
96
158
|
return;
|
|
97
159
|
}
|
|
98
|
-
|
|
99
160
|
clearInterval(intervalId);
|
|
100
|
-
|
|
101
161
|
if (policy === ClearPolicy.Resolve) {
|
|
102
162
|
this._action();
|
|
103
163
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
164
|
+
};
|
|
165
|
+
_createClass(Interval, [{
|
|
166
|
+
key: "isSet",
|
|
167
|
+
get: function () {
|
|
168
|
+
return this._intervalId != null;
|
|
169
|
+
}
|
|
170
|
+
}]);
|
|
171
|
+
return Interval;
|
|
172
|
+
}();
|
|
173
|
+
|
|
174
|
+
let AnimationFrame = function () {
|
|
175
|
+
function AnimationFrame(action, schedulePolicy = SchedulePolicy.Immediately) {
|
|
176
|
+
this._animationFrameId = void 0;
|
|
177
|
+
this._action = void 0;
|
|
110
178
|
if (typeof action !== "function") {
|
|
111
179
|
throw new Error("Action must be a function");
|
|
112
180
|
}
|
|
113
|
-
|
|
114
181
|
this._action = action;
|
|
115
|
-
|
|
116
182
|
if (schedulePolicy === SchedulePolicy.Immediately) {
|
|
117
183
|
this.set();
|
|
118
184
|
}
|
|
119
185
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return this._animationFrameId != null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
set() {
|
|
186
|
+
var _proto = AnimationFrame.prototype;
|
|
187
|
+
_proto.set = function set() {
|
|
126
188
|
if (this.isSet) {
|
|
127
189
|
this.clear(ClearPolicy.Cancel);
|
|
128
190
|
}
|
|
129
|
-
|
|
130
191
|
this._animationFrameId = requestAnimationFrame(time => this.clear(ClearPolicy.Resolve, time));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
clear(policy = ClearPolicy.Cancel, time) {
|
|
192
|
+
};
|
|
193
|
+
_proto.clear = function clear(policy = ClearPolicy.Cancel, time) {
|
|
134
194
|
const animationFrameId = this._animationFrameId;
|
|
135
195
|
this._animationFrameId = null;
|
|
136
|
-
|
|
137
196
|
if (animationFrameId == null) {
|
|
138
197
|
return;
|
|
139
198
|
}
|
|
140
|
-
|
|
141
199
|
cancelAnimationFrame(animationFrameId);
|
|
142
|
-
|
|
143
200
|
if (policy === ClearPolicy.Resolve) {
|
|
144
201
|
this._action(time || performance.now());
|
|
145
202
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
203
|
+
};
|
|
204
|
+
_createClass(AnimationFrame, [{
|
|
205
|
+
key: "isSet",
|
|
206
|
+
get: function () {
|
|
207
|
+
return this._animationFrameId != null;
|
|
208
|
+
}
|
|
209
|
+
}]);
|
|
210
|
+
return AnimationFrame;
|
|
211
|
+
}();
|
|
149
212
|
|
|
150
|
-
|
|
151
|
-
|
|
213
|
+
let ActionScheduler = function () {
|
|
214
|
+
function ActionScheduler() {
|
|
152
215
|
this._disabled = false;
|
|
153
216
|
this._registeredActions = [];
|
|
154
217
|
}
|
|
155
|
-
|
|
156
|
-
timeout(action, period, options) {
|
|
218
|
+
var _proto = ActionScheduler.prototype;
|
|
219
|
+
_proto.timeout = function timeout(action, period, options) {
|
|
157
220
|
if (this._disabled) {
|
|
158
221
|
return ActionScheduler.NoopAction;
|
|
159
222
|
}
|
|
160
|
-
|
|
161
223
|
const timeout = new Timeout(action, period, options == null ? void 0 : options.schedulePolicy);
|
|
162
|
-
|
|
163
224
|
this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
|
|
164
|
-
|
|
165
225
|
return timeout;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
interval(action, period, options) {
|
|
226
|
+
};
|
|
227
|
+
_proto.interval = function interval(action, period, options) {
|
|
169
228
|
if (this._disabled) {
|
|
170
229
|
return ActionScheduler.NoopAction;
|
|
171
230
|
}
|
|
172
|
-
|
|
173
231
|
const interval = new Interval(action, period, options == null ? void 0 : options.schedulePolicy);
|
|
174
|
-
|
|
175
232
|
this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
|
|
176
|
-
|
|
177
233
|
return interval;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
animationFrame(action, options) {
|
|
234
|
+
};
|
|
235
|
+
_proto.animationFrame = function animationFrame(action, options) {
|
|
181
236
|
if (this._disabled) {
|
|
182
237
|
return ActionScheduler.NoopAction;
|
|
183
238
|
}
|
|
184
|
-
|
|
185
239
|
const animationFrame = new AnimationFrame(action, options == null ? void 0 : options.schedulePolicy);
|
|
186
|
-
|
|
187
240
|
this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
|
|
188
|
-
|
|
189
241
|
return animationFrame;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
clearAll() {
|
|
242
|
+
};
|
|
243
|
+
_proto.clearAll = function clearAll() {
|
|
193
244
|
const registered = [].concat(this._registeredActions);
|
|
194
245
|
this._registeredActions = [];
|
|
195
246
|
registered.forEach(clearFn => clearFn());
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
disable() {
|
|
247
|
+
};
|
|
248
|
+
_proto.disable = function disable() {
|
|
199
249
|
this._disabled = true;
|
|
200
250
|
this.clearAll();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
}
|
|
251
|
+
};
|
|
252
|
+
return ActionScheduler;
|
|
253
|
+
}();
|
|
204
254
|
ActionScheduler.NoopAction = {
|
|
205
255
|
set: () => {},
|
|
206
|
-
|
|
207
256
|
get isSet() {
|
|
208
257
|
return false;
|
|
209
258
|
},
|
|
210
|
-
|
|
211
259
|
clear: () => {}
|
|
212
260
|
};
|
|
213
261
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
262
|
+
let ActionSchedulerProvider = function (_React$Component) {
|
|
263
|
+
_inheritsLoose(ActionSchedulerProvider, _React$Component);
|
|
264
|
+
function ActionSchedulerProvider(...args) {
|
|
265
|
+
var _this;
|
|
266
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
267
|
+
_this._actionScheduler = new ActionScheduler();
|
|
268
|
+
return _this;
|
|
218
269
|
}
|
|
219
|
-
|
|
220
|
-
componentWillUnmount() {
|
|
270
|
+
var _proto = ActionSchedulerProvider.prototype;
|
|
271
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
221
272
|
this._actionScheduler.disable();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
render() {
|
|
273
|
+
};
|
|
274
|
+
_proto.render = function render() {
|
|
225
275
|
const {
|
|
226
276
|
children
|
|
227
277
|
} = this.props;
|
|
228
278
|
return children(this._actionScheduler);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
}
|
|
279
|
+
};
|
|
280
|
+
return ActionSchedulerProvider;
|
|
281
|
+
}(React.Component);
|
|
232
282
|
|
|
233
283
|
function withActionScheduler(WrappedComponent) {
|
|
234
284
|
return React.forwardRef((props, ref) => React.createElement(ActionSchedulerProvider, null, schedule => React.createElement(WrappedComponent, _extends({}, props, {
|
|
@@ -275,28 +325,22 @@ function useTimeout(action, timeoutMs, active) {
|
|
|
275
325
|
|
|
276
326
|
function useScheduledInterval(action, intervalMs, options) {
|
|
277
327
|
var _options$schedulePoli;
|
|
278
|
-
|
|
279
328
|
if (typeof action !== "function") {
|
|
280
329
|
throw new Error("Action must be a function");
|
|
281
330
|
}
|
|
282
|
-
|
|
283
331
|
if (intervalMs < 1) {
|
|
284
332
|
throw new Error("Interval period must be >= 1");
|
|
285
333
|
}
|
|
286
|
-
|
|
287
334
|
const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : SchedulePolicy.Immediately;
|
|
288
335
|
const [isSet, setIsSet] = useState(schedulePolicy === SchedulePolicy.Immediately);
|
|
289
336
|
const set = useCallback(() => setIsSet(true), []);
|
|
290
337
|
const actionRef = useUpdatingRef(action);
|
|
291
338
|
const clear = useCallback(policy => {
|
|
292
339
|
var _policy;
|
|
293
|
-
|
|
294
340
|
policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy;
|
|
295
|
-
|
|
296
341
|
if (isSet && policy === ClearPolicy.Resolve) {
|
|
297
342
|
actionRef.current();
|
|
298
343
|
}
|
|
299
|
-
|
|
300
344
|
setIsSet(false);
|
|
301
345
|
}, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]);
|
|
302
346
|
const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve);
|
|
@@ -317,15 +361,12 @@ function useScheduledInterval(action, intervalMs, options) {
|
|
|
317
361
|
|
|
318
362
|
function useScheduledTimeout(action, timeoutMs, options) {
|
|
319
363
|
var _options$schedulePoli;
|
|
320
|
-
|
|
321
364
|
if (typeof action !== "function") {
|
|
322
365
|
throw new Error("Action must be a function");
|
|
323
366
|
}
|
|
324
|
-
|
|
325
367
|
if (timeoutMs < 0) {
|
|
326
368
|
throw new Error("Timeout period must be >= 0");
|
|
327
369
|
}
|
|
328
|
-
|
|
329
370
|
const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : SchedulePolicy.Immediately;
|
|
330
371
|
const [isSet, setIsSet] = useState(schedulePolicy === SchedulePolicy.Immediately);
|
|
331
372
|
const set = useCallback(() => setIsSet(true), []);
|
|
@@ -336,13 +377,10 @@ function useScheduledTimeout(action, timeoutMs, options) {
|
|
|
336
377
|
const actionRef = useUpdatingRef(wrappedAction);
|
|
337
378
|
const clear = useCallback(policy => {
|
|
338
379
|
var _policy;
|
|
339
|
-
|
|
340
380
|
policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy;
|
|
341
|
-
|
|
342
381
|
if (isSet && policy === ClearPolicy.Resolve) {
|
|
343
382
|
actionRef.current();
|
|
344
383
|
}
|
|
345
|
-
|
|
346
384
|
setIsSet(false);
|
|
347
385
|
}, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]);
|
|
348
386
|
const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a ref whose .current value is updated whenever
|
|
3
|
+
* the `value` passed to this hook changes.
|
|
4
|
+
*
|
|
5
|
+
* this is great for values that you want to reference from
|
|
6
|
+
* within a useCallback or useEffect event listener, without
|
|
7
|
+
* re-triggering the effect when the value changes
|
|
8
|
+
*
|
|
9
|
+
* @returns {{current: T}}
|
|
10
|
+
*/
|
|
11
|
+
export declare const useUpdatingRef: <T>(value: T) => {
|
|
12
|
+
current: T;
|
|
13
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-updating-ref
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns a ref whose .current value is updated whenever
|
|
10
|
+
* the `value` passed to this hook changes.
|
|
11
|
+
*
|
|
12
|
+
* this is great for values that you want to reference from
|
|
13
|
+
* within a useCallback or useEffect event listener, without
|
|
14
|
+
* re-triggering the effect when the value changes
|
|
15
|
+
* @returns {{
|
|
16
|
+
current: T,...
|
|
17
|
+
}}
|
|
18
|
+
*/
|
|
19
|
+
declare export var useUpdatingRef: <T>(value: T) => {
|
|
20
|
+
current: T,
|
|
21
|
+
...
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple hook for using `setInterval`.
|
|
3
|
+
*
|
|
4
|
+
* @param action called every `intervalMs` when `active` is true
|
|
5
|
+
* @param intervalMs the duration between calls to `action`
|
|
6
|
+
* @param active whether or not the interval is active
|
|
7
|
+
*/
|
|
8
|
+
export declare function useInterval(action: () => unknown, intervalMs: number, active: boolean): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-interval
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A simple hook for using `setInterval`.
|
|
10
|
+
* @param action called every `intervalMs` when `active` is true
|
|
11
|
+
* @param intervalMs the duration between calls to `action`
|
|
12
|
+
* @param active whether or not the interval is active
|
|
13
|
+
*/
|
|
14
|
+
declare export function useInterval(
|
|
15
|
+
action: () => mixed,
|
|
16
|
+
intervalMs: number,
|
|
17
|
+
active: boolean
|
|
18
|
+
): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-scheduled-interval
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { IInterval, Options } from "../util/types";
|
|
9
|
+
declare export function useScheduledInterval(
|
|
10
|
+
action: () => mixed,
|
|
11
|
+
intervalMs: number,
|
|
12
|
+
options?: Options
|
|
13
|
+
): IInterval;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for use-scheduled-timeout
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ITimeout, Options } from "../util/types";
|
|
9
|
+
declare export function useScheduledTimeout(
|
|
10
|
+
action: () => mixed,
|
|
11
|
+
timeoutMs: number,
|
|
12
|
+
options?: Options
|
|
13
|
+
): ITimeout;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple hook for using `setTimeout`.
|
|
3
|
+
*
|
|
4
|
+
* @param action called after `timeoutMs` when `active` is true
|
|
5
|
+
* @param timeoutMs the duration after which `action` is called
|
|
6
|
+
* @param active whether or not the interval is active
|
|
7
|
+
*/
|
|
8
|
+
export declare function useTimeout(action: () => unknown, timeoutMs: number, active: boolean): void;
|