Skip to content

Commit 14debd2

Browse files
committed
Load text-wrapper lazily
Profiler shows that loading text-wrapper dependencies takes >20ms This is unnecessary when the page is initially loading
1 parent e87d3e1 commit 14debd2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/TextBubbleSkin.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
const twgl = require('twgl.js');
22

3-
const TextWrapper = require('./util/text-wrapper');
43
const CanvasMeasurementProvider = require('./util/canvas-measurement-provider');
54
const Skin = require('./Skin');
65

6+
let _TextWrapper;
7+
const getTextWrapper = () => {
8+
if (!_TextWrapper) {
9+
// eslint-disable-next-line global-require
10+
_TextWrapper = require('./util/text-wrapper');
11+
}
12+
return _TextWrapper;
13+
};
14+
715
const BubbleStyle = {
816
MAX_LINE_WIDTH: 170, // Maximum width, in Scratch pixels, of a single line of text
917

@@ -67,7 +75,7 @@ class TextBubbleSkin extends Skin {
6775
this._textureDirty = true;
6876

6977
this.measurementProvider = new CanvasMeasurementProvider(this._canvas.getContext('2d'));
70-
this.textWrapper = new TextWrapper(this.measurementProvider);
78+
this.textWrapper = new (getTextWrapper())(this.measurementProvider);
7179

7280
this._restyleCanvas();
7381
}

0 commit comments

Comments
 (0)