first
This commit is contained in:
Generated
Vendored
+165
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* @license React
|
||||
* use-sync-external-store-shim/with-selector.development.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
||||
if (
|
||||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
||||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
||||
'function'
|
||||
) {
|
||||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
||||
}
|
||||
var React = require('react');
|
||||
var shim = require('use-sync-external-store/shim');
|
||||
|
||||
/**
|
||||
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
||||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
||||
*/
|
||||
function is(x, y) {
|
||||
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
||||
;
|
||||
}
|
||||
|
||||
var objectIs = typeof Object.is === 'function' ? Object.is : is;
|
||||
|
||||
var useSyncExternalStore = shim.useSyncExternalStore;
|
||||
|
||||
// for CommonJS interop.
|
||||
|
||||
var useRef = React.useRef,
|
||||
useEffect = React.useEffect,
|
||||
useMemo = React.useMemo,
|
||||
useDebugValue = React.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
|
||||
|
||||
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
||||
// Use this to track the rendered snapshot.
|
||||
var instRef = useRef(null);
|
||||
var inst;
|
||||
|
||||
if (instRef.current === null) {
|
||||
inst = {
|
||||
hasValue: false,
|
||||
value: null
|
||||
};
|
||||
instRef.current = inst;
|
||||
} else {
|
||||
inst = instRef.current;
|
||||
}
|
||||
|
||||
var _useMemo = useMemo(function () {
|
||||
// Track the memoized state using closure variables that are local to this
|
||||
// memoized instance of a getSnapshot function. Intentionally not using a
|
||||
// useRef hook, because that state would be shared across all concurrent
|
||||
// copies of the hook/component.
|
||||
var hasMemo = false;
|
||||
var memoizedSnapshot;
|
||||
var memoizedSelection;
|
||||
|
||||
var memoizedSelector = function (nextSnapshot) {
|
||||
if (!hasMemo) {
|
||||
// The first time the hook is called, there is no memoized result.
|
||||
hasMemo = true;
|
||||
memoizedSnapshot = nextSnapshot;
|
||||
|
||||
var _nextSelection = selector(nextSnapshot);
|
||||
|
||||
if (isEqual !== undefined) {
|
||||
// Even if the selector has changed, the currently rendered selection
|
||||
// may be equal to the new selection. We should attempt to reuse the
|
||||
// current value if possible, to preserve downstream memoizations.
|
||||
if (inst.hasValue) {
|
||||
var currentSelection = inst.value;
|
||||
|
||||
if (isEqual(currentSelection, _nextSelection)) {
|
||||
memoizedSelection = currentSelection;
|
||||
return currentSelection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memoizedSelection = _nextSelection;
|
||||
return _nextSelection;
|
||||
} // We may be able to reuse the previous invocation's result.
|
||||
|
||||
|
||||
// We may be able to reuse the previous invocation's result.
|
||||
var prevSnapshot = memoizedSnapshot;
|
||||
var prevSelection = memoizedSelection;
|
||||
|
||||
if (objectIs(prevSnapshot, nextSnapshot)) {
|
||||
// The snapshot is the same as last time. Reuse the previous selection.
|
||||
return prevSelection;
|
||||
} // The snapshot has changed, so we need to compute a new selection.
|
||||
|
||||
|
||||
// The snapshot has changed, so we need to compute a new selection.
|
||||
var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data
|
||||
// has changed. If it hasn't, return the previous selection. That signals
|
||||
// to React that the selections are conceptually equal, and we can bail
|
||||
// out of rendering.
|
||||
|
||||
// If a custom isEqual function is provided, use that to check if the data
|
||||
// has changed. If it hasn't, return the previous selection. That signals
|
||||
// to React that the selections are conceptually equal, and we can bail
|
||||
// out of rendering.
|
||||
if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
|
||||
return prevSelection;
|
||||
}
|
||||
|
||||
memoizedSnapshot = nextSnapshot;
|
||||
memoizedSelection = nextSelection;
|
||||
return nextSelection;
|
||||
}; // Assigning this to a constant so that Flow knows it can't change.
|
||||
|
||||
|
||||
// Assigning this to a constant so that Flow knows it can't change.
|
||||
var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
|
||||
|
||||
var getSnapshotWithSelector = function () {
|
||||
return memoizedSelector(getSnapshot());
|
||||
};
|
||||
|
||||
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
|
||||
return memoizedSelector(maybeGetServerSnapshot());
|
||||
};
|
||||
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
||||
}, [getSnapshot, getServerSnapshot, selector, isEqual]),
|
||||
getSelection = _useMemo[0],
|
||||
getServerSelection = _useMemo[1];
|
||||
|
||||
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
||||
useEffect(function () {
|
||||
inst.hasValue = true;
|
||||
inst.value = value;
|
||||
}, [value]);
|
||||
useDebugValue(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
||||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
||||
if (
|
||||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
||||
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
||||
'function'
|
||||
) {
|
||||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
||||
}
|
||||
|
||||
})();
|
||||
}
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @license React
|
||||
* use-sync-external-store-shim/with-selector.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
'use strict';var h=require("react"),n=require("use-sync-external-store/shim");function p(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var q="function"===typeof Object.is?Object.is:p,r=n.useSyncExternalStore,t=h.useRef,u=h.useEffect,v=h.useMemo,w=h.useDebugValue;
|
||||
exports.useSyncExternalStoreWithSelector=function(a,b,e,l,g){var c=t(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f}else f=c.current;c=v(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==g&&f.hasValue){var b=f.value;if(g(b,a))return k=b}return k=a}b=k;if(q(d,a))return b;var e=l(a);if(void 0!==g&&g(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return[function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,g]);var d=r(a,c[0],c[1]);
|
||||
u(function(){f.hasValue=!0;f.value=d},[d]);w(d);return d};
|
||||
Reference in New Issue
Block a user