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

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

Added visualizations

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