Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
import React from 'react';
|
||||
var defaultContext = /*#__PURE__*/React.createContext(undefined);
|
||||
var QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // if contextSharing is on, we share the first and at least one
|
||||
// instance of the context across the window
|
||||
// to ensure that if React Query is used across
|
||||
// different bundles or microfrontends they will
|
||||
// all use the same **instance** of context, regardless
|
||||
// of module scoping.
|
||||
|
||||
function getQueryClientContext(contextSharing) {
|
||||
if (contextSharing && typeof window !== 'undefined') {
|
||||
if (!window.ReactQueryClientContext) {
|
||||
window.ReactQueryClientContext = defaultContext;
|
||||
}
|
||||
|
||||
return window.ReactQueryClientContext;
|
||||
}
|
||||
|
||||
return defaultContext;
|
||||
}
|
||||
|
||||
export var useQueryClient = function useQueryClient() {
|
||||
var queryClient = React.useContext(getQueryClientContext(React.useContext(QueryClientSharingContext)));
|
||||
|
||||
if (!queryClient) {
|
||||
throw new Error('No QueryClient set, use QueryClientProvider to set one');
|
||||
}
|
||||
|
||||
return queryClient;
|
||||
};
|
||||
export var QueryClientProvider = function QueryClientProvider(_ref) {
|
||||
var client = _ref.client,
|
||||
_ref$contextSharing = _ref.contextSharing,
|
||||
contextSharing = _ref$contextSharing === void 0 ? false : _ref$contextSharing,
|
||||
children = _ref.children;
|
||||
React.useEffect(function () {
|
||||
client.mount();
|
||||
return function () {
|
||||
client.unmount();
|
||||
};
|
||||
}, [client]);
|
||||
var Context = getQueryClientContext(contextSharing);
|
||||
return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
|
||||
value: contextSharing
|
||||
}, /*#__PURE__*/React.createElement(Context.Provider, {
|
||||
value: client
|
||||
}, children));
|
||||
};
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import React from 'react'; // CONTEXT
|
||||
|
||||
function createValue() {
|
||||
var _isReset = false;
|
||||
return {
|
||||
clearReset: function clearReset() {
|
||||
_isReset = false;
|
||||
},
|
||||
reset: function reset() {
|
||||
_isReset = true;
|
||||
},
|
||||
isReset: function isReset() {
|
||||
return _isReset;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue()); // HOOK
|
||||
|
||||
export var useQueryErrorResetBoundary = function useQueryErrorResetBoundary() {
|
||||
return React.useContext(QueryErrorResetBoundaryContext);
|
||||
}; // COMPONENT
|
||||
|
||||
export var QueryErrorResetBoundary = function QueryErrorResetBoundary(_ref) {
|
||||
var children = _ref.children;
|
||||
var value = React.useMemo(function () {
|
||||
return createValue();
|
||||
}, []);
|
||||
return /*#__PURE__*/React.createElement(QueryErrorResetBoundaryContext.Provider, {
|
||||
value: value
|
||||
}, typeof children === 'function' ? children(value) : children);
|
||||
};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export var logger = console;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import ReactDOM from 'react-dom';
|
||||
export var unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { notifyManager } from '../core';
|
||||
import { unstable_batchedUpdates } from './reactBatchedUpdates';
|
||||
notifyManager.setBatchNotifyFunction(unstable_batchedUpdates);
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { setLogger } from '../core';
|
||||
import { logger } from './logger';
|
||||
setLogger(logger);
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
import React from 'react';
|
||||
import { notifyManager } from '../core/notifyManager';
|
||||
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary';
|
||||
import { useQueryClient } from './QueryClientProvider';
|
||||
import { shouldThrowError } from './utils';
|
||||
export function useBaseQuery(options, Observer) {
|
||||
var mountedRef = React.useRef(false);
|
||||
|
||||
var _React$useState = React.useState(0),
|
||||
forceUpdate = _React$useState[1];
|
||||
|
||||
var queryClient = useQueryClient();
|
||||
var errorResetBoundary = useQueryErrorResetBoundary();
|
||||
var defaultedOptions = queryClient.defaultQueryObserverOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
|
||||
|
||||
defaultedOptions.optimisticResults = true; // Include callbacks in batch renders
|
||||
|
||||
if (defaultedOptions.onError) {
|
||||
defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
|
||||
}
|
||||
|
||||
if (defaultedOptions.onSuccess) {
|
||||
defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
|
||||
}
|
||||
|
||||
if (defaultedOptions.onSettled) {
|
||||
defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
|
||||
}
|
||||
|
||||
if (defaultedOptions.suspense) {
|
||||
// Always set stale time when using suspense to prevent
|
||||
// fetching again when directly mounting after suspending
|
||||
if (typeof defaultedOptions.staleTime !== 'number') {
|
||||
defaultedOptions.staleTime = 1000;
|
||||
} // Set cache time to 1 if the option has been set to 0
|
||||
// when using suspense to prevent infinite loop of fetches
|
||||
|
||||
|
||||
if (defaultedOptions.cacheTime === 0) {
|
||||
defaultedOptions.cacheTime = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultedOptions.suspense || defaultedOptions.useErrorBoundary) {
|
||||
// Prevent retrying failed query if the error boundary has not been reset yet
|
||||
if (!errorResetBoundary.isReset()) {
|
||||
defaultedOptions.retryOnMount = false;
|
||||
}
|
||||
}
|
||||
|
||||
var _React$useState2 = React.useState(function () {
|
||||
return new Observer(queryClient, defaultedOptions);
|
||||
}),
|
||||
observer = _React$useState2[0];
|
||||
|
||||
var result = observer.getOptimisticResult(defaultedOptions);
|
||||
React.useEffect(function () {
|
||||
mountedRef.current = true;
|
||||
errorResetBoundary.clearReset();
|
||||
var unsubscribe = observer.subscribe(notifyManager.batchCalls(function () {
|
||||
if (mountedRef.current) {
|
||||
forceUpdate(function (x) {
|
||||
return x + 1;
|
||||
});
|
||||
}
|
||||
})); // Update result to make sure we did not miss any query updates
|
||||
// between creating the observer and subscribing to it.
|
||||
|
||||
observer.updateResult();
|
||||
return function () {
|
||||
mountedRef.current = false;
|
||||
unsubscribe();
|
||||
};
|
||||
}, [errorResetBoundary, observer]);
|
||||
React.useEffect(function () {
|
||||
// Do not notify on updates because of changes in the options because
|
||||
// these changes should already be reflected in the optimistic result.
|
||||
observer.setOptions(defaultedOptions, {
|
||||
listeners: false
|
||||
});
|
||||
}, [defaultedOptions, observer]); // Handle suspense
|
||||
|
||||
if (defaultedOptions.suspense && result.isLoading) {
|
||||
throw observer.fetchOptimistic(defaultedOptions).then(function (_ref) {
|
||||
var data = _ref.data;
|
||||
defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
|
||||
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
|
||||
}).catch(function (error) {
|
||||
errorResetBoundary.clearReset();
|
||||
defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
|
||||
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
|
||||
});
|
||||
} // Handle error boundary
|
||||
|
||||
|
||||
if (result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(defaultedOptions.suspense, defaultedOptions.useErrorBoundary, [result.error, observer.getCurrentQuery()])) {
|
||||
throw result.error;
|
||||
} // Handle result property usage tracking
|
||||
|
||||
|
||||
if (defaultedOptions.notifyOnChangeProps === 'tracked') {
|
||||
result = observer.trackResult(result, defaultedOptions);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { QueryObserver } from '../core';
|
||||
import { parseQueryArgs } from '../core/utils';
|
||||
import { useBaseQuery } from './useBaseQuery'; // HOOK
|
||||
|
||||
export function useQuery(arg1, arg2, arg3) {
|
||||
var parsedOptions = parseQueryArgs(arg1, arg2, arg3);
|
||||
return useBaseQuery(parsedOptions, QueryObserver);
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export function shouldThrowError(suspense, _useErrorBoundary, params) {
|
||||
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
||||
if (typeof _useErrorBoundary === 'function') {
|
||||
return _useErrorBoundary.apply(void 0, params);
|
||||
} // Allow useErrorBoundary to override suspense's throwing behavior
|
||||
|
||||
|
||||
if (typeof _useErrorBoundary === 'boolean') return _useErrorBoundary; // If suspense is enabled default to throwing errors
|
||||
|
||||
return !!suspense;
|
||||
}
|
||||
Reference in New Issue
Block a user