UNPKG

@awsui/components-react

Version:

AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A

60 lines (59 loc) 1.72 kB
import { __spreadArrays } from "tslib"; import { useEffect, useRef } from 'react'; var PromiseCancelledSignal = (function () { function PromiseCancelledSignal() { } return PromiseCancelledSignal; }()); export { PromiseCancelledSignal }; export function findIndex(array, condition) { for (var i = 0; i < array.length; i++) { if (condition(array[i])) { return i; } } return -1; } export function makeCancellable(promise) { var cancelled = false; var wrapped = promise.then(function (value) { if (cancelled) { throw new PromiseCancelledSignal(); } return value; }, function (err) { if (cancelled) { throw new PromiseCancelledSignal(); } throw err; }); return { promise: wrapped, cancel: function () { cancelled = true; }, isCancelled: function () { return cancelled; } }; } function makeMemoizedArray(prev, next, isEqual) { for (var i = 0; i < Math.max(prev.length, next.length); i++) { if (i === next.length) { return prev.slice(0, i); } if (i === prev.length) { return __spreadArrays(prev.slice(0, i), next.slice(i)); } if (!isEqual(prev[i], next[i])) { return __spreadArrays(prev.slice(0, i), [next[i]], makeMemoizedArray(prev.slice(i + 1), next.slice(i + 1), isEqual)); } } return prev; } export function useMemoizedArray(array, isEqual) { var ref = useRef(array); var updated = makeMemoizedArray(ref.current, array, isEqual); useEffect(function () { ref.current = updated; }, [updated]); return updated; }