Commit 411148a6 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate watch module to TS

parent 9f84b43f
...@@ -35,6 +35,7 @@ type IntlType = typeof window.Intl; ...@@ -35,6 +35,7 @@ type IntlType = typeof window.Intl;
function format( function format(
date: Date, date: Date,
options: Intl.DateTimeFormatOptions, options: Intl.DateTimeFormatOptions,
/* istanbul ignore next */
Intl: IntlType = window.Intl Intl: IntlType = window.Intl
): string { ): string {
const key = JSON.stringify(options); const key = JSON.stringify(options);
......
...@@ -32,19 +32,21 @@ ...@@ -32,19 +32,21 @@
* ); * );
* *
* @template T * @template T
* @param {(callback: () => void) => VoidFunction} subscribe - Function to * @param subscribe - Function to subscribe to changes from the data source.
* subscribe to changes from the data source. * @param getValue - Callback that extracts information of interest from the
* @param {() => T} getValue - Callback that extracts information of interest * data source.
* from the data source. * @param callback - A callback that receives the data extracted by `getValue`.
* @param {(current: T, previous: T) => void} callback - * It is called each time the result of `getValue` changes.
* A callback that receives the data extracted by `getValue`. It is called * @param compare - Comparison function that tests whether the results of two
* each time the result of `getValue` changes. * `getValue` calls are equal. If omitted, a strict equality check is used
* @param {((current: T, previous: T) => boolean)} [compare] - * @return Return value of `subscribe`
* Comparison function that tests whether the results of two `getValue` calls
* are equal. If omitted, a strict equality check is used
* @return {VoidFunction} - Return value of `subscribe`
*/ */
export function watch(subscribe, getValue, callback, compare) { export function watch<T>(
subscribe: (callback: VoidFunction) => VoidFunction,
getValue: () => T,
callback: (current: T, previous: T) => void,
compare?: (current: T, previous: T) => boolean
): VoidFunction {
let prevValue = getValue(); let prevValue = getValue();
const unsubscribe = subscribe(() => { const unsubscribe = subscribe(() => {
const currentValue = getValue(); const currentValue = getValue();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment