mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
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).
This commit is contained in:
@@ -6,26 +6,24 @@
|
||||
import { IGlyphIdentifier } from './Types';
|
||||
|
||||
export default abstract class BaseCharAtlas {
|
||||
private _didWarmUp: Promise<any>;
|
||||
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<any> {
|
||||
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<any> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
protected _doWarmUp(): void { }
|
||||
|
||||
/**
|
||||
* May be called before warmUp finishes, however it is okay for the implementation to
|
||||
|
||||
@@ -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<void> {
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user