UNPKG

@trusthab/composable-resources

Version:

migrating https://github.com/knetikmedia/hab-api/tree/integration/app/resources/composable

33 lines (24 loc) 659 B
const populateResources = require('./src/resource_loader'); let resources = {}; module.exports = class ComposableAdaptor { static init(Core) { resources = populateResources(); return Core.AdaptorInitializer.add('Composable', this); } static connect(App) { return Promise.resolve(new this(App)); } static requireComposableResource(name, App) { return resources[name](App); } constructor(app) { this.app = app; this.modules = {}; } get(path) { const { modules } = this; return modules[path] ? modules[path] : modules[path] = this.constructor.requireComposableResource(path, this.app); } }