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