ts-simple-ast
Version:
TypeScript compiler wrapper for static analysis and code manipulation.
49 lines (48 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("../utils");
var SettingsContainer = /** @class */ (function () {
/** @private */
function SettingsContainer(defaultSettings) {
this._defaultSettings = utils_1.ObjectUtils.assign({}, defaultSettings);
this._settings = defaultSettings;
}
/**
* Resets the settings to the default.
*/
SettingsContainer.prototype.reset = function () {
this._settings = utils_1.ObjectUtils.assign({}, this._defaultSettings);
this._fireModified();
};
/**
* Gets a copy of the settings as an object.
*/
SettingsContainer.prototype.get = function () {
return utils_1.ObjectUtils.assign({}, this._settings);
};
/**
* Sets one or all of the settings.
* @param settings - Settings to set.
*/
SettingsContainer.prototype.set = function (settings) {
utils_1.ObjectUtils.assign(this._settings, settings);
this._fireModified();
};
/**
* Subscribe to modifications in the settings container.
* @param action - Action to execute when the settings change.
* @internal
*/
SettingsContainer.prototype._onModified = function (action) {
if (this._modifiedEventContainer == null)
this._modifiedEventContainer = new utils_1.EventContainer();
this._modifiedEventContainer.subscribe(action);
};
/** @internal */
SettingsContainer.prototype._fireModified = function () {
if (this._modifiedEventContainer != null)
this._modifiedEventContainer.fire(undefined);
};
return SettingsContainer;
}());
exports.SettingsContainer = SettingsContainer;