From ac7db87fd0b4d7399ce2ea210f9388d0ed71d0d5 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Sat, 17 Mar 2018 23:54:18 -0700 Subject: [PATCH] Remove use of Promises in {Base,Static}CharAtlas Nothing actually cares about the return value, so we can avoid depending on `Promise` by not returning a promise. This should make this work for IE11 (though I haven't tested that). I tried this in Chrome and Firefox to test both codepaths (ImageBitmap and HTMLCanvasElement). --- src/renderer/atlas/BaseCharAtlas.ts | 14 ++++++-------- src/renderer/atlas/StaticCharAtlas.ts | 13 +++++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/renderer/atlas/BaseCharAtlas.ts b/src/renderer/atlas/BaseCharAtlas.ts index 21d5f833..8656f212 100644 --- a/src/renderer/atlas/BaseCharAtlas.ts +++ b/src/renderer/atlas/BaseCharAtlas.ts @@ -6,26 +6,24 @@ import { IGlyphIdentifier } from './Types'; export default abstract class BaseCharAtlas { - private _didWarmUp: Promise; + private _didWarmUp: boolean = false; /** * Perform any work needed to warm the cache before it can be used. May be called multiple times. * Implement _doWarmUp instead if you only want to get called once. */ - public warmUp(): Promise { - if (this._didWarmUp == null) { - this._didWarmUp = this._doWarmUp(); + public warmUp(): void { + if (!this._didWarmUp) { + this._doWarmUp(); + this._didWarmUp = true; } - return this._didWarmUp; } /** * Perform any work needed to warm the cache before it can be used. Used by the default * implementation of warmUp(), and will only be called once. */ - protected _doWarmUp(): Promise { - return Promise.resolve(); - } + protected _doWarmUp(): void { } /** * May be called before warmUp finishes, however it is okay for the implementation to diff --git a/src/renderer/atlas/StaticCharAtlas.ts b/src/renderer/atlas/StaticCharAtlas.ts index 746369fc..f68c7c6c 100644 --- a/src/renderer/atlas/StaticCharAtlas.ts +++ b/src/renderer/atlas/StaticCharAtlas.ts @@ -4,8 +4,7 @@ */ import { DIM_OPACITY, IGlyphIdentifier } from './Types'; -import { ICharAtlasConfig } from '../../shared/atlas/Types'; -import { CHAR_ATLAS_CELL_SPACING } from '../../shared/atlas/Types'; +import { CHAR_ATLAS_CELL_SPACING, ICharAtlasConfig } from '../../shared/atlas/Types'; import { generateStaticCharAtlasTexture } from '../../shared/atlas/CharAtlasGenerator'; import BaseCharAtlas from './BaseCharAtlas'; @@ -23,12 +22,14 @@ export default class StaticCharAtlas extends BaseCharAtlas { return canvas; } - public async _doWarmUp(): Promise { + public _doWarmUp() { const result = generateStaticCharAtlasTexture(window, this._canvasFactory, this._config); - if (result instanceof Promise) { - this._texture = await result; - } else { + if (result instanceof HTMLCanvasElement) { this._texture = result; + } else { + result.then(texture => { + this._texture = texture + }); } }