UNPKG

@aws-amplify/core

Version:

Core category of aws-amplify

49 lines (47 loc) • 1.49 kB
'use strict'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.getGlobalContext = getGlobalContext; exports.setGlobalContext = setGlobalContext; exports.hasGlobalContext = hasGlobalContext; exports.clearGlobalContext = clearGlobalContext; const NoAmplifyContextError_1 = require("../errors/NoAmplifyContextError"); let _globalContext = null; /** * Returns the global {@link AmplifyContext} set by `Amplify.configure()`. * * @throws {@link NoAmplifyContextError} If `Amplify.configure()` has not been * called yet and no context is available. */ function getGlobalContext() { if (!_globalContext) { // Typed error (stable name/code) so categories can catch the unconfigured // path uniformly. Message text is preserved for back-compat. throw new NoAmplifyContextError_1.NoAmplifyContextError(); } return _globalContext; } /** * Stores the given context as the global {@link AmplifyContext}. * * @internal */ function setGlobalContext(ctx) { _globalContext = ctx; } /** * Returns `true` if a global {@link AmplifyContext} has been set. */ function hasGlobalContext() { return _globalContext !== null; } /** * Clears the global {@link AmplifyContext}. * * @internal — intended for testing and HMR. */ function clearGlobalContext() { _globalContext = null; } //# sourceMappingURL=globalContext.js.map