1df226684Sopenharmony_ci/* 2df226684Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3df226684Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4df226684Sopenharmony_ci * you may not use this file except in compliance with the License. 5df226684Sopenharmony_ci * You may obtain a copy of the License at 6df226684Sopenharmony_ci * 7df226684Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8df226684Sopenharmony_ci * 9df226684Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10df226684Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11df226684Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12df226684Sopenharmony_ci * See the License for the specific language governing permissions and 13df226684Sopenharmony_ci * limitations under the License. 14df226684Sopenharmony_ci */ 15df226684Sopenharmony_ciexport default class GlobalContext { 16df226684Sopenharmony_ci private constructor() {} 17df226684Sopenharmony_ci private static instance: GlobalContext; 18df226684Sopenharmony_ci private _objects = new Map<string, Object>(); 19df226684Sopenharmony_ci 20df226684Sopenharmony_ci public static getContext(): GlobalContext { 21df226684Sopenharmony_ci if (!GlobalContext.instance) { 22df226684Sopenharmony_ci GlobalContext.instance = new GlobalContext(); 23df226684Sopenharmony_ci } 24df226684Sopenharmony_ci return GlobalContext.instance; 25df226684Sopenharmony_ci } 26df226684Sopenharmony_ci 27df226684Sopenharmony_ci static store(name: string, obj: Object): void { 28df226684Sopenharmony_ci globalThis[name] = obj; 29df226684Sopenharmony_ci } 30df226684Sopenharmony_ci 31df226684Sopenharmony_ci static load(name: string): any { 32df226684Sopenharmony_ci return globalThis[name]; 33df226684Sopenharmony_ci } 34df226684Sopenharmony_ci 35df226684Sopenharmony_ci getObject(key: string): Object | undefined { 36df226684Sopenharmony_ci return this._objects.get(key); 37df226684Sopenharmony_ci } 38df226684Sopenharmony_ci 39df226684Sopenharmony_ci setObject(key: string, object: Object): void { 40df226684Sopenharmony_ci this._objects.set(key, object); 41df226684Sopenharmony_ci } 42df226684Sopenharmony_ci 43df226684Sopenharmony_ci} 44