source: node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.native.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: 1.7 KB
Line 
1/**
2 * @license React
3 * use-sync-external-store-shim.native.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 useState = React.useState,
18 useEffect = React.useEffect,
19 useLayoutEffect = React.useLayoutEffect,
20 useDebugValue = React.useDebugValue;
21function useSyncExternalStore$1(subscribe, getSnapshot) {
22 var value = getSnapshot(),
23 _useState = useState({ inst: { value: value, getSnapshot: getSnapshot } }),
24 inst = _useState[0].inst,
25 forceUpdate = _useState[1];
26 useLayoutEffect(
27 function () {
28 inst.value = value;
29 inst.getSnapshot = getSnapshot;
30 checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
31 },
32 [subscribe, value, getSnapshot]
33 );
34 useEffect(
35 function () {
36 checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
37 return subscribe(function () {
38 checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
39 });
40 },
41 [subscribe]
42 );
43 useDebugValue(value);
44 return value;
45}
46function checkIfSnapshotChanged(inst) {
47 var latestGetSnapshot = inst.getSnapshot;
48 inst = inst.value;
49 try {
50 var nextValue = latestGetSnapshot();
51 return !objectIs(inst, nextValue);
52 } catch (error) {
53 return !0;
54 }
55}
56exports.useSyncExternalStore =
57 void 0 !== React.useSyncExternalStore
58 ? React.useSyncExternalStore
59 : useSyncExternalStore$1;
Note: See TracBrowser for help on using the repository browser.