@khanacademy/wonder-blocks-timing
Advanced tools
Comparing version 2.1.0 to 2.1.1
# @khanacademy/wonder-blocks-timing | ||
## 2.1.1 | ||
### Patch Changes | ||
- 91cb727c: Remove file extensions from imports | ||
## 2.1.0 | ||
### Minor Changes | ||
- 029b4810: Adds `useInterval()` hook that mimics the behavior of `ActionScheduler`'s | ||
`interval()` method. | ||
- c57cd770: Rename `useInterval` and `useTimeout` to `useScheduledInterval` | ||
and `useScheduledTimeout` respectively. | ||
- 29766c8e: Add `useInterval` and `useTimeout` hooks to provide a simple API for | ||
using intervals and timeouts. | ||
- 029b4810: Adds `useInterval()` hook that mimics the behavior of `ActionScheduler`'s | ||
`interval()` method. | ||
- c57cd770: Rename `useInterval` and `useTimeout` to `useScheduledInterval` | ||
and `useScheduledTimeout` respectively. | ||
- 29766c8e: Add `useInterval` and `useTimeout` hooks to provide an API for | ||
using intervals and timeouts. |
@@ -14,25 +14,3 @@ import _extends from '@babel/runtime/helpers/extends'; | ||
/** | ||
* Encapsulates everything associated with calling setTimeout/clearTimeout, and | ||
* managing the lifecycle of that timer, including the ability to resolve or | ||
* cancel a pending timeout action. | ||
* | ||
* @export | ||
* @class Timeout | ||
* @implements {ITimeout} | ||
*/ | ||
class Timeout { | ||
/** | ||
* Creates a timeout that will invoke the given action after | ||
* the given period. The timeout does not start until set is called. | ||
* | ||
* @param {() => mixed} action The action to be invoked when the timeout | ||
* period has passed. | ||
* @param {number} timeoutMs The timeout period. | ||
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately, | ||
* the timer is set immediately on instantiation; otherwise, `set` must be | ||
* called to set the timeout. | ||
* Defaults to `SchedulePolicy.Immediately`. | ||
* @memberof Timeout | ||
*/ | ||
constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) { | ||
@@ -54,25 +32,7 @@ if (typeof action !== "function") { | ||
} | ||
/** | ||
* Determine if the timeout is set or not. | ||
* | ||
* @returns {boolean} true if the timeout is set (aka pending), otherwise | ||
* false. | ||
* @memberof Timeout | ||
*/ | ||
get isSet() { | ||
return this._timeoutId != null; | ||
} | ||
/** | ||
* Set the timeout. | ||
* | ||
* If the timeout is pending, this cancels that pending timeout and | ||
* sets the timeout afresh. If the timeout is not pending, this | ||
* sets a new timeout. | ||
* | ||
* @memberof Timeout | ||
*/ | ||
set() { | ||
@@ -85,18 +45,3 @@ if (this.isSet) { | ||
} | ||
/** | ||
* Clear the set timeout. | ||
* | ||
* If the timeout is pending, this cancels that pending timeout without | ||
* invoking the action. If no timeout is pending, this does nothing. | ||
* | ||
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request | ||
* was set when called, the request action is invoked after cancelling | ||
* the request; otherwise, the pending action is cancelled. | ||
* Defaults to `ClearPolicy.Cancel`. | ||
* | ||
* @returns {void} | ||
* @memberof Timeout | ||
*/ | ||
clear(policy = ClearPolicy.Cancel) { | ||
@@ -119,25 +64,3 @@ const timeoutId = this._timeoutId; | ||
/** | ||
* Encapsulates everything associated with calling setInterval/clearInterval, | ||
* and managing the lifecycle of that interval. This includes the ability to | ||
* cancel the interval, and knowing if the interval is active. | ||
* | ||
* @export | ||
* @class Interval | ||
* @implements {IInterval} | ||
*/ | ||
class Interval { | ||
/** | ||
* Creates an interval that will invoke the given action after | ||
* the given period. The interval does not start until set is called. | ||
* | ||
* @param {() => mixed} action The action to be invoked each time the | ||
* interval period has passed. | ||
* @param {number} intervalMs The interval period. | ||
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately, | ||
* the interval is set immediately on instantiation; otherwise, `set` must be | ||
* called to set the interval. | ||
* Defaults to `SchedulePolicy.Immediately`. | ||
* @memberof Interval | ||
*/ | ||
constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) { | ||
@@ -159,23 +82,7 @@ if (typeof action !== "function") { | ||
} | ||
/** | ||
* Determine if the interval is active or not. | ||
* | ||
* @returns {boolean} true if the interval is active, otherwise false. | ||
* @memberof Interval | ||
*/ | ||
get isSet() { | ||
return this._intervalId != null; | ||
} | ||
/** | ||
* Activate the interval. | ||
* | ||
* If the interval is active, this cancels that interval and starts the | ||
* interval afresh. If the interval is not active, this starts it. | ||
* | ||
* @memberof Interval | ||
*/ | ||
set() { | ||
@@ -188,18 +95,3 @@ if (this.isSet) { | ||
} | ||
/** | ||
* Clear the active interval. | ||
* | ||
* If the interval is active, this cancels that interval. If no interval is | ||
* pending, this does nothing. | ||
* | ||
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request | ||
* was set when called, the request action is invoked after cancelling | ||
* the request; otherwise, the pending action is cancelled. | ||
* Defaults to `ClearPolicy.Cancel`. | ||
* | ||
* @returns {void} | ||
* @memberof Interval | ||
*/ | ||
clear(policy = ClearPolicy.Cancel) { | ||
@@ -222,23 +114,3 @@ const intervalId = this._intervalId; | ||
/** | ||
* Encapsulates everything associated with calling requestAnimationFrame/ | ||
* cancelAnimationFrame, and managing the lifecycle of that request, including | ||
* the ability to resolve or cancel a pending request action. | ||
* | ||
* @export | ||
* @class AnimationFrame | ||
* @implements {IAnimationFrame} | ||
*/ | ||
class AnimationFrame { | ||
/** | ||
* Creates an animation frame request that will invoke the given action. | ||
* The request is not made until set is called. | ||
* | ||
* @param {DOMHighResTimeStamp => mixed} action The action to be invoked. | ||
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately, | ||
* the interval is set immediately on instantiation; otherwise, `set` must be | ||
* called to set the interval. | ||
* Defaults to `SchedulePolicy.Immediately`. | ||
* @memberof AnimationFrame | ||
*/ | ||
constructor(action, schedulePolicy = SchedulePolicy.Immediately) { | ||
@@ -255,25 +127,7 @@ if (typeof action !== "function") { | ||
} | ||
/** | ||
* Determine if the request is pending or not. | ||
* | ||
* @returns {boolean} true if the request is pending, otherwise | ||
* false. | ||
* @memberof AnimationFrame | ||
*/ | ||
get isSet() { | ||
return this._animationFrameId != null; | ||
} | ||
/** | ||
* Make the animation frame request. | ||
* | ||
* If the request is pending, this cancels that pending request and | ||
* makes the request afresh. If the request is not pending, this | ||
* makes a new request. | ||
* | ||
* @memberof AnimationFrame | ||
*/ | ||
set() { | ||
@@ -286,21 +140,3 @@ if (this.isSet) { | ||
} | ||
/** | ||
* Clear the pending request. | ||
* | ||
* If the request is pending, this cancels that pending request without | ||
* invoking the action. If no request is pending, this does nothing. | ||
* | ||
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request | ||
* was set when called, the request action is invoked after cancelling | ||
* the request; otherwise, the pending action is cancelled. | ||
* Defaults to `ClearPolicy.Cancel`. | ||
* @param {DOMHighResTimeStamp} [time] Timestamp to pass to the action when | ||
* ClearPolicy.Resolve is specified. Ignored when ClearPolicy.Cancel is | ||
* specified. | ||
* | ||
* @returns {void} | ||
* @memberof AnimationFrame | ||
*/ | ||
clear(policy = ClearPolicy.Cancel, time) { | ||
@@ -323,8 +159,2 @@ const animationFrameId = this._animationFrameId; | ||
/** | ||
* Implements the `IScheduleActions` API to provide timeout, interval, and | ||
* animation frame support. This is not intended for direct use, but instead | ||
* is to be used solely by the `ActionSchedulerProvider` to provide an | ||
* `IScheduleActions` instance. | ||
*/ | ||
class ActionScheduler { | ||
@@ -377,8 +207,3 @@ constructor() { | ||
} | ||
/** | ||
* Prevents this scheduler from creating any additional actions. | ||
* This also clears any pending actions. | ||
*/ | ||
disable() { | ||
@@ -400,12 +225,2 @@ this._disabled = true; | ||
/** | ||
* A provider component that passes our action scheduling API to its children | ||
* and ensures that all scheduled actions are cleared on unmount. | ||
* | ||
* ```jsx | ||
* <ActionSchedulerProvider> | ||
* {schedule => this.renderThingThatNeedsTimers(schedule)} | ||
* </ActionSchedulerProvider> | ||
* ``` | ||
*/ | ||
class ActionSchedulerProvider extends React.Component { | ||
@@ -430,13 +245,4 @@ constructor(...args) { | ||
/** | ||
* A higher order component that attaches the given component to an | ||
* `IScheduleActions` instance. Any actions scheduled will automatically be | ||
* cleared on unmount. | ||
* | ||
* @template TOwnProps The own props of the component being rendered, without | ||
* the additional action scheduler prop. To attach the additional prop to | ||
* these props use the `WithActionScheduler` type. | ||
*/ | ||
function withActionScheduler(WrappedComponent) { | ||
return /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement(ActionSchedulerProvider, null, schedule => /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, { | ||
return React.forwardRef((props, ref) => React.createElement(ActionSchedulerProvider, null, schedule => React.createElement(WrappedComponent, _extends({}, props, { | ||
ref: ref, | ||
@@ -447,13 +253,2 @@ schedule: schedule | ||
/** | ||
* Returns a ref whose .current value is updated whenever | ||
* the `value` passed to this hook changes. | ||
* | ||
* this is great for values that you want to reference from | ||
* within a useCallback or useEffect event listener, without | ||
* re-triggering the effect when the value changes | ||
* | ||
* @returns {{current: T}} | ||
*/ | ||
const useUpdatingRef = value => { | ||
@@ -467,13 +262,3 @@ const ref = useRef(value); | ||
/** | ||
* A simple hook for using `setInterval`. | ||
* | ||
* @param action called every `intervalMs` when `active` is true | ||
* @param intervalMs the duration between calls to `action` | ||
* @param active whether or not the interval is active | ||
*/ | ||
function useInterval(action, intervalMs, active) { | ||
// We using a ref instead of a callback for `action` to avoid resetting | ||
// the interval whenever the `action` changes. | ||
const actionRef = useUpdatingRef(action); | ||
@@ -488,21 +273,7 @@ useEffect(() => { | ||
}; | ||
} // actionRef isn't actually required, but react-hooks/exhaustive-deps | ||
// doesn't recognize it as a ref and thus complains if it isn't in the | ||
// deps list. It isn't a big deal though since the value ofactionRef | ||
// never changes (only its contents do). | ||
} | ||
}, [intervalMs, active, actionRef]); | ||
} | ||
/** | ||
* A simple hook for using `setTimeout`. | ||
* | ||
* @param action called after `timeoutMs` when `active` is true | ||
* @param timeoutMs the duration after which `action` is called | ||
* @param active whether or not the interval is active | ||
*/ | ||
function useTimeout(action, timeoutMs, active) { | ||
// We using a ref instead of a callback for `action` to avoid resetting | ||
// the interval whenever the `action` changes. | ||
const actionRef = useUpdatingRef(action); | ||
@@ -517,7 +288,3 @@ useEffect(() => { | ||
}; | ||
} // actionRef isn't actually required, but react-hooks/exhaustive-deps | ||
// doesn't recognize it as a ref and thus complains if it isn't in the | ||
// deps list. It isn't a big deal though since the value ofactionRef | ||
// never changes (only its contents do). | ||
} | ||
}, [timeoutMs, active, actionRef]); | ||
@@ -551,19 +318,10 @@ } | ||
setIsSet(false); | ||
}, // react-hooks/exhaustive-deps doesn't require refs to be | ||
// listed in the deps array. Unfortunately, in this situation | ||
// it doesn't recognized actionRef as a ref. | ||
[actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
}, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve); | ||
useEffect(() => { | ||
return () => { | ||
// This code will only run with the component using this | ||
// hook is unmounted. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
if (runOnUnmountRef.current) { | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
actionRef.current(); | ||
} | ||
}; // This eslint rule doesn't realize actionRef and runOnUnmountRef | ||
// a both refs and thus do not have to be listed as deps. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}; | ||
}, []); | ||
@@ -591,5 +349,3 @@ useInterval(action, intervalMs, isSet); | ||
const [isSet, setIsSet] = useState(schedulePolicy === SchedulePolicy.Immediately); | ||
const set = useCallback(() => setIsSet(true), []); // This wrapper isn't present in useScheduledInterval because we | ||
// don't need to update `isSet` in that situations. | ||
const set = useCallback(() => setIsSet(true), []); | ||
const wrappedAction = useCallback(() => { | ||
@@ -610,19 +366,10 @@ setIsSet(false); | ||
setIsSet(false); | ||
}, // react-hooks/exhaustive-deps doesn't require refs to be | ||
// listed in the deps array. Unfortunately, in this situation | ||
// it doesn't recognized actionRef as a ref. | ||
[actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
}, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve); | ||
useEffect(() => { | ||
return () => { | ||
// This code will only run with the component using this | ||
// hook is unmounted. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
if (runOnUnmountRef.current) { | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
actionRef.current(); | ||
} | ||
}; // This eslint rule doesn't realize actionRef and runOnUnmountRef | ||
// a both refs and thus do not have to be listed as deps. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}; | ||
}, []); | ||
@@ -629,0 +376,0 @@ useTimeout(wrappedAction, timeoutMs, isSet); |
@@ -1,95 +0,31 @@ | ||
module.exports = | ||
/******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) { | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ i: moduleId, | ||
/******/ l: false, | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.l = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ | ||
/******/ // define getter function for harmony exports | ||
/******/ __webpack_require__.d = function(exports, name, getter) { | ||
/******/ if(!__webpack_require__.o(exports, name)) { | ||
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = function(exports) { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ | ||
/******/ // create a fake namespace object | ||
/******/ // mode & 1: value is a module id, require it | ||
/******/ // mode & 2: merge all properties of value into the ns | ||
/******/ // mode & 4: return value when already ns object | ||
/******/ // mode & 8|1: behave like require | ||
/******/ __webpack_require__.t = function(value, mode) { | ||
/******/ if(mode & 1) value = __webpack_require__(value); | ||
/******/ if(mode & 8) return value; | ||
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||
/******/ var ns = Object.create(null); | ||
/******/ __webpack_require__.r(ns); | ||
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||
/******/ return ns; | ||
/******/ }; | ||
/******/ | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = function(module) { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ function getDefault() { return module['default']; } : | ||
/******/ function getModuleExports() { return module; }; | ||
/******/ __webpack_require__.d(getter, 'a', getter); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ | ||
/******/ // Object.prototype.hasOwnProperty.call | ||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||
/******/ | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ | ||
/******/ | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(__webpack_require__.s = 13); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
'use strict'; | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return SchedulePolicy; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ClearPolicy; }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _extends = require('@babel/runtime/helpers/extends'); | ||
var React = require('react'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { return e[k]; } | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends); | ||
var React__namespace = /*#__PURE__*/_interopNamespace(React); | ||
const SchedulePolicy = { | ||
@@ -104,342 +40,138 @@ Immediately: "schedule-immediately", | ||
/***/ }), | ||
/* 1 */ | ||
/***/ (function(module, exports) { | ||
class Timeout { | ||
constructor(action, timeoutMs, schedulePolicy = SchedulePolicy.Immediately) { | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
} | ||
module.exports = require("react"); | ||
if (timeoutMs < 0) { | ||
throw new Error("Timeout period must be >= 0"); | ||
} | ||
/***/ }), | ||
/* 2 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
this._action = action; | ||
this._timeoutMs = timeoutMs; | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useUpdatingRef; }); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
if (schedulePolicy === SchedulePolicy.Immediately) { | ||
this.set(); | ||
} | ||
} | ||
/** | ||
* Returns a ref whose .current value is updated whenever | ||
* the `value` passed to this hook changes. | ||
* | ||
* this is great for values that you want to reference from | ||
* within a useCallback or useEffect event listener, without | ||
* re-triggering the effect when the value changes | ||
* | ||
* @returns {{current: T}} | ||
*/ | ||
get isSet() { | ||
return this._timeoutId != null; | ||
} | ||
const useUpdatingRef = value => { | ||
const ref = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(value); | ||
Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref; | ||
}; | ||
set() { | ||
if (this.isSet) { | ||
this.clear(ClearPolicy.Cancel); | ||
} | ||
/***/ }), | ||
/* 3 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
this._timeoutId = setTimeout(() => this.clear(ClearPolicy.Resolve), this._timeoutMs); | ||
} | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useInterval; }); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); | ||
clear(policy = ClearPolicy.Cancel) { | ||
const timeoutId = this._timeoutId; | ||
this._timeoutId = null; | ||
if (timeoutId == null) { | ||
return; | ||
} | ||
/** | ||
* A simple hook for using `setInterval`. | ||
* | ||
* @param action called every `intervalMs` when `active` is true | ||
* @param intervalMs the duration between calls to `action` | ||
* @param active whether or not the interval is active | ||
*/ | ||
clearTimeout(timeoutId); | ||
function useInterval(action, intervalMs, active) { | ||
// We using a ref instead of a callback for `action` to avoid resetting | ||
// the interval whenever the `action` changes. | ||
const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__[/* useUpdatingRef */ "a"])(action); | ||
Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => { | ||
if (active) { | ||
const intervalId = setInterval(() => { | ||
actionRef.current(); | ||
}, intervalMs); | ||
return () => { | ||
clearInterval(intervalId); | ||
}; | ||
} // actionRef isn't actually required, but react-hooks/exhaustive-deps | ||
// doesn't recognize it as a ref and thus complains if it isn't in the | ||
// deps list. It isn't a big deal though since the value ofactionRef | ||
// never changes (only its contents do). | ||
if (policy === ClearPolicy.Resolve) { | ||
this._action(); | ||
} | ||
} | ||
}, [intervalMs, active, actionRef]); | ||
} | ||
/***/ }), | ||
/* 4 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
class Interval { | ||
constructor(action, intervalMs, schedulePolicy = SchedulePolicy.Immediately) { | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
} | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useTimeout; }); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2); | ||
if (intervalMs < 1) { | ||
throw new Error("Interval period must be >= 1"); | ||
} | ||
this._action = action; | ||
this._intervalMs = intervalMs; | ||
/** | ||
* A simple hook for using `setTimeout`. | ||
* | ||
* @param action called after `timeoutMs` when `active` is true | ||
* @param timeoutMs the duration after which `action` is called | ||
* @param active whether or not the interval is active | ||
*/ | ||
if (schedulePolicy === SchedulePolicy.Immediately) { | ||
this.set(); | ||
} | ||
} | ||
function useTimeout(action, timeoutMs, active) { | ||
// We using a ref instead of a callback for `action` to avoid resetting | ||
// the interval whenever the `action` changes. | ||
const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_1__[/* useUpdatingRef */ "a"])(action); | ||
Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => { | ||
if (active) { | ||
const timeoutId = setTimeout(() => { | ||
actionRef.current(); | ||
}, timeoutMs); | ||
return () => { | ||
clearTimeout(timeoutId); | ||
}; | ||
} // actionRef isn't actually required, but react-hooks/exhaustive-deps | ||
// doesn't recognize it as a ref and thus complains if it isn't in the | ||
// deps list. It isn't a big deal though since the value ofactionRef | ||
// never changes (only its contents do). | ||
get isSet() { | ||
return this._intervalId != null; | ||
} | ||
}, [timeoutMs, active, actionRef]); | ||
} | ||
set() { | ||
if (this.isSet) { | ||
this.clear(ClearPolicy.Cancel); | ||
} | ||
/***/ }), | ||
/* 5 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
this._intervalId = setInterval(() => this._action(), this._intervalMs); | ||
} | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return withActionScheduler; }); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _action_scheduler_provider_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
clear(policy = ClearPolicy.Cancel) { | ||
const intervalId = this._intervalId; | ||
this._intervalId = null; | ||
if (intervalId == null) { | ||
return; | ||
} | ||
clearInterval(intervalId); | ||
if (policy === ClearPolicy.Resolve) { | ||
this._action(); | ||
} | ||
} | ||
/** | ||
* A higher order component that attaches the given component to an | ||
* `IScheduleActions` instance. Any actions scheduled will automatically be | ||
* cleared on unmount. | ||
* | ||
* @template TOwnProps The own props of the component being rendered, without | ||
* the additional action scheduler prop. To attach the additional prop to | ||
* these props use the `WithActionScheduler` type. | ||
*/ | ||
function withActionScheduler(WrappedComponent) { | ||
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["forwardRef"]((props, ref) => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_action_scheduler_provider_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"], null, schedule => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](WrappedComponent, _extends({}, props, { | ||
ref: ref, | ||
schedule: schedule | ||
})))); | ||
} | ||
/***/ }), | ||
/* 6 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
class AnimationFrame { | ||
constructor(action, schedulePolicy = SchedulePolicy.Immediately) { | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
} | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useScheduledInterval; }); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _util_policies_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0); | ||
/* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2); | ||
/* harmony import */ var _use_interval_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3); | ||
this._action = action; | ||
function useScheduledInterval(action, intervalMs, options) { | ||
var _options$schedulePoli; | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
if (schedulePolicy === SchedulePolicy.Immediately) { | ||
this.set(); | ||
} | ||
} | ||
if (intervalMs < 1) { | ||
throw new Error("Interval period must be >= 1"); | ||
get isSet() { | ||
return this._animationFrameId != null; | ||
} | ||
const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately; | ||
const [isSet, setIsSet] = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(schedulePolicy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately); | ||
const set = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(() => setIsSet(true), []); | ||
const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(action); | ||
const clear = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(policy => { | ||
var _policy; | ||
policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy; | ||
if (isSet && policy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve) { | ||
actionRef.current(); | ||
set() { | ||
if (this.isSet) { | ||
this.clear(ClearPolicy.Cancel); | ||
} | ||
setIsSet(false); | ||
}, // react-hooks/exhaustive-deps doesn't require refs to be | ||
// listed in the deps array. Unfortunately, in this situation | ||
// it doesn't recognized actionRef as a ref. | ||
[actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
const runOnUnmountRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(isSet && (options == null ? void 0 : options.clearPolicy) === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve); | ||
Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => { | ||
return () => { | ||
// This code will only run with the component using this | ||
// hook is unmounted. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
if (runOnUnmountRef.current) { | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
actionRef.current(); | ||
} | ||
}; // This eslint rule doesn't realize actionRef and runOnUnmountRef | ||
// a both refs and thus do not have to be listed as deps. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
Object(_use_interval_js__WEBPACK_IMPORTED_MODULE_3__[/* useInterval */ "a"])(action, intervalMs, isSet); | ||
return { | ||
isSet, | ||
set, | ||
clear | ||
}; | ||
} | ||
/***/ }), | ||
/* 7 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useScheduledTimeout; }); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _util_policies_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0); | ||
/* harmony import */ var _internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2); | ||
/* harmony import */ var _use_timeout_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4); | ||
function useScheduledTimeout(action, timeoutMs, options) { | ||
var _options$schedulePoli; | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
this._animationFrameId = requestAnimationFrame(time => this.clear(ClearPolicy.Resolve, time)); | ||
} | ||
if (timeoutMs < 0) { | ||
throw new Error("Timeout period must be >= 0"); | ||
} | ||
clear(policy = ClearPolicy.Cancel, time) { | ||
const animationFrameId = this._animationFrameId; | ||
this._animationFrameId = null; | ||
const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately; | ||
const [isSet, setIsSet] = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(schedulePolicy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* SchedulePolicy */ "b"].Immediately); | ||
const set = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(() => setIsSet(true), []); // This wrapper isn't present in useScheduledInterval because we | ||
// don't need to update `isSet` in that situations. | ||
if (animationFrameId == null) { | ||
return; | ||
} | ||
const wrappedAction = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(() => { | ||
setIsSet(false); | ||
action(); | ||
}, [action]); | ||
const actionRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(wrappedAction); | ||
const clear = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])(policy => { | ||
var _policy; | ||
cancelAnimationFrame(animationFrameId); | ||
policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy; | ||
if (isSet && policy === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve) { | ||
actionRef.current(); | ||
if (policy === ClearPolicy.Resolve) { | ||
this._action(time || performance.now()); | ||
} | ||
setIsSet(false); | ||
}, // react-hooks/exhaustive-deps doesn't require refs to be | ||
// listed in the deps array. Unfortunately, in this situation | ||
// it doesn't recognized actionRef as a ref. | ||
[actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
const runOnUnmountRef = Object(_internal_use_updating_ref_js__WEBPACK_IMPORTED_MODULE_2__[/* useUpdatingRef */ "a"])(isSet && (options == null ? void 0 : options.clearPolicy) === _util_policies_js__WEBPACK_IMPORTED_MODULE_1__[/* ClearPolicy */ "a"].Resolve); | ||
Object(react__WEBPACK_IMPORTED_MODULE_0__["useEffect"])(() => { | ||
return () => { | ||
// This code will only run with the component using this | ||
// hook is unmounted. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
if (runOnUnmountRef.current) { | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
actionRef.current(); | ||
} | ||
}; // This eslint rule doesn't realize actionRef and runOnUnmountRef | ||
// a both refs and thus do not have to be listed as deps. | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
Object(_use_timeout_js__WEBPACK_IMPORTED_MODULE_3__[/* useTimeout */ "a"])(wrappedAction, timeoutMs, isSet); | ||
return { | ||
isSet, | ||
set, | ||
clear | ||
}; | ||
} | ||
/***/ }), | ||
/* 8 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ActionSchedulerProvider; }); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); | ||
/* harmony import */ var _util_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9); | ||
/** | ||
* A provider component that passes our action scheduling API to its children | ||
* and ensures that all scheduled actions are cleared on unmount. | ||
* | ||
* ```jsx | ||
* <ActionSchedulerProvider> | ||
* {schedule => this.renderThingThatNeedsTimers(schedule)} | ||
* </ActionSchedulerProvider> | ||
* ``` | ||
*/ | ||
class ActionSchedulerProvider extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] { | ||
constructor(...args) { | ||
super(...args); | ||
this._actionScheduler = new _util_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"](); | ||
} | ||
componentWillUnmount() { | ||
this._actionScheduler.disable(); | ||
} | ||
render() { | ||
const { | ||
children | ||
} = this.props; | ||
return children(this._actionScheduler); | ||
} | ||
} | ||
/***/ }), | ||
/* 9 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ActionScheduler; }); | ||
/* harmony import */ var _timeout_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(10); | ||
/* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(11); | ||
/* harmony import */ var _animation_frame_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(12); | ||
/** | ||
* Implements the `IScheduleActions` API to provide timeout, interval, and | ||
* animation frame support. This is not intended for direct use, but instead | ||
* is to be used solely by the `ActionSchedulerProvider` to provide an | ||
* `IScheduleActions` instance. | ||
*/ | ||
class ActionScheduler { | ||
@@ -456,3 +188,3 @@ constructor() { | ||
const timeout = new _timeout_js__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"](action, period, options == null ? void 0 : options.schedulePolicy); | ||
const timeout = new Timeout(action, period, options == null ? void 0 : options.schedulePolicy); | ||
@@ -469,3 +201,3 @@ this._registeredActions.push(() => timeout.clear(options == null ? void 0 : options.clearPolicy)); | ||
const interval = new _interval_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"](action, period, options == null ? void 0 : options.schedulePolicy); | ||
const interval = new Interval(action, period, options == null ? void 0 : options.schedulePolicy); | ||
@@ -482,3 +214,3 @@ this._registeredActions.push(() => interval.clear(options == null ? void 0 : options.clearPolicy)); | ||
const animationFrame = new _animation_frame_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"](action, options == null ? void 0 : options.schedulePolicy); | ||
const animationFrame = new AnimationFrame(action, options == null ? void 0 : options.schedulePolicy); | ||
@@ -495,8 +227,3 @@ this._registeredActions.push(() => animationFrame.clear(options == null ? void 0 : options.clearPolicy)); | ||
} | ||
/** | ||
* Prevents this scheduler from creating any additional actions. | ||
* This also clears any pending actions. | ||
*/ | ||
disable() { | ||
@@ -518,363 +245,158 @@ this._disabled = true; | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Timeout; }); | ||
/* harmony import */ var _policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0); | ||
/** | ||
* Encapsulates everything associated with calling setTimeout/clearTimeout, and | ||
* managing the lifecycle of that timer, including the ability to resolve or | ||
* cancel a pending timeout action. | ||
* | ||
* @export | ||
* @class Timeout | ||
* @implements {ITimeout} | ||
*/ | ||
class Timeout { | ||
/** | ||
* Creates a timeout that will invoke the given action after | ||
* the given period. The timeout does not start until set is called. | ||
* | ||
* @param {() => mixed} action The action to be invoked when the timeout | ||
* period has passed. | ||
* @param {number} timeoutMs The timeout period. | ||
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately, | ||
* the timer is set immediately on instantiation; otherwise, `set` must be | ||
* called to set the timeout. | ||
* Defaults to `SchedulePolicy.Immediately`. | ||
* @memberof Timeout | ||
*/ | ||
constructor(action, timeoutMs, schedulePolicy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) { | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
} | ||
if (timeoutMs < 0) { | ||
throw new Error("Timeout period must be >= 0"); | ||
} | ||
this._action = action; | ||
this._timeoutMs = timeoutMs; | ||
if (schedulePolicy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) { | ||
this.set(); | ||
} | ||
class ActionSchedulerProvider extends React__namespace.Component { | ||
constructor(...args) { | ||
super(...args); | ||
this._actionScheduler = new ActionScheduler(); | ||
} | ||
/** | ||
* Determine if the timeout is set or not. | ||
* | ||
* @returns {boolean} true if the timeout is set (aka pending), otherwise | ||
* false. | ||
* @memberof Timeout | ||
*/ | ||
get isSet() { | ||
return this._timeoutId != null; | ||
componentWillUnmount() { | ||
this._actionScheduler.disable(); | ||
} | ||
/** | ||
* Set the timeout. | ||
* | ||
* If the timeout is pending, this cancels that pending timeout and | ||
* sets the timeout afresh. If the timeout is not pending, this | ||
* sets a new timeout. | ||
* | ||
* @memberof Timeout | ||
*/ | ||
set() { | ||
if (this.isSet) { | ||
this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel); | ||
} | ||
this._timeoutId = setTimeout(() => this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve), this._timeoutMs); | ||
render() { | ||
const { | ||
children | ||
} = this.props; | ||
return children(this._actionScheduler); | ||
} | ||
/** | ||
* Clear the set timeout. | ||
* | ||
* If the timeout is pending, this cancels that pending timeout without | ||
* invoking the action. If no timeout is pending, this does nothing. | ||
* | ||
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request | ||
* was set when called, the request action is invoked after cancelling | ||
* the request; otherwise, the pending action is cancelled. | ||
* Defaults to `ClearPolicy.Cancel`. | ||
* | ||
* @returns {void} | ||
* @memberof Timeout | ||
*/ | ||
} | ||
clear(policy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel) { | ||
const timeoutId = this._timeoutId; | ||
this._timeoutId = null; | ||
function withActionScheduler(WrappedComponent) { | ||
return React__namespace.forwardRef((props, ref) => React__namespace.createElement(ActionSchedulerProvider, null, schedule => React__namespace.createElement(WrappedComponent, _extends__default["default"]({}, props, { | ||
ref: ref, | ||
schedule: schedule | ||
})))); | ||
} | ||
if (timeoutId == null) { | ||
return; | ||
} | ||
const useUpdatingRef = value => { | ||
const ref = React.useRef(value); | ||
React.useEffect(() => { | ||
ref.current = value; | ||
}, [value]); | ||
return ref; | ||
}; | ||
clearTimeout(timeoutId); | ||
if (policy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve) { | ||
this._action(); | ||
function useInterval(action, intervalMs, active) { | ||
const actionRef = useUpdatingRef(action); | ||
React.useEffect(() => { | ||
if (active) { | ||
const intervalId = setInterval(() => { | ||
actionRef.current(); | ||
}, intervalMs); | ||
return () => { | ||
clearInterval(intervalId); | ||
}; | ||
} | ||
} | ||
}, [intervalMs, active, actionRef]); | ||
} | ||
/***/ }), | ||
/* 11 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Interval; }); | ||
/* harmony import */ var _policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0); | ||
/** | ||
* Encapsulates everything associated with calling setInterval/clearInterval, | ||
* and managing the lifecycle of that interval. This includes the ability to | ||
* cancel the interval, and knowing if the interval is active. | ||
* | ||
* @export | ||
* @class Interval | ||
* @implements {IInterval} | ||
*/ | ||
class Interval { | ||
/** | ||
* Creates an interval that will invoke the given action after | ||
* the given period. The interval does not start until set is called. | ||
* | ||
* @param {() => mixed} action The action to be invoked each time the | ||
* interval period has passed. | ||
* @param {number} intervalMs The interval period. | ||
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately, | ||
* the interval is set immediately on instantiation; otherwise, `set` must be | ||
* called to set the interval. | ||
* Defaults to `SchedulePolicy.Immediately`. | ||
* @memberof Interval | ||
*/ | ||
constructor(action, intervalMs, schedulePolicy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) { | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
function useTimeout(action, timeoutMs, active) { | ||
const actionRef = useUpdatingRef(action); | ||
React.useEffect(() => { | ||
if (active) { | ||
const timeoutId = setTimeout(() => { | ||
actionRef.current(); | ||
}, timeoutMs); | ||
return () => { | ||
clearTimeout(timeoutId); | ||
}; | ||
} | ||
}, [timeoutMs, active, actionRef]); | ||
} | ||
if (intervalMs < 1) { | ||
throw new Error("Interval period must be >= 1"); | ||
} | ||
function useScheduledInterval(action, intervalMs, options) { | ||
var _options$schedulePoli; | ||
this._action = action; | ||
this._intervalMs = intervalMs; | ||
if (schedulePolicy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) { | ||
this.set(); | ||
} | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
} | ||
/** | ||
* Determine if the interval is active or not. | ||
* | ||
* @returns {boolean} true if the interval is active, otherwise false. | ||
* @memberof Interval | ||
*/ | ||
get isSet() { | ||
return this._intervalId != null; | ||
if (intervalMs < 1) { | ||
throw new Error("Interval period must be >= 1"); | ||
} | ||
/** | ||
* Activate the interval. | ||
* | ||
* If the interval is active, this cancels that interval and starts the | ||
* interval afresh. If the interval is not active, this starts it. | ||
* | ||
* @memberof Interval | ||
*/ | ||
const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : SchedulePolicy.Immediately; | ||
const [isSet, setIsSet] = React.useState(schedulePolicy === SchedulePolicy.Immediately); | ||
const set = React.useCallback(() => setIsSet(true), []); | ||
const actionRef = useUpdatingRef(action); | ||
const clear = React.useCallback(policy => { | ||
var _policy; | ||
set() { | ||
if (this.isSet) { | ||
this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel); | ||
} | ||
policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy; | ||
this._intervalId = setInterval(() => this._action(), this._intervalMs); | ||
} | ||
/** | ||
* Clear the active interval. | ||
* | ||
* If the interval is active, this cancels that interval. If no interval is | ||
* pending, this does nothing. | ||
* | ||
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request | ||
* was set when called, the request action is invoked after cancelling | ||
* the request; otherwise, the pending action is cancelled. | ||
* Defaults to `ClearPolicy.Cancel`. | ||
* | ||
* @returns {void} | ||
* @memberof Interval | ||
*/ | ||
clear(policy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel) { | ||
const intervalId = this._intervalId; | ||
this._intervalId = null; | ||
if (intervalId == null) { | ||
return; | ||
if (isSet && policy === ClearPolicy.Resolve) { | ||
actionRef.current(); | ||
} | ||
clearInterval(intervalId); | ||
if (policy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve) { | ||
this._action(); | ||
} | ||
} | ||
setIsSet(false); | ||
}, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve); | ||
React.useEffect(() => { | ||
return () => { | ||
if (runOnUnmountRef.current) { | ||
actionRef.current(); | ||
} | ||
}; | ||
}, []); | ||
useInterval(action, intervalMs, isSet); | ||
return { | ||
isSet, | ||
set, | ||
clear | ||
}; | ||
} | ||
/***/ }), | ||
/* 12 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
function useScheduledTimeout(action, timeoutMs, options) { | ||
var _options$schedulePoli; | ||
"use strict"; | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return AnimationFrame; }); | ||
/* harmony import */ var _policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0); | ||
/** | ||
* Encapsulates everything associated with calling requestAnimationFrame/ | ||
* cancelAnimationFrame, and managing the lifecycle of that request, including | ||
* the ability to resolve or cancel a pending request action. | ||
* | ||
* @export | ||
* @class AnimationFrame | ||
* @implements {IAnimationFrame} | ||
*/ | ||
class AnimationFrame { | ||
/** | ||
* Creates an animation frame request that will invoke the given action. | ||
* The request is not made until set is called. | ||
* | ||
* @param {DOMHighResTimeStamp => mixed} action The action to be invoked. | ||
* @param {SchedulePolicy} [schedulePolicy] When SchedulePolicy.Immediately, | ||
* the interval is set immediately on instantiation; otherwise, `set` must be | ||
* called to set the interval. | ||
* Defaults to `SchedulePolicy.Immediately`. | ||
* @memberof AnimationFrame | ||
*/ | ||
constructor(action, schedulePolicy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) { | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
} | ||
this._action = action; | ||
if (schedulePolicy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* SchedulePolicy */ "b"].Immediately) { | ||
this.set(); | ||
} | ||
if (typeof action !== "function") { | ||
throw new Error("Action must be a function"); | ||
} | ||
/** | ||
* Determine if the request is pending or not. | ||
* | ||
* @returns {boolean} true if the request is pending, otherwise | ||
* false. | ||
* @memberof AnimationFrame | ||
*/ | ||
get isSet() { | ||
return this._animationFrameId != null; | ||
if (timeoutMs < 0) { | ||
throw new Error("Timeout period must be >= 0"); | ||
} | ||
/** | ||
* Make the animation frame request. | ||
* | ||
* If the request is pending, this cancels that pending request and | ||
* makes the request afresh. If the request is not pending, this | ||
* makes a new request. | ||
* | ||
* @memberof AnimationFrame | ||
*/ | ||
const schedulePolicy = (_options$schedulePoli = options == null ? void 0 : options.schedulePolicy) != null ? _options$schedulePoli : SchedulePolicy.Immediately; | ||
const [isSet, setIsSet] = React.useState(schedulePolicy === SchedulePolicy.Immediately); | ||
const set = React.useCallback(() => setIsSet(true), []); | ||
const wrappedAction = React.useCallback(() => { | ||
setIsSet(false); | ||
action(); | ||
}, [action]); | ||
const actionRef = useUpdatingRef(wrappedAction); | ||
const clear = React.useCallback(policy => { | ||
var _policy; | ||
set() { | ||
if (this.isSet) { | ||
this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel); | ||
} | ||
policy = (_policy = policy) != null ? _policy : options == null ? void 0 : options.clearPolicy; | ||
this._animationFrameId = requestAnimationFrame(time => this.clear(_policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve, time)); | ||
} | ||
/** | ||
* Clear the pending request. | ||
* | ||
* If the request is pending, this cancels that pending request without | ||
* invoking the action. If no request is pending, this does nothing. | ||
* | ||
* @param {ClearPolicy} [policy] When ClearPolicy.Resolve, if the request | ||
* was set when called, the request action is invoked after cancelling | ||
* the request; otherwise, the pending action is cancelled. | ||
* Defaults to `ClearPolicy.Cancel`. | ||
* @param {DOMHighResTimeStamp} [time] Timestamp to pass to the action when | ||
* ClearPolicy.Resolve is specified. Ignored when ClearPolicy.Cancel is | ||
* specified. | ||
* | ||
* @returns {void} | ||
* @memberof AnimationFrame | ||
*/ | ||
clear(policy = _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Cancel, time) { | ||
const animationFrameId = this._animationFrameId; | ||
this._animationFrameId = null; | ||
if (animationFrameId == null) { | ||
return; | ||
if (isSet && policy === ClearPolicy.Resolve) { | ||
actionRef.current(); | ||
} | ||
cancelAnimationFrame(animationFrameId); | ||
if (policy === _policies_js__WEBPACK_IMPORTED_MODULE_0__[/* ClearPolicy */ "a"].Resolve) { | ||
this._action(time || performance.now()); | ||
} | ||
} | ||
setIsSet(false); | ||
}, [actionRef, isSet, options == null ? void 0 : options.clearPolicy]); | ||
const runOnUnmountRef = useUpdatingRef(isSet && (options == null ? void 0 : options.clearPolicy) === ClearPolicy.Resolve); | ||
React.useEffect(() => { | ||
return () => { | ||
if (runOnUnmountRef.current) { | ||
actionRef.current(); | ||
} | ||
}; | ||
}, []); | ||
useTimeout(wrappedAction, timeoutMs, isSet); | ||
return { | ||
isSet, | ||
set, | ||
clear | ||
}; | ||
} | ||
/***/ }), | ||
/* 13 */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony import */ var _util_policies_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SchedulePolicy", function() { return _util_policies_js__WEBPACK_IMPORTED_MODULE_0__["b"]; }); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ClearPolicy", function() { return _util_policies_js__WEBPACK_IMPORTED_MODULE_0__["a"]; }); | ||
/* harmony import */ var _components_with_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "withActionScheduler", function() { return _components_with_action_scheduler_js__WEBPACK_IMPORTED_MODULE_1__["a"]; }); | ||
/* harmony import */ var _hooks_use_interval_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useInterval", function() { return _hooks_use_interval_js__WEBPACK_IMPORTED_MODULE_2__["a"]; }); | ||
/* harmony import */ var _hooks_use_timeout_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useTimeout", function() { return _hooks_use_timeout_js__WEBPACK_IMPORTED_MODULE_3__["a"]; }); | ||
/* harmony import */ var _hooks_use_scheduled_interval_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useScheduledInterval", function() { return _hooks_use_scheduled_interval_js__WEBPACK_IMPORTED_MODULE_4__["a"]; }); | ||
/* harmony import */ var _hooks_use_scheduled_timeout_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useScheduledTimeout", function() { return _hooks_use_scheduled_timeout_js__WEBPACK_IMPORTED_MODULE_5__["a"]; }); | ||
/***/ }) | ||
/******/ ]); | ||
exports.ClearPolicy = ClearPolicy; | ||
exports.SchedulePolicy = SchedulePolicy; | ||
exports.useInterval = useInterval; | ||
exports.useScheduledInterval = useScheduledInterval; | ||
exports.useScheduledTimeout = useScheduledTimeout; | ||
exports.useTimeout = useTimeout; | ||
exports.withActionScheduler = withActionScheduler; |
{ | ||
"name": "@khanacademy/wonder-blocks-timing", | ||
"private": false, | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"design": "v1", | ||
@@ -20,3 +20,3 @@ "publishConfig": { | ||
"devDependencies": { | ||
"wb-dev-build-settings": "^0.2.0" | ||
"wb-dev-build-settings": "^0.7.1" | ||
}, | ||
@@ -23,0 +23,0 @@ "author": "", |
// @flow | ||
import * as React from "react"; | ||
import {mount} from "enzyme"; | ||
import "jest-enzyme"; | ||
import {render} from "@testing-library/react"; | ||
import ActionSchedulerProvider from "../action-scheduler-provider.js"; | ||
import ActionScheduler from "../../util/action-scheduler.js"; | ||
import ActionSchedulerProvider from "../action-scheduler-provider"; | ||
import ActionScheduler from "../../util/action-scheduler"; | ||
jest.mock("../../util/action-scheduler.js"); | ||
jest.mock("../../util/action-scheduler"); | ||
@@ -17,3 +16,3 @@ describe("ActionSchedulerProvider", () => { | ||
// Act | ||
mount( | ||
render( | ||
<ActionSchedulerProvider>{childrenMock}</ActionSchedulerProvider>, | ||
@@ -29,3 +28,3 @@ ); | ||
const childrenMock = jest.fn().mockReturnValueOnce(null); | ||
const wrapper = mount( | ||
const {unmount} = render( | ||
<ActionSchedulerProvider>{childrenMock}</ActionSchedulerProvider>, | ||
@@ -35,3 +34,3 @@ ); | ||
// Act | ||
wrapper.unmount(); | ||
unmount(); | ||
@@ -38,0 +37,0 @@ // Assert |
// @flow | ||
import * as React from "react"; | ||
import {mount} from "enzyme"; | ||
import "jest-enzyme"; | ||
import {render, screen} from "@testing-library/react"; | ||
import withActionScheduler from "../with-action-scheduler.js"; | ||
import withActionScheduler from "../with-action-scheduler"; | ||
import type {WithActionSchedulerProps} from "../../util/types.js"; | ||
import type {WithActionSchedulerProps} from "../../util/types"; | ||
@@ -18,6 +17,6 @@ describe("withActionScheduler", () => { | ||
const WithScheduler = withActionScheduler(Component); | ||
const wrapper = mount(<WithScheduler />); | ||
render(<WithScheduler />); | ||
// Assert | ||
expect(wrapper.text()).toBe("true"); | ||
expect(screen.getByText("true")).toBeInTheDocument(); | ||
}); | ||
@@ -36,3 +35,3 @@ | ||
// Act | ||
mount(<TestComponent ref={(node) => (ref = node)} />); | ||
render(<TestComponent ref={(node) => (ref = node)} />); | ||
@@ -39,0 +38,0 @@ // Assert |
// @flow | ||
import * as React from "react"; | ||
import ActionScheduler from "../util/action-scheduler.js"; | ||
import ActionScheduler from "../util/action-scheduler"; | ||
import type {IScheduleActions} from "../util/types.js"; | ||
import type {IScheduleActions} from "../util/types"; | ||
@@ -7,0 +7,0 @@ type Props = {| |
// @flow | ||
import * as React from "react"; | ||
import ActionSchedulerProvider from "./action-scheduler-provider.js"; | ||
import ActionSchedulerProvider from "./action-scheduler-provider"; | ||
@@ -10,3 +10,3 @@ import type { | ||
WithActionScheduler, | ||
} from "../util/types.js"; | ||
} from "../util/types"; | ||
@@ -13,0 +13,0 @@ type WithoutActionScheduler<T> = $Exact<$Diff<T, WithActionSchedulerProps>>; |
// @flow | ||
import {renderHook} from "@testing-library/react-hooks"; | ||
import {useInterval} from "../use-interval.js"; | ||
import {useInterval} from "../use-interval"; | ||
@@ -6,0 +6,0 @@ describe("useTimeout", () => { |
// @flow | ||
import {renderHook, act} from "@testing-library/react-hooks"; | ||
import {SchedulePolicy, ClearPolicy} from "../../util/policies.js"; | ||
import {SchedulePolicy, ClearPolicy} from "../../util/policies"; | ||
import {useScheduledInterval} from "../use-scheduled-interval.js"; | ||
import {useScheduledInterval} from "../use-scheduled-interval"; | ||
@@ -309,2 +309,4 @@ describe("useScheduledInterval", () => { | ||
result.current.set(); | ||
}); | ||
act(() => { | ||
jest.advanceTimersByTime(501); | ||
@@ -348,2 +350,4 @@ }); | ||
result.current.clear(); | ||
}); | ||
act(() => { | ||
jest.advanceTimersByTime(501); | ||
@@ -369,2 +373,4 @@ }); | ||
result.current.clear(ClearPolicy.Resolve); | ||
}); | ||
act(() => { | ||
jest.advanceTimersByTime(501); | ||
@@ -392,2 +398,4 @@ }); | ||
result.current.clear(ClearPolicy.Cancel); | ||
}); | ||
act(() => { | ||
jest.advanceTimersByTime(501); | ||
@@ -394,0 +402,0 @@ }); |
// @flow | ||
import {renderHook, act} from "@testing-library/react-hooks"; | ||
import {SchedulePolicy, ClearPolicy} from "../../util/policies.js"; | ||
import {SchedulePolicy, ClearPolicy} from "../../util/policies"; | ||
import {useScheduledTimeout} from "../use-scheduled-timeout.js"; | ||
import {useScheduledTimeout} from "../use-scheduled-timeout"; | ||
@@ -198,3 +198,7 @@ describe("useScheduledTimeout", () => { | ||
jest.advanceTimersByTime(1001); | ||
}); | ||
act(() => { | ||
result.current.set(); | ||
}); | ||
act(() => { | ||
jest.advanceTimersByTime(1001); | ||
@@ -228,3 +232,3 @@ }); | ||
expect(action).not.toHaveBeenCalled(); | ||
act(() => jest.advanceTimersByTime(500)); | ||
act((): void => jest.advanceTimersByTime(500)); | ||
expect(action).toHaveBeenCalled(); | ||
@@ -305,2 +309,4 @@ }); | ||
result.current.clear(); | ||
}); | ||
act(() => { | ||
jest.advanceTimersByTime(1000); | ||
@@ -423,2 +429,4 @@ }); | ||
result.current.set(); | ||
}); | ||
act(() => { | ||
jest.advanceTimersByTime(1000); | ||
@@ -465,2 +473,4 @@ }); | ||
jest.advanceTimersByTime(500); | ||
}); | ||
act(() => { | ||
result.current.set(); | ||
@@ -467,0 +477,0 @@ jest.advanceTimersByTime(1000); |
// @flow | ||
import {renderHook} from "@testing-library/react-hooks"; | ||
import {useTimeout} from "../use-timeout.js"; | ||
import {useTimeout} from "../use-timeout"; | ||
@@ -6,0 +6,0 @@ describe("useTimeout", () => { |
// @flow | ||
import {useEffect} from "react"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref.js"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref"; | ||
@@ -6,0 +6,0 @@ /** |
@@ -7,7 +7,7 @@ // @flow | ||
ClearPolicy as ClearPolicies, | ||
} from "../util/policies.js"; | ||
import type {IInterval, ClearPolicy, Options} from "../util/types.js"; | ||
} from "../util/policies"; | ||
import type {IInterval, ClearPolicy, Options} from "../util/types"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref.js"; | ||
import {useInterval} from "./use-interval.js"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref"; | ||
import {useInterval} from "./use-interval"; | ||
@@ -14,0 +14,0 @@ export function useScheduledInterval( |
@@ -7,7 +7,7 @@ // @flow | ||
ClearPolicy as ClearPolicies, | ||
} from "../util/policies.js"; | ||
import type {ITimeout, ClearPolicy, Options} from "../util/types.js"; | ||
} from "../util/policies"; | ||
import type {ITimeout, ClearPolicy, Options} from "../util/types"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref.js"; | ||
import {useTimeout} from "./use-timeout.js"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref"; | ||
import {useTimeout} from "./use-timeout"; | ||
@@ -14,0 +14,0 @@ export function useScheduledTimeout( |
// @flow | ||
import {useEffect} from "react"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref.js"; | ||
import {useUpdatingRef} from "./internal/use-updating-ref"; | ||
@@ -6,0 +6,0 @@ /** |
@@ -10,3 +10,3 @@ // @flow | ||
WithoutActionScheduler, | ||
} from "./util/types.js"; | ||
} from "./util/types"; | ||
@@ -23,7 +23,7 @@ export type { | ||
export {SchedulePolicy, ClearPolicy} from "./util/policies.js"; | ||
export {default as withActionScheduler} from "./components/with-action-scheduler.js"; | ||
export {useInterval} from "./hooks/use-interval.js"; | ||
export {useTimeout} from "./hooks/use-timeout.js"; | ||
export {useScheduledInterval} from "./hooks/use-scheduled-interval.js"; | ||
export {useScheduledTimeout} from "./hooks/use-scheduled-timeout.js"; | ||
export {SchedulePolicy, ClearPolicy} from "./util/policies"; | ||
export {default as withActionScheduler} from "./components/with-action-scheduler"; | ||
export {useInterval} from "./hooks/use-interval"; | ||
export {useTimeout} from "./hooks/use-timeout"; | ||
export {useScheduledInterval} from "./hooks/use-scheduled-interval"; | ||
export {useScheduledTimeout} from "./hooks/use-scheduled-timeout"; |
// @flow | ||
import ActionScheduler from "../action-scheduler.js"; | ||
import Timeout from "../timeout.js"; | ||
import Interval from "../interval.js"; | ||
import AnimationFrame from "../animation-frame.js"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies.js"; | ||
import ActionScheduler from "../action-scheduler"; | ||
import Timeout from "../timeout"; | ||
import Interval from "../interval"; | ||
import AnimationFrame from "../animation-frame"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies"; | ||
jest.mock("../timeout.js"); | ||
jest.mock("../interval.js"); | ||
jest.mock("../animation-frame.js"); | ||
jest.mock("../timeout"); | ||
jest.mock("../interval"); | ||
jest.mock("../animation-frame"); | ||
@@ -12,0 +12,0 @@ describe("ActionScheduler", () => { |
// @flow | ||
import AnimationFrame from "../animation-frame.js"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies.js"; | ||
import AnimationFrame from "../animation-frame"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies"; | ||
@@ -5,0 +5,0 @@ describe("AnimationFrame", () => { |
// @flow | ||
import Interval from "../interval.js"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies.js"; | ||
import Interval from "../interval"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies"; | ||
@@ -5,0 +5,0 @@ describe("Interval", () => { |
// @flow | ||
import Timeout from "../timeout.js"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies.js"; | ||
import Timeout from "../timeout"; | ||
import {SchedulePolicy, ClearPolicy} from "../policies"; | ||
@@ -5,0 +5,0 @@ describe("Timeout", () => { |
// @flow | ||
import Timeout from "./timeout.js"; | ||
import Interval from "./interval.js"; | ||
import AnimationFrame from "./animation-frame.js"; | ||
import Timeout from "./timeout"; | ||
import Interval from "./interval"; | ||
import AnimationFrame from "./animation-frame"; | ||
@@ -12,3 +12,3 @@ import type { | ||
Options, | ||
} from "./types.js"; | ||
} from "./types"; | ||
@@ -15,0 +15,0 @@ /** |
@@ -5,5 +5,5 @@ // @flow | ||
ClearPolicy as ClearPolicies, | ||
} from "./policies.js"; | ||
} from "./policies"; | ||
import type {IAnimationFrame, SchedulePolicy, ClearPolicy} from "./types.js"; | ||
import type {IAnimationFrame, SchedulePolicy, ClearPolicy} from "./types"; | ||
@@ -10,0 +10,0 @@ /** |
@@ -5,5 +5,5 @@ // @flow | ||
ClearPolicy as ClearPolicies, | ||
} from "./policies.js"; | ||
} from "./policies"; | ||
import type {IInterval, SchedulePolicy, ClearPolicy} from "./types.js"; | ||
import type {IInterval, SchedulePolicy, ClearPolicy} from "./types"; | ||
@@ -10,0 +10,0 @@ /** |
@@ -5,5 +5,5 @@ // @flow | ||
ClearPolicy as ClearPolicies, | ||
} from "./policies.js"; | ||
} from "./policies"; | ||
import type {ITimeout, SchedulePolicy, ClearPolicy} from "./types.js"; | ||
import type {ITimeout, SchedulePolicy, ClearPolicy} from "./types"; | ||
@@ -10,0 +10,0 @@ /** |
@@ -7,5 +7,5 @@ /* eslint-disable no-unused-vars */ | ||
import * as React from "react"; | ||
import withActionScheduler from "../components/with-action-scheduler.js"; | ||
import withActionScheduler from "../components/with-action-scheduler"; | ||
import type {WithActionSchedulerProps} from "./types.js"; | ||
import type {WithActionSchedulerProps} from "./types"; | ||
@@ -12,0 +12,0 @@ /** |
Sorry, the diff of this file is not supported yet
39
152501
3490