Skip to content

Commit dd01474

Browse files
justin808claude
andcommitted
Convert Stimulus controller methods to arrow functions for SWC compatibility
Use arrow functions (class fields) instead of regular methods in CommentsController to ensure proper `this` binding with SWC transpilation. Arrow functions maintain lexical `this` binding, which fixes the issue where Stimulus event listeners weren't triggering methods correctly when transpiled by SWC. Changes: - resetText() -> resetText = () => {} - refreshCommentList() -> refreshCommentList = () => {} - connect() -> connect = () => {} This ensures Stimulus can properly bind and call these methods when responding to Turbo events. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b6548d7 commit dd01474

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

client/app/controllers/comments_controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ marked.use(mangle());
1010
export default class CommentsController extends Controller {
1111
static targets = ['commentList', 'commentAuthor', 'commentText', 'commentRefresh', 'alertDiv', 'errorList'];
1212

13-
resetText() {
13+
resetText = () => {
1414
const inputAuthor = this.commentAuthorTarget;
1515
const inputText = this.commentTextTarget;
1616
const alertDiv = this.alertDivTarget;
@@ -41,12 +41,12 @@ export default class CommentsController extends Controller {
4141
}
4242
}
4343

44-
refreshCommentList() {
44+
refreshCommentList = () => {
4545
const refreshBtn = this.commentRefreshTarget;
4646
refreshBtn.click();
4747
}
4848

49-
connect() {
49+
connect = () => {
5050
console.log('connected to Stimulus comments_controller');
5151

5252
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';

0 commit comments

Comments
 (0)