Fix event firing

This commit is contained in:
Daniel Imms
2019-06-08 15:45:07 -07:00
parent 47fab14efc
commit 6375d9b88e
3 changed files with 10 additions and 7 deletions
+1 -1
View File
@@ -432,7 +432,7 @@ export class MockCompositionHelper implements ICompositionHelper {
export class MockCharSizeService implements ICharSizeService { export class MockCharSizeService implements ICharSizeService {
get hasValidSize(): boolean { return this.width > 0 && this.height > 0; } get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
onCharSizeChange: IEvent<string>; onCharSizeChange: IEvent<void>;
constructor(public width: number, public height: number) {} constructor(public width: number, public height: number) {}
measure(): void {} measure(): void {}
} }
+8 -5
View File
@@ -14,8 +14,8 @@ export class CharSizeService implements ICharSizeService {
public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; } public get hasValidSize(): boolean { return this.width > 0 && this.height > 0; }
private _onCharSizeChange = new EventEmitter2<string>(); private _onCharSizeChange = new EventEmitter2<void>();
public get onCharSizeChange(): IEvent<string> { return this._onCharSizeChange.event; } public get onCharSizeChange(): IEvent<void> { return this._onCharSizeChange.event; }
constructor( constructor(
document: Document, document: Document,
@@ -27,8 +27,11 @@ export class CharSizeService implements ICharSizeService {
public measure(): void { public measure(): void {
const result = this._measureStrategy.measure(); const result = this._measureStrategy.measure();
this.width = result.width; if (result.width !== this.width || result.height !== this.height) {
this.height = result.height; this.width = result.width;
this.height = result.height;
this._onCharSizeChange.fire();
}
} }
} }
@@ -69,7 +72,7 @@ class DomMeasureStrategy implements IMeasureStrategy {
// Note that this triggers a synchronous layout // Note that this triggers a synchronous layout
const geometry = this._measureElement.getBoundingClientRect(); const geometry = this._measureElement.getBoundingClientRect();
console.log('measure', geometry);
// If values are 0 then the element is likely currently display:none, in which case we should // If values are 0 then the element is likely currently display:none, in which case we should
// retain the previous value. // retain the previous value.
if (geometry.width !== 0 && geometry.height !== 0) { if (geometry.width !== 0 && geometry.height !== 0) {
+1 -1
View File
@@ -10,7 +10,7 @@ export interface ICharSizeService {
readonly height: number; readonly height: number;
readonly hasValidSize: boolean; readonly hasValidSize: boolean;
readonly onCharSizeChange: IEvent<string>; readonly onCharSizeChange: IEvent<void>;
measure(): void; measure(): void;
} }