remove proxy
This commit is contained in:
@@ -30,16 +30,22 @@ export class Terminal implements ITerminalApi {
|
|||||||
this._core = new TerminalCore(options);
|
this._core = new TerminalCore(options);
|
||||||
this._addonManager = new AddonManager();
|
this._addonManager = new AddonManager();
|
||||||
|
|
||||||
this._publicOptions = new Proxy(this._core.options, {
|
this._publicOptions = {};
|
||||||
get: (target, propName: string): any => {
|
const getter = (propName: string): any => {
|
||||||
return target[propName];
|
return this._core.options[propName];
|
||||||
},
|
};
|
||||||
set: (target, propName: string, value): any => {
|
const setter = (propName: string, value: any): void => {
|
||||||
this._checkReadonlyOptions(propName);
|
this._checkReadonlyOptions(propName);
|
||||||
target[propName] = value;
|
this._core.options[propName] = value;
|
||||||
return true;
|
};
|
||||||
}
|
|
||||||
});
|
for (const propName in this._core.options) {
|
||||||
|
const desc = {
|
||||||
|
get: getter.bind(this, propName),
|
||||||
|
set: setter.bind(this, propName)
|
||||||
|
};
|
||||||
|
Object.defineProperty(this._publicOptions, propName, desc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _checkReadonlyOptions(propName: string): void {
|
private _checkReadonlyOptions(propName: string): void {
|
||||||
|
|||||||
@@ -120,11 +120,13 @@ export class MockLogService implements ILogService {
|
|||||||
|
|
||||||
export class MockOptionsService implements IOptionsService {
|
export class MockOptionsService implements IOptionsService {
|
||||||
public serviceBrand: any;
|
public serviceBrand: any;
|
||||||
|
public readonly rawOptions: ITerminalOptions = clone(DEFAULT_OPTIONS);
|
||||||
public options: ITerminalOptions = clone(DEFAULT_OPTIONS);
|
public options: ITerminalOptions = clone(DEFAULT_OPTIONS);
|
||||||
public onOptionChange: IEvent<string> = new EventEmitter<string>().event;
|
public onOptionChange: IEvent<string> = new EventEmitter<string>().event;
|
||||||
constructor(testOptions?: Partial<ITerminalOptions>) {
|
constructor(testOptions?: Partial<ITerminalOptions>) {
|
||||||
if (testOptions) {
|
if (testOptions) {
|
||||||
for (const key of Object.keys(testOptions)) {
|
for (const key of Object.keys(testOptions)) {
|
||||||
|
this.rawOptions = testOptions[key];
|
||||||
this.options[key] = testOptions[key];
|
this.options[key] = testOptions[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ describe('OptionsService', () => {
|
|||||||
it('uses default value if invalid constructor option value passed', () => {
|
it('uses default value if invalid constructor option value passed', () => {
|
||||||
assert.equal(new OptionsService({ tabStopWidth: 0 }).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
|
assert.equal(new OptionsService({ tabStopWidth: 0 }).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
|
||||||
});
|
});
|
||||||
|
it('object.keys return the correct number of options', () => {
|
||||||
|
const optionsService = new OptionsService({ cols: 80, rows: 25 });
|
||||||
|
assert.notEqual(Object.keys(optionsService.options).length, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('setOption', () => {
|
describe('setOption', () => {
|
||||||
let service: OptionsService;
|
let service: OptionsService;
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ const FONT_WEIGHT_OPTIONS: Extract<FontWeight, string>[] = ['normal', 'bold', '1
|
|||||||
export class OptionsService implements IOptionsService {
|
export class OptionsService implements IOptionsService {
|
||||||
public serviceBrand: any;
|
public serviceBrand: any;
|
||||||
|
|
||||||
|
public readonly rawOptions: ITerminalOptions;
|
||||||
public options: ITerminalOptions;
|
public options: ITerminalOptions;
|
||||||
|
|
||||||
private _onOptionChange = new EventEmitter<string>();
|
private _onOptionChange = new EventEmitter<string>();
|
||||||
@@ -80,31 +81,39 @@ export class OptionsService implements IOptionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set up getters and setters for each option
|
// set up getters and setters for each option
|
||||||
this.options = this._setupOptions(defaultOptions);
|
this.rawOptions = defaultOptions;
|
||||||
|
this.options = { ... defaultOptions };
|
||||||
|
this._setupOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setupOptions(options: ITerminalOptions): ITerminalOptions {
|
private _setupOptions(): void {
|
||||||
return new Proxy(options, {
|
const getter = (propName: string): any => {
|
||||||
get: (target, propName: string): any => {
|
if (!(propName in DEFAULT_OPTIONS)) {
|
||||||
if (!(propName in DEFAULT_OPTIONS)) {
|
throw new Error(`No option with key "${propName}"`);
|
||||||
throw new Error(`No option with key "${propName}"`);
|
|
||||||
}
|
|
||||||
return target[propName];
|
|
||||||
},
|
|
||||||
set: (target, propName: string, value): any => {
|
|
||||||
if (!(propName in DEFAULT_OPTIONS)) {
|
|
||||||
throw new Error(`No option with key "${propName}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
value = this._sanitizeAndValidateOption(propName, value);
|
|
||||||
// Don't fire an option change event if they didn't change
|
|
||||||
if (target[propName] !== value) {
|
|
||||||
target[propName] = value;
|
|
||||||
this._onOptionChange.fire(propName);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
});
|
return this.rawOptions[propName];
|
||||||
|
};
|
||||||
|
|
||||||
|
const setter = (propName: string, value: any): void => {
|
||||||
|
if (!(propName in DEFAULT_OPTIONS)) {
|
||||||
|
throw new Error(`No option with key "${propName}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = this._sanitizeAndValidateOption(propName, value);
|
||||||
|
// Don't fire an option change event if they didn't change
|
||||||
|
if (this.rawOptions[propName] !== value) {
|
||||||
|
this.rawOptions[propName] = value;
|
||||||
|
this._onOptionChange.fire(propName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const propName in this.rawOptions) {
|
||||||
|
const desc = {
|
||||||
|
get: getter.bind(this, propName),
|
||||||
|
set: setter.bind(this, propName)
|
||||||
|
};
|
||||||
|
Object.defineProperty(this.options, propName, desc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public setOption(key: string, value: any): void {
|
public setOption(key: string, value: any): void {
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ export const IOptionsService = createDecorator<IOptionsService>('OptionsService'
|
|||||||
export interface IOptionsService {
|
export interface IOptionsService {
|
||||||
serviceBrand: undefined;
|
serviceBrand: undefined;
|
||||||
|
|
||||||
|
readonly rawOptions: Readonly<ITerminalOptions>;
|
||||||
readonly options: ITerminalOptions;
|
readonly options: ITerminalOptions;
|
||||||
|
|
||||||
readonly onOptionChange: IEvent<string>;
|
readonly onOptionChange: IEvent<string>;
|
||||||
|
|||||||
@@ -189,6 +189,10 @@ describe('API Integration Tests', function(): void {
|
|||||||
assert.equal(await page.evaluate(`window.term.options.fontSize`), 30);
|
assert.equal(await page.evaluate(`window.term.options.fontSize`), 30);
|
||||||
assert.equal(await page.evaluate(`window.term.options.fontFamily`), 'Arial');
|
assert.equal(await page.evaluate(`window.term.options.fontFamily`), 'Arial');
|
||||||
});
|
});
|
||||||
|
it('object.keys return the correct number of options', async () => {
|
||||||
|
await openTerminal(page);
|
||||||
|
assert.notEqual(await page.evaluate(`Object.keys(window.term.options).length`), 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('renderer', () => {
|
describe('renderer', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user