UNPKG

@microsoft/windows-admin-center-sdk

Version:

Microsoft - Windows Admin Center Shell

60 lines (58 loc) 2.1 kB
import { LogLevel } from '../diagnostics/log-level'; import { Logging } from '../diagnostics/logging'; /** * Resource service to find a resource data by type and id. */ export class ResourceCache { static svgType = 'svg'; static svgInlineType = 'svgInline'; static strings = 'strings'; static collection = {}; /** * Register resource service to a specific type. * * @param type the type name of resource. * @param resource the resource data with find() interface. */ register(type, resource) { const existingResource = ResourceCache.collection[type]; if (existingResource) { const mergedResource = MsftSme.deepAssign(existingResource, resource); ResourceCache.collection[type] = mergedResource; } else { ResourceCache.collection[type] = resource; } } /** * Find a resource for the type and id. * * @param type the type name of resource. * @param id the identification. * @return T the found object id any. */ find(type, id) { const resource = ResourceCache.collection[type]; if (!resource) { Logging.log({ source: 'ResourceCache', level: LogLevel.Warning, message: MsftSme.getStrings().MsftSmeShell.Core.Error.ResourceCacheUnableFind.message.format(type) }); return null; } return resource.find(id); } /** * @deprecated - Use MsftSme.getStrings<T>() instead. * * Gets the localized strings initialized by localization manager. The LocalizationManager should have * been used to get the localized strings. This can also be achieved by calling SmeEnvironment.initEnvironment(). * @returns an object containing all the localized strings, or null if noe localized strings have been fetched yet */ getStrings() { const global = window; return global.MsftSme.Resources && global.MsftSme.Resources.strings; } } //# sourceMappingURL=resource-cache.js.map