Fitbit/webpack-config

View on GitHub
src/ConfigCommandFactory.js

Summary

Maintainability
A
0 mins
Test Coverage
import types from './ConfigCommandTypes';

/**
 * @private
 * @type {WeakMap}
 */
const CONTAINER = new WeakMap();

/**
 * @class
 */
class ConfigCommandFactory {
    /**
     * @constructor
     * @param {ConfigContainer} container
     */
    constructor(container) {
        CONTAINER.set(this, container);
    }

    /**
     * @readonly
     * @type {ConfigContainer}
     */
    get container() {
        return CONTAINER.get(this);
    }

    /**
     * Creates {@link ConfigCommand}
     * @param {String} name
     * @returns {ConfigCommand}
     */
    createCommand(name) {
        return this.container.resolve(types[name]);
    }
}

export default ConfigCommandFactory;