UNPKG

react-obsidian

Version:

Dependency injection framework for React and React Native applications

27 lines 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GRAPH_INSTANCE_NAME_KEY = void 0; const GraphRegistry_1 = __importDefault(require("../../graph/registry/GraphRegistry")); const InjectionMetadata_1 = __importDefault(require("./InjectionMetadata")); exports.GRAPH_INSTANCE_NAME_KEY = 'GRAPH_INSTANCE_NAME'; class LateInjector { inject(target, sourceGraph) { if (sourceGraph) GraphRegistry_1.default.ensureRegistered(sourceGraph); const injectionMetadata = new InjectionMetadata_1.default(); const graph = sourceGraph !== null && sourceGraph !== void 0 ? sourceGraph : this.getGraphInstance(target); injectionMetadata.getLatePropertiesToInject(target.constructor).forEach((key) => { Reflect.set(target, key, graph.retrieve(key)); }); return target; } getGraphInstance(target) { const graphInstanceName = Reflect.getMetadata(exports.GRAPH_INSTANCE_NAME_KEY, target.constructor); return GraphRegistry_1.default.getGraphInstance(graphInstanceName); } } exports.default = new LateInjector(); //# sourceMappingURL=LateInjector.js.map