Remove publicOptions completely

This commit is contained in:
Simon Lamon
2021-11-10 10:17:14 +00:00
parent 317641c3bb
commit 4245ce33b5
7 changed files with 24 additions and 32 deletions
+4 -18
View File
@@ -57,17 +57,11 @@ export const DEFAULT_OPTIONS: Readonly<ITerminalOptions> = {
const FONT_WEIGHT_OPTIONS: Extract<FontWeight, string>[] = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'];
/**
* The set of options that only have an effect when set in the Terminal constructor.
*/
const CONSTRUCTOR_ONLY_OPTIONS = ['cols', 'rows'];
export class OptionsService implements IOptionsService {
public serviceBrand: any;
private _options: ITerminalOptions;
public options: ITerminalOptions;
public publicOptions: ITerminalOptions;
private _onOptionChange = new EventEmitter<string>();
public get onOptionChange(): IEvent<string> { return this._onOptionChange.event; }
@@ -87,11 +81,10 @@ export class OptionsService implements IOptionsService {
}
// set up getters and setters for each option
this.options = this._setupOptions(this._options, false);
this.publicOptions = this._setupOptions(this._options, true);
this.options = this._setupOptions(this._options);
}
private _setupOptions(options: ITerminalOptions, isPublic: boolean): ITerminalOptions {
private _setupOptions(options: ITerminalOptions): ITerminalOptions {
const copiedOptions = { ... options };
for (const propName in copiedOptions) {
Object.defineProperty(copiedOptions, propName, {
@@ -106,13 +99,6 @@ export class OptionsService implements IOptionsService {
throw new Error(`No option with key "${propName}"`);
}
// Throw an error if any constructor only option is modified
// from terminal.options
// Modifications from anywhere else are allowed
if (isPublic && CONSTRUCTOR_ONLY_OPTIONS.includes(propName)) {
throw new Error(`Option "${propName}" can only be set in the constructor`);
}
value = this._sanitizeAndValidateOption(propName, value);
// Don't fire an option change event if they didn't change
if (this._options[propName] !== value) {
@@ -126,7 +112,7 @@ export class OptionsService implements IOptionsService {
}
public setOption(key: string, value: any): void {
this.publicOptions[key] = value;
this.options[key] = value;
}
private _sanitizeAndValidateOption(key: string, value: any): any {
@@ -181,6 +167,6 @@ export class OptionsService implements IOptionsService {
}
public getOption(key: string): any {
return this.publicOptions[key];
return this.options[key];
}
}
-1
View File
@@ -189,7 +189,6 @@ export interface IOptionsService {
serviceBrand: undefined;
readonly options: ITerminalOptions;
readonly publicOptions: ITerminalOptions;
readonly onOptionChange: IEvent<string>;