source: node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/**
2 * @license React
3 * use-sync-external-store-shim/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 shim = require("use-sync-external-store/shim"),
23 objectIs = "function" === typeof Object.is ? Object.is : is,
24 useSyncExternalStore = shim.useSyncExternalStore,
25 useRef = React.useRef,
26 useEffect = React.useEffect,
27 useMemo = React.useMemo,
28 useDebugValue = React.useDebugValue;
29 exports.useSyncExternalStoreWithSelector = function (
30 subscribe,
31 getSnapshot,
32 getServerSnapshot,
33 selector,
34 isEqual
35 ) {
36 var instRef = useRef(null);
37 if (null === instRef.current) {
38 var inst = { hasValue: !1, value: null };
39 instRef.current = inst;
40 } else inst = instRef.current;
41 instRef = useMemo(
42 function () {
43 function memoizedSelector(nextSnapshot) {
44 if (!hasMemo) {
45 hasMemo = !0;
46 memoizedSnapshot = nextSnapshot;
47 nextSnapshot = selector(nextSnapshot);
48 if (void 0 !== isEqual && inst.hasValue) {
49 var currentSelection = inst.value;
50 if (isEqual(currentSelection, nextSnapshot))
51 return (memoizedSelection = currentSelection);
52 }
53 return (memoizedSelection = nextSnapshot);
54 }
55 currentSelection = memoizedSelection;
56 if (objectIs(memoizedSnapshot, nextSnapshot))
57 return currentSelection;
58 var nextSelection = selector(nextSnapshot);
59 if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
60 return (memoizedSnapshot = nextSnapshot), currentSelection;
61 memoizedSnapshot = nextSnapshot;
62 return (memoizedSelection = nextSelection);
63 }
64 var hasMemo = !1,
65 memoizedSnapshot,
66 memoizedSelection,
67 maybeGetServerSnapshot =
68 void 0 === getServerSnapshot ? null : getServerSnapshot;
69 return [
70 function () {
71 return memoizedSelector(getSnapshot());
72 },
73 null === maybeGetServerSnapshot
74 ? void 0
75 : function () {
76 return memoizedSelector(maybeGetServerSnapshot());
77 }
78 ];
79 },
80 [getSnapshot, getServerSnapshot, selector, isEqual]
81 );
82 var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
83 useEffect(
84 function () {
85 inst.hasValue = !0;
86 inst.value = value;
87 },
88 [value]
89 );
90 useDebugValue(value);
91 return value;
92 };
93 "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
94 "function" ===
95 typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
96 __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
97 })();
Note: See TracBrowser for help on using the repository browser.