| [a762898] | 1 | /**
|
|---|
| 2 | * @license React
|
|---|
| 3 | * use-sync-external-store-with-selector.development.js
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) Meta Platforms, Inc. and affiliates.
|
|---|
| 6 | *
|
|---|
| 7 | * This source code is licensed under the MIT license found in the
|
|---|
| 8 | * LICENSE file in the root directory of this source tree.
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | "use strict";
|
|---|
| 12 | "production" !== process.env.NODE_ENV &&
|
|---|
| 13 | (function () {
|
|---|
| 14 | function is(x, y) {
|
|---|
| 15 | return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
|
|---|
| 16 | }
|
|---|
| 17 | "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|---|
| 18 | "function" ===
|
|---|
| 19 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
|
|---|
| 20 | __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|---|
| 21 | var React = require("react"),
|
|---|
| 22 | objectIs = "function" === typeof Object.is ? Object.is : is,
|
|---|
| 23 | useSyncExternalStore = React.useSyncExternalStore,
|
|---|
| 24 | useRef = React.useRef,
|
|---|
| 25 | useEffect = React.useEffect,
|
|---|
| 26 | useMemo = React.useMemo,
|
|---|
| 27 | useDebugValue = React.useDebugValue;
|
|---|
| 28 | exports.useSyncExternalStoreWithSelector = function (
|
|---|
| 29 | subscribe,
|
|---|
| 30 | getSnapshot,
|
|---|
| 31 | getServerSnapshot,
|
|---|
| 32 | selector,
|
|---|
| 33 | isEqual
|
|---|
| 34 | ) {
|
|---|
| 35 | var instRef = useRef(null);
|
|---|
| 36 | if (null === instRef.current) {
|
|---|
| 37 | var inst = { hasValue: !1, value: null };
|
|---|
| 38 | instRef.current = inst;
|
|---|
| 39 | } else inst = instRef.current;
|
|---|
| 40 | instRef = useMemo(
|
|---|
| 41 | function () {
|
|---|
| 42 | function memoizedSelector(nextSnapshot) {
|
|---|
| 43 | if (!hasMemo) {
|
|---|
| 44 | hasMemo = !0;
|
|---|
| 45 | memoizedSnapshot = nextSnapshot;
|
|---|
| 46 | nextSnapshot = selector(nextSnapshot);
|
|---|
| 47 | if (void 0 !== isEqual && inst.hasValue) {
|
|---|
| 48 | var currentSelection = inst.value;
|
|---|
| 49 | if (isEqual(currentSelection, nextSnapshot))
|
|---|
| 50 | return (memoizedSelection = currentSelection);
|
|---|
| 51 | }
|
|---|
| 52 | return (memoizedSelection = nextSnapshot);
|
|---|
| 53 | }
|
|---|
| 54 | currentSelection = memoizedSelection;
|
|---|
| 55 | if (objectIs(memoizedSnapshot, nextSnapshot))
|
|---|
| 56 | return currentSelection;
|
|---|
| 57 | var nextSelection = selector(nextSnapshot);
|
|---|
| 58 | if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
|
|---|
| 59 | return (memoizedSnapshot = nextSnapshot), currentSelection;
|
|---|
| 60 | memoizedSnapshot = nextSnapshot;
|
|---|
| 61 | return (memoizedSelection = nextSelection);
|
|---|
| 62 | }
|
|---|
| 63 | var hasMemo = !1,
|
|---|
| 64 | memoizedSnapshot,
|
|---|
| 65 | memoizedSelection,
|
|---|
| 66 | maybeGetServerSnapshot =
|
|---|
| 67 | void 0 === getServerSnapshot ? null : getServerSnapshot;
|
|---|
| 68 | return [
|
|---|
| 69 | function () {
|
|---|
| 70 | return memoizedSelector(getSnapshot());
|
|---|
| 71 | },
|
|---|
| 72 | null === maybeGetServerSnapshot
|
|---|
| 73 | ? void 0
|
|---|
| 74 | : function () {
|
|---|
| 75 | return memoizedSelector(maybeGetServerSnapshot());
|
|---|
| 76 | }
|
|---|
| 77 | ];
|
|---|
| 78 | },
|
|---|
| 79 | [getSnapshot, getServerSnapshot, selector, isEqual]
|
|---|
| 80 | );
|
|---|
| 81 | var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
|
|---|
| 82 | useEffect(
|
|---|
| 83 | function () {
|
|---|
| 84 | inst.hasValue = !0;
|
|---|
| 85 | inst.value = value;
|
|---|
| 86 | },
|
|---|
| 87 | [value]
|
|---|
| 88 | );
|
|---|
| 89 | useDebugValue(value);
|
|---|
| 90 | return value;
|
|---|
| 91 | };
|
|---|
| 92 | "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|---|
| 93 | "function" ===
|
|---|
| 94 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
|
|---|
| 95 | __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|---|
| 96 | })();
|
|---|