@khanacademy/wonder-blocks-timing 3.0.0 → 3.0.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 +2 -2
- package/dist/components/action-scheduler-provider.js.flow +5 -7
- package/dist/components/with-action-scheduler.js.flow +3 -4
- package/dist/es/index.js +53 -133
- package/dist/hooks/internal/use-updating-ref.js.flow +6 -8
- package/dist/hooks/use-interval.js.flow +1 -2
- package/dist/hooks/use-scheduled-interval.js.flow +1 -2
- package/dist/hooks/use-scheduled-timeout.js.flow +1 -2
- package/dist/hooks/use-timeout.js.flow +1 -2
- package/dist/index.js +53 -133
- package/dist/index.js.flow +1 -2
- package/dist/util/action-scheduler.js.flow +3 -4
- package/dist/util/animation-frame.js.flow +2 -3
- package/dist/util/interval.js.flow +2 -3
- package/dist/util/policies.js.flow +5 -8
- package/dist/util/timeout.js.flow +2 -3
- package/dist/util/types.d.ts +3 -3
- package/dist/util/types.js.flow +10 -13
- package/dist/util/types.typestest.js.flow +1 -1
- package/package.json +2 -2
- package/src/components/action-scheduler-provider.ts +2 -2
- package/src/hooks/use-scheduled-interval.ts +0 -1
- package/src/hooks/use-scheduled-timeout.ts +0 -1
- package/src/util/action-scheduler.ts +0 -4
- package/src/util/animation-frame.ts +0 -1
- package/src/util/interval.ts +0 -1
- package/src/util/timeout.ts +0 -1
- package/src/util/types.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-timing
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c20f48f3: Don't transpile classes when building bundles
|
|
8
|
+
|
|
9
|
+
## 3.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ccb6fe00: Miscellaneous TS type fixes
|
|
14
|
+
- d4c2b18c: Fix a variety of issues with Flow types generated by flowgen
|
|
15
|
+
|
|
3
16
|
## 3.0.0
|
|
4
17
|
|
|
5
18
|
### Major Changes
|
|
@@ -6,7 +6,7 @@ type Props = {
|
|
|
6
6
|
* A function that, when given an instance of `IScheduleActions` will
|
|
7
7
|
* render a `React.Node`.
|
|
8
8
|
*/
|
|
9
|
-
children: (arg1: IScheduleActions) => React.
|
|
9
|
+
children: (arg1: IScheduleActions) => React.ReactNode;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* A provider component that passes our action scheduling API to its children
|
|
@@ -21,6 +21,6 @@ type Props = {
|
|
|
21
21
|
export default class ActionSchedulerProvider extends React.Component<Props> {
|
|
22
22
|
componentWillUnmount(): void;
|
|
23
23
|
_actionScheduler: ActionScheduler;
|
|
24
|
-
render(): React.
|
|
24
|
+
render(): React.ReactNode;
|
|
25
25
|
}
|
|
26
26
|
export {};
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import ActionScheduler from "../util/action-scheduler";
|
|
10
9
|
import type { IScheduleActions } from "../util/types";
|
|
11
|
-
declare type Props = {
|
|
10
|
+
declare type Props = {|
|
|
12
11
|
/**
|
|
13
12
|
* A function that, when given an instance of `IScheduleActions` will
|
|
14
13
|
* render a `React.Node`.
|
|
15
14
|
*/
|
|
16
|
-
children: (arg1: IScheduleActions) => React.
|
|
17
|
-
|
|
18
|
-
};
|
|
15
|
+
children: (arg1: IScheduleActions) => React.Node,
|
|
16
|
+
|};
|
|
19
17
|
/**
|
|
20
18
|
* A provider component that passes our action scheduling API to its children
|
|
21
19
|
* and ensures that all scheduled actions are cleared on unmount.
|
|
@@ -31,5 +29,5 @@ declare export default class ActionSchedulerProvider
|
|
|
31
29
|
{
|
|
32
30
|
componentWillUnmount(): void;
|
|
33
31
|
_actionScheduler: ActionScheduler;
|
|
34
|
-
render(): React.
|
|
32
|
+
render(): React.Node;
|
|
35
33
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import type { WithActionSchedulerProps } from "../util/types";
|
|
10
9
|
declare type WithoutActionScheduler<T> = $Diff<T, { schedule: any }>;
|
|
@@ -20,7 +19,7 @@ declare export default function withActionScheduler<
|
|
|
20
19
|
Props: WithActionSchedulerProps
|
|
21
20
|
>(
|
|
22
21
|
WrappedComponent: React.ComponentType<Props>
|
|
23
|
-
): React.ForwardRefExoticComponent<{
|
|
22
|
+
): React.ForwardRefExoticComponent<{|
|
|
24
23
|
...React.PropsWithoutRef<WithoutActionScheduler<Props>>,
|
|
25
24
|
...React.RefAttributes<mixed>,
|
|
26
|
-
}>;
|
|
25
|
+
|}>;
|
package/dist/es/index.js
CHANGED
|
@@ -10,66 +10,8 @@ const ClearPolicy = {
|
|
|
10
10
|
Cancel: "cancel-on-clear"
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
o.__proto__ = p;
|
|
16
|
-
return o;
|
|
17
|
-
};
|
|
18
|
-
return _setPrototypeOf(o, p);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _inheritsLoose(subClass, superClass) {
|
|
22
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
23
|
-
subClass.prototype.constructor = subClass;
|
|
24
|
-
_setPrototypeOf(subClass, superClass);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function _typeof(obj) {
|
|
28
|
-
"@babel/helpers - typeof";
|
|
29
|
-
|
|
30
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
31
|
-
return typeof obj;
|
|
32
|
-
} : function (obj) {
|
|
33
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
34
|
-
}, _typeof(obj);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function _toPrimitive(input, hint) {
|
|
38
|
-
if (_typeof(input) !== "object" || input === null) return input;
|
|
39
|
-
var prim = input[Symbol.toPrimitive];
|
|
40
|
-
if (prim !== undefined) {
|
|
41
|
-
var res = prim.call(input, hint || "default");
|
|
42
|
-
if (_typeof(res) !== "object") return res;
|
|
43
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
44
|
-
}
|
|
45
|
-
return (hint === "string" ? String : Number)(input);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _toPropertyKey(arg) {
|
|
49
|
-
var key = _toPrimitive(arg, "string");
|
|
50
|
-
return _typeof(key) === "symbol" ? key : String(key);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function _defineProperties(target, props) {
|
|
54
|
-
for (var i = 0; i < props.length; i++) {
|
|
55
|
-
var descriptor = props[i];
|
|
56
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
57
|
-
descriptor.configurable = true;
|
|
58
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
59
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
63
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
64
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
65
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
66
|
-
writable: false
|
|
67
|
-
});
|
|
68
|
-
return Constructor;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let Timeout = function () {
|
|
72
|
-
function Timeout(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
13
|
+
class Timeout {
|
|
14
|
+
constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
73
15
|
this._timeoutId = void 0;
|
|
74
16
|
this._action = void 0;
|
|
75
17
|
this._timeoutMs = void 0;
|
|
@@ -85,14 +27,16 @@ let Timeout = function () {
|
|
|
85
27
|
this.set();
|
|
86
28
|
}
|
|
87
29
|
}
|
|
88
|
-
|
|
89
|
-
|
|
30
|
+
get isSet() {
|
|
31
|
+
return this._timeoutId != null;
|
|
32
|
+
}
|
|
33
|
+
set() {
|
|
90
34
|
if (this.isSet) {
|
|
91
35
|
this.clear(ClearPolicy.Cancel);
|
|
92
36
|
}
|
|
93
37
|
this._timeoutId = setTimeout(() => this.clear(ClearPolicy.Resolve), this._timeoutMs);
|
|
94
|
-
}
|
|
95
|
-
|
|
38
|
+
}
|
|
39
|
+
clear(policy = ClearPolicy.Cancel) {
|
|
96
40
|
const timeoutId = this._timeoutId;
|
|
97
41
|
this._timeoutId = null;
|
|
98
42
|
if (timeoutId == null) {
|
|
@@ -102,18 +46,11 @@ let Timeout = function () {
|
|
|
102
46
|
if (policy === ClearPolicy.Resolve) {
|
|
103
47
|
this._action();
|
|
104
48
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
key: "isSet",
|
|
108
|
-
get: function () {
|
|
109
|
-
return this._timeoutId != null;
|
|
110
|
-
}
|
|
111
|
-
}]);
|
|
112
|
-
return Timeout;
|
|
113
|
-
}();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
114
51
|
|
|
115
|
-
|
|
116
|
-
|
|
52
|
+
class Interval {
|
|
53
|
+
constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
117
54
|
this._intervalId = void 0;
|
|
118
55
|
this._action = void 0;
|
|
119
56
|
this._intervalMs = void 0;
|
|
@@ -129,14 +66,16 @@ let Interval = function () {
|
|
|
129
66
|
this.set();
|
|
130
67
|
}
|
|
131
68
|
}
|
|
132
|
-
|
|
133
|
-
|
|
69
|
+
get isSet() {
|
|
70
|
+
return this._intervalId != null;
|
|
71
|
+
}
|
|
72
|
+
set() {
|
|
134
73
|
if (this.isSet) {
|
|
135
74
|
this.clear(ClearPolicy.Cancel);
|
|
136
75
|
}
|
|
137
76
|
this._intervalId = setInterval(() => this._action(), this._intervalMs);
|
|
138
|
-
}
|
|
139
|
-
|
|
77
|
+
}
|
|
78
|
+
clear(policy = ClearPolicy.Cancel) {
|
|
140
79
|
const intervalId = this._intervalId;
|
|
141
80
|
this._intervalId = null;
|
|
142
81
|
if (intervalId == null) {
|
|
@@ -146,18 +85,11 @@ let Interval = function () {
|
|
|
146
85
|
if (policy === ClearPolicy.Resolve) {
|
|
147
86
|
this._action();
|
|
148
87
|
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
key: "isSet",
|
|
152
|
-
get: function () {
|
|
153
|
-
return this._intervalId != null;
|
|
154
|
-
}
|
|
155
|
-
}]);
|
|
156
|
-
return Interval;
|
|
157
|
-
}();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
158
90
|
|
|
159
|
-
|
|
160
|
-
|
|
91
|
+
class AnimationFrame {
|
|
92
|
+
constructor(action, schedulePolicy = SchedulePolicy.Immediately) {
|
|
161
93
|
this._animationFrameId = void 0;
|
|
162
94
|
this._action = void 0;
|
|
163
95
|
if (typeof action !== "function") {
|
|
@@ -168,14 +100,16 @@ let AnimationFrame = function () {
|
|
|
168
100
|
this.set();
|
|
169
101
|
}
|
|
170
102
|
}
|
|
171
|
-
|
|
172
|
-
|
|
103
|
+
get isSet() {
|
|
104
|
+
return this._animationFrameId != null;
|
|
105
|
+
}
|
|
106
|
+
set() {
|
|
173
107
|
if (this.isSet) {
|
|
174
108
|
this.clear(ClearPolicy.Cancel);
|
|
175
109
|
}
|
|
176
110
|
this._animationFrameId = requestAnimationFrame(time => this.clear(ClearPolicy.Resolve, time));
|
|
177
|
-
}
|
|
178
|
-
|
|
111
|
+
}
|
|
112
|
+
clear(policy = ClearPolicy.Cancel, time) {
|
|
179
113
|
const animationFrameId = this._animationFrameId;
|
|
180
114
|
this._animationFrameId = null;
|
|
181
115
|
if (animationFrameId == null) {
|
|
@@ -185,57 +119,48 @@ let AnimationFrame = function () {
|
|
|
185
119
|
if (policy === ClearPolicy.Resolve) {
|
|
186
120
|
this._action(time || performance.now());
|
|
187
121
|
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
key: "isSet",
|
|
191
|
-
get: function () {
|
|
192
|
-
return this._animationFrameId != null;
|
|
193
|
-
}
|
|
194
|
-
}]);
|
|
195
|
-
return AnimationFrame;
|
|
196
|
-
}();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
197
124
|
|
|
198
|
-
|
|
199
|
-
|
|
125
|
+
class ActionScheduler {
|
|
126
|
+
constructor() {
|
|
200
127
|
this._disabled = false;
|
|
201
128
|
this._registeredActions = [];
|
|
202
129
|
}
|
|
203
|
-
|
|
204
|
-
_proto.timeout = function timeout(action, period, options) {
|
|
130
|
+
timeout(action, period, options) {
|
|
205
131
|
if (this._disabled) {
|
|
206
132
|
return ActionScheduler.NoopAction;
|
|
207
133
|
}
|
|
208
134
|
const timeout = new Timeout(action, period, options == null ? void 0 : options.schedulePolicy);
|
|
209
135
|
this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
|
|
210
136
|
return timeout;
|
|
211
|
-
}
|
|
212
|
-
|
|
137
|
+
}
|
|
138
|
+
interval(action, period, options) {
|
|
213
139
|
if (this._disabled) {
|
|
214
140
|
return ActionScheduler.NoopAction;
|
|
215
141
|
}
|
|
216
142
|
const interval = new Interval(action, period, options == null ? void 0 : options.schedulePolicy);
|
|
217
143
|
this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
|
|
218
144
|
return interval;
|
|
219
|
-
}
|
|
220
|
-
|
|
145
|
+
}
|
|
146
|
+
animationFrame(action, options) {
|
|
221
147
|
if (this._disabled) {
|
|
222
148
|
return ActionScheduler.NoopAction;
|
|
223
149
|
}
|
|
224
150
|
const animationFrame = new AnimationFrame(action, options == null ? void 0 : options.schedulePolicy);
|
|
225
151
|
this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
|
|
226
152
|
return animationFrame;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const registered = [
|
|
153
|
+
}
|
|
154
|
+
clearAll() {
|
|
155
|
+
const registered = [...this._registeredActions];
|
|
230
156
|
this._registeredActions = [];
|
|
231
157
|
registered.forEach(clearFn => clearFn());
|
|
232
|
-
}
|
|
233
|
-
|
|
158
|
+
}
|
|
159
|
+
disable() {
|
|
234
160
|
this._disabled = true;
|
|
235
161
|
this.clearAll();
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
}();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
239
164
|
ActionScheduler.NoopAction = {
|
|
240
165
|
set: () => {},
|
|
241
166
|
get isSet() {
|
|
@@ -244,26 +169,21 @@ ActionScheduler.NoopAction = {
|
|
|
244
169
|
clear: () => {}
|
|
245
170
|
};
|
|
246
171
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
252
|
-
_this._actionScheduler = new ActionScheduler();
|
|
253
|
-
return _this;
|
|
172
|
+
class ActionSchedulerProvider extends React.Component {
|
|
173
|
+
constructor(...args) {
|
|
174
|
+
super(...args);
|
|
175
|
+
this._actionScheduler = new ActionScheduler();
|
|
254
176
|
}
|
|
255
|
-
|
|
256
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
177
|
+
componentWillUnmount() {
|
|
257
178
|
this._actionScheduler.disable();
|
|
258
|
-
}
|
|
259
|
-
|
|
179
|
+
}
|
|
180
|
+
render() {
|
|
260
181
|
const {
|
|
261
182
|
children
|
|
262
183
|
} = this.props;
|
|
263
184
|
return children(this._actionScheduler);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
}(React.Component);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
267
187
|
|
|
268
188
|
function _extends() {
|
|
269
189
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns a ref whose .current value is updated whenever
|
|
10
9
|
* the `value` passed to this hook changes.
|
|
@@ -12,11 +11,10 @@
|
|
|
12
11
|
* this is great for values that you want to reference from
|
|
13
12
|
* within a useCallback or useEffect event listener, without
|
|
14
13
|
* re-triggering the effect when the value changes
|
|
15
|
-
* @returns {{
|
|
16
|
-
current: T
|
|
17
|
-
}}
|
|
14
|
+
* @returns {{|
|
|
15
|
+
current: T,
|
|
16
|
+
|}}
|
|
18
17
|
*/
|
|
19
|
-
declare export var useUpdatingRef: <T>(value: T) => {
|
|
18
|
+
declare export var useUpdatingRef: <T>(value: T) => {|
|
|
20
19
|
current: T,
|
|
21
|
-
|
|
22
|
-
};
|
|
20
|
+
|};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* A simple hook for using `setInterval`.
|
|
10
9
|
* @param action called every `intervalMs` when `active` is true
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import type { IInterval, Options } from "../util/types";
|
|
9
8
|
declare export function useScheduledInterval(
|
|
10
9
|
action: () => mixed,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import type { ITimeout, Options } from "../util/types";
|
|
9
8
|
declare export function useScheduledTimeout(
|
|
10
9
|
action: () => mixed,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* A simple hook for using `setTimeout`.
|
|
10
9
|
* @param action called after `timeoutMs` when `active` is true
|