Skip to content

Commit

Permalink
Use arrow function to avoid new this binding (#58)
Browse files Browse the repository at this point in the history
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 mlc-ai/web-llm#52.
  • Loading branch information
dragon-rider0111 committed Apr 22, 2023
1 parent ddfce22 commit 99b380a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions web/llm_chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ class LLMChatInstance {
}
this.appendMessage("init", "");
this.tvm = tvm;
self = this;
function initProgressCallback(report) {
self.updateLastMessage("init", report.text);
const initProgressCallback = (report) => {
this.updateLastMessage("init", report.text);
}
tvm.registerInitProgressCallback(initProgressCallback);
if (!cacheUrl.startsWith("http")) {
Expand Down

0 comments on commit 99b380a

Please sign in to comment.