Skip to content

Commit 28332cb

Browse files
authored
Use arrow function to avoid new this binding (#58)
While integrating this into a Next.js project I noticed that when it tried to run `self.updateLastMessage` it would crash Webpack in general and nothing else would load. Converting this to an arrow function to maintain the existing `this` binding fixed my issue. I'd reported this in #52.
1 parent eb20aef commit 28332cb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

web/llm_chat.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,8 @@ class LLMChatInstance {
466466
}
467467
this.appendMessage("init", "");
468468
this.tvm = tvm;
469-
self = this;
470-
function initProgressCallback(report) {
471-
self.updateLastMessage("init", report.text);
469+
const initProgressCallback = (report) => {
470+
this.updateLastMessage("init", report.text);
472471
}
473472
tvm.registerInitProgressCallback(initProgressCallback);
474473
if (!cacheUrl.startsWith("http")) {

0 commit comments

Comments
 (0)