@khanacademy/wonder-blocks-timing 3.0.1 → 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 +6 -0
- package/dist/components/action-scheduler-provider.js.flow +1 -2
- package/dist/components/with-action-scheduler.js.flow +2 -3
- package/dist/es/index.js +53 -133
- package/dist/hooks/internal/use-updating-ref.js.flow +1 -2
- 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 +1 -2
- package/dist/util/animation-frame.js.flow +1 -2
- package/dist/util/interval.js.flow +1 -2
- package/dist/util/policies.js.flow +1 -2
- package/dist/util/timeout.js.flow +1 -2
- package/dist/util/types.js.flow +1 -2
- package/dist/util/types.typestest.js.flow +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -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 ActionScheduler from "../util/action-scheduler";
|
|
10
9
|
import type { IScheduleActions } from "../util/types";
|
|
@@ -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 }>;
|
|
@@ -19,7 +18,7 @@ declare type WithoutActionScheduler<T> = $Diff<T, { schedule: any }>;
|
|
|
19
18
|
declare export default function withActionScheduler<
|
|
20
19
|
Props: WithActionSchedulerProps
|
|
21
20
|
>(
|
|
22
|
-
WrappedComponent: React.
|
|
21
|
+
WrappedComponent: React.ComponentType<Props>
|
|
23
22
|
): React.ForwardRefExoticComponent<{|
|
|
24
23
|
...React.PropsWithoutRef<WithoutActionScheduler<Props>>,
|
|
25
24
|
...React.RefAttributes<mixed>,
|
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.
|
|
@@ -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
|
package/dist/index.js
CHANGED
|
@@ -33,66 +33,8 @@ const ClearPolicy = {
|
|
|
33
33
|
Cancel: "cancel-on-clear"
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
o.__proto__ = p;
|
|
39
|
-
return o;
|
|
40
|
-
};
|
|
41
|
-
return _setPrototypeOf(o, p);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function _inheritsLoose(subClass, superClass) {
|
|
45
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
46
|
-
subClass.prototype.constructor = subClass;
|
|
47
|
-
_setPrototypeOf(subClass, superClass);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function _typeof(obj) {
|
|
51
|
-
"@babel/helpers - typeof";
|
|
52
|
-
|
|
53
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
54
|
-
return typeof obj;
|
|
55
|
-
} : function (obj) {
|
|
56
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
57
|
-
}, _typeof(obj);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function _toPrimitive(input, hint) {
|
|
61
|
-
if (_typeof(input) !== "object" || input === null) return input;
|
|
62
|
-
var prim = input[Symbol.toPrimitive];
|
|
63
|
-
if (prim !== undefined) {
|
|
64
|
-
var res = prim.call(input, hint || "default");
|
|
65
|
-
if (_typeof(res) !== "object") return res;
|
|
66
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
67
|
-
}
|
|
68
|
-
return (hint === "string" ? String : Number)(input);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function _toPropertyKey(arg) {
|
|
72
|
-
var key = _toPrimitive(arg, "string");
|
|
73
|
-
return _typeof(key) === "symbol" ? key : String(key);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function _defineProperties(target, props) {
|
|
77
|
-
for (var i = 0; i < props.length; i++) {
|
|
78
|
-
var descriptor = props[i];
|
|
79
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
80
|
-
descriptor.configurable = true;
|
|
81
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
82
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
86
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
87
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
88
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
89
|
-
writable: false
|
|
90
|
-
});
|
|
91
|
-
return Constructor;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let Timeout = function () {
|
|
95
|
-
function Timeout(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
36
|
+
class Timeout {
|
|
37
|
+
constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
96
38
|
this._timeoutId = void 0;
|
|
97
39
|
this._action = void 0;
|
|
98
40
|
this._timeoutMs = void 0;
|
|
@@ -108,14 +50,16 @@ let Timeout = function () {
|
|
|
108
50
|
this.set();
|
|
109
51
|
}
|
|
110
52
|
}
|
|
111
|
-
|
|
112
|
-
|
|
53
|
+
get isSet() {
|
|
54
|
+
return this._timeoutId != null;
|
|
55
|
+
}
|
|
56
|
+
set() {
|
|
113
57
|
if (this.isSet) {
|
|
114
58
|
this.clear(ClearPolicy.Cancel);
|
|
115
59
|
}
|
|
116
60
|
this._timeoutId = setTimeout(() => this.clear(ClearPolicy.Resolve), this._timeoutMs);
|
|
117
|
-
}
|
|
118
|
-
|
|
61
|
+
}
|
|
62
|
+
clear(policy = ClearPolicy.Cancel) {
|
|
119
63
|
const timeoutId = this._timeoutId;
|
|
120
64
|
this._timeoutId = null;
|
|
121
65
|
if (timeoutId == null) {
|
|
@@ -125,18 +69,11 @@ let Timeout = function () {
|
|
|
125
69
|
if (policy === ClearPolicy.Resolve) {
|
|
126
70
|
this._action();
|
|
127
71
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
key: "isSet",
|
|
131
|
-
get: function () {
|
|
132
|
-
return this._timeoutId != null;
|
|
133
|
-
}
|
|
134
|
-
}]);
|
|
135
|
-
return Timeout;
|
|
136
|
-
}();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
137
74
|
|
|
138
|
-
|
|
139
|
-
|
|
75
|
+
class Interval {
|
|
76
|
+
constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) {
|
|
140
77
|
this._intervalId = void 0;
|
|
141
78
|
this._action = void 0;
|
|
142
79
|
this._intervalMs = void 0;
|
|
@@ -152,14 +89,16 @@ let Interval = function () {
|
|
|
152
89
|
this.set();
|
|
153
90
|
}
|
|
154
91
|
}
|
|
155
|
-
|
|
156
|
-
|
|
92
|
+
get isSet() {
|
|
93
|
+
return this._intervalId != null;
|
|
94
|
+
}
|
|
95
|
+
set() {
|
|
157
96
|
if (this.isSet) {
|
|
158
97
|
this.clear(ClearPolicy.Cancel);
|
|
159
98
|
}
|
|
160
99
|
this._intervalId = setInterval(() => this._action(), this._intervalMs);
|
|
161
|
-
}
|
|
162
|
-
|
|
100
|
+
}
|
|
101
|
+
clear(policy = ClearPolicy.Cancel) {
|
|
163
102
|
const intervalId = this._intervalId;
|
|
164
103
|
this._intervalId = null;
|
|
165
104
|
if (intervalId == null) {
|
|
@@ -169,18 +108,11 @@ let Interval = function () {
|
|
|
169
108
|
if (policy === ClearPolicy.Resolve) {
|
|
170
109
|
this._action();
|
|
171
110
|
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
key: "isSet",
|
|
175
|
-
get: function () {
|
|
176
|
-
return this._intervalId != null;
|
|
177
|
-
}
|
|
178
|
-
}]);
|
|
179
|
-
return Interval;
|
|
180
|
-
}();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
181
113
|
|
|
182
|
-
|
|
183
|
-
|
|
114
|
+
class AnimationFrame {
|
|
115
|
+
constructor(action, schedulePolicy = SchedulePolicy.Immediately) {
|
|
184
116
|
this._animationFrameId = void 0;
|
|
185
117
|
this._action = void 0;
|
|
186
118
|
if (typeof action !== "function") {
|
|
@@ -191,14 +123,16 @@ let AnimationFrame = function () {
|
|
|
191
123
|
this.set();
|
|
192
124
|
}
|
|
193
125
|
}
|
|
194
|
-
|
|
195
|
-
|
|
126
|
+
get isSet() {
|
|
127
|
+
return this._animationFrameId != null;
|
|
128
|
+
}
|
|
129
|
+
set() {
|
|
196
130
|
if (this.isSet) {
|
|
197
131
|
this.clear(ClearPolicy.Cancel);
|
|
198
132
|
}
|
|
199
133
|
this._animationFrameId = requestAnimationFrame(time => this.clear(ClearPolicy.Resolve, time));
|
|
200
|
-
}
|
|
201
|
-
|
|
134
|
+
}
|
|
135
|
+
clear(policy = ClearPolicy.Cancel, time) {
|
|
202
136
|
const animationFrameId = this._animationFrameId;
|
|
203
137
|
this._animationFrameId = null;
|
|
204
138
|
if (animationFrameId == null) {
|
|
@@ -208,57 +142,48 @@ let AnimationFrame = function () {
|
|
|
208
142
|
if (policy === ClearPolicy.Resolve) {
|
|
209
143
|
this._action(time || performance.now());
|
|
210
144
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
key: "isSet",
|
|
214
|
-
get: function () {
|
|
215
|
-
return this._animationFrameId != null;
|
|
216
|
-
}
|
|
217
|
-
}]);
|
|
218
|
-
return AnimationFrame;
|
|
219
|
-
}();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
220
147
|
|
|
221
|
-
|
|
222
|
-
|
|
148
|
+
class ActionScheduler {
|
|
149
|
+
constructor() {
|
|
223
150
|
this._disabled = false;
|
|
224
151
|
this._registeredActions = [];
|
|
225
152
|
}
|
|
226
|
-
|
|
227
|
-
_proto.timeout = function timeout(action, period, options) {
|
|
153
|
+
timeout(action, period, options) {
|
|
228
154
|
if (this._disabled) {
|
|
229
155
|
return ActionScheduler.NoopAction;
|
|
230
156
|
}
|
|
231
157
|
const timeout = new Timeout(action, period, options == null ? void 0 : options.schedulePolicy);
|
|
232
158
|
this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy));
|
|
233
159
|
return timeout;
|
|
234
|
-
}
|
|
235
|
-
|
|
160
|
+
}
|
|
161
|
+
interval(action, period, options) {
|
|
236
162
|
if (this._disabled) {
|
|
237
163
|
return ActionScheduler.NoopAction;
|
|
238
164
|
}
|
|
239
165
|
const interval = new Interval(action, period, options == null ? void 0 : options.schedulePolicy);
|
|
240
166
|
this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy));
|
|
241
167
|
return interval;
|
|
242
|
-
}
|
|
243
|
-
|
|
168
|
+
}
|
|
169
|
+
animationFrame(action, options) {
|
|
244
170
|
if (this._disabled) {
|
|
245
171
|
return ActionScheduler.NoopAction;
|
|
246
172
|
}
|
|
247
173
|
const animationFrame = new AnimationFrame(action, options == null ? void 0 : options.schedulePolicy);
|
|
248
174
|
this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy));
|
|
249
175
|
return animationFrame;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const registered = [
|
|
176
|
+
}
|
|
177
|
+
clearAll() {
|
|
178
|
+
const registered = [...this._registeredActions];
|
|
253
179
|
this._registeredActions = [];
|
|
254
180
|
registered.forEach(clearFn => clearFn());
|
|
255
|
-
}
|
|
256
|
-
|
|
181
|
+
}
|
|
182
|
+
disable() {
|
|
257
183
|
this._disabled = true;
|
|
258
184
|
this.clearAll();
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
}();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
262
187
|
ActionScheduler.NoopAction = {
|
|
263
188
|
set: () => {},
|
|
264
189
|
get isSet() {
|
|
@@ -267,26 +192,21 @@ ActionScheduler.NoopAction = {
|
|
|
267
192
|
clear: () => {}
|
|
268
193
|
};
|
|
269
194
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
275
|
-
_this._actionScheduler = new ActionScheduler();
|
|
276
|
-
return _this;
|
|
195
|
+
class ActionSchedulerProvider extends React__namespace.Component {
|
|
196
|
+
constructor(...args) {
|
|
197
|
+
super(...args);
|
|
198
|
+
this._actionScheduler = new ActionScheduler();
|
|
277
199
|
}
|
|
278
|
-
|
|
279
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
200
|
+
componentWillUnmount() {
|
|
280
201
|
this._actionScheduler.disable();
|
|
281
|
-
}
|
|
282
|
-
|
|
202
|
+
}
|
|
203
|
+
render() {
|
|
283
204
|
const {
|
|
284
205
|
children
|
|
285
206
|
} = this.props;
|
|
286
207
|
return children(this._actionScheduler);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
}(React__namespace.Component);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
290
210
|
|
|
291
211
|
function _extends() {
|
|
292
212
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
package/dist/index.js.flow
CHANGED
|
@@ -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 { IAnimationFrame, SchedulePolicy, ClearPolicy } from "./types";
|
|
9
8
|
|
|
10
9
|
/**
|
|
@@ -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
|
declare export var SchedulePolicy: {|
|
|
9
8
|
+Immediately: "schedule-immediately",
|
|
10
9
|
+OnDemand: "schedule-on-demand",
|
package/dist/util/types.js.flow
CHANGED
|
@@ -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
|
export type SchedulePolicy = "schedule-immediately" | "schedule-on-demand";
|
|
9
8
|
export type ClearPolicy = "resolve-on-clear" | "cancel-on-clear";
|
|
10
9
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-timing",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.2",
|
|
5
5
|
"design": "v1",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"react": "16.14.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"wb-dev-build-settings": "^0.9.
|
|
20
|
+
"wb-dev-build-settings": "^0.9.5"
|
|
21
21
|
},
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "MIT"
|