core-api: get or create all bridged contexts
Co-authored-by: Juan Lulkin <jmaiz@spotify.com> Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -24,7 +24,10 @@ import React, {
|
||||
import PropTypes from 'prop-types';
|
||||
import { ApiRef, ApiHolder, TypesToApiRefs } from './types';
|
||||
import { ApiAggregator } from './ApiAggregator';
|
||||
import { getGlobalSingleton, setGlobalSingleton } from '../../lib/globalObject';
|
||||
import {
|
||||
getGlobalSingleton,
|
||||
getOrCreateGlobalSingleton,
|
||||
} from '../../lib/globalObject';
|
||||
import {
|
||||
VersionedValue,
|
||||
createVersionedValueMap,
|
||||
@@ -42,9 +45,9 @@ type ApiProviderProps = {
|
||||
};
|
||||
|
||||
type ApiContextType = VersionedValue<{ 1: ApiHolder }> | undefined;
|
||||
const ApiContext = createContext<ApiContextType>(undefined);
|
||||
|
||||
setGlobalSingleton('api-context', ApiContext);
|
||||
const ApiContext = getOrCreateGlobalSingleton('api-context', () =>
|
||||
createContext<ApiContextType>(undefined),
|
||||
);
|
||||
|
||||
export const ApiProvider = ({
|
||||
apis,
|
||||
|
||||
@@ -24,13 +24,16 @@ import {
|
||||
VersionedValue,
|
||||
createVersionedValueMap,
|
||||
} from '../lib/versionedValues';
|
||||
import { getGlobalSingleton, setGlobalSingleton } from '../lib/globalObject';
|
||||
import {
|
||||
getGlobalSingleton,
|
||||
getOrCreateGlobalSingleton,
|
||||
} from '../lib/globalObject';
|
||||
import { AppContext as AppContextV1 } from './types';
|
||||
|
||||
type AppContextType = VersionedValue<{ 1: AppContextV1 }> | undefined;
|
||||
const AppContext = createContext<AppContextType | undefined>(undefined);
|
||||
|
||||
setGlobalSingleton('app-context', AppContext);
|
||||
const AppContext = getOrCreateGlobalSingleton('app-context', () =>
|
||||
createContext<AppContextType | undefined>(undefined),
|
||||
);
|
||||
|
||||
type Props = {
|
||||
appContext: AppContextV1;
|
||||
|
||||
@@ -35,12 +35,15 @@ import {
|
||||
VersionedValue,
|
||||
createVersionedValueMap,
|
||||
} from '../lib/versionedValues';
|
||||
import { setGlobalSingleton, getGlobalSingleton } from '../lib/globalObject';
|
||||
import {
|
||||
getGlobalSingleton,
|
||||
getOrCreateGlobalSingleton,
|
||||
} from '../lib/globalObject';
|
||||
|
||||
type RoutingContextType = VersionedValue<{ 1: RouteResolver }> | undefined;
|
||||
const RoutingContext = createContext<RoutingContextType>(undefined);
|
||||
|
||||
setGlobalSingleton('routing-context', RoutingContext);
|
||||
const RoutingContext = getOrCreateGlobalSingleton('routing-context', () =>
|
||||
createContext<RoutingContextType>(undefined),
|
||||
);
|
||||
|
||||
export function useRouteRef<Optional extends boolean, Params extends AnyParams>(
|
||||
routeRef: ExternalRouteRef<Params, Optional>,
|
||||
|
||||
Reference in New Issue
Block a user