-
Notifications
You must be signed in to change notification settings - Fork 28
feat(autofix-result): refactor logstream handling with modifier #3188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
25f4011
ea15d50
f37dd4e
9ba6ce5
521128d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Invokes a callback when a logstream is updated. | ||
| // Usage: <div {{logstream-did-update this.handleLogstreamDidUpdate logstreamId}}></div> | ||
| import type ActionCableConsumerService from 'codecrafters-frontend/services/action-cable-consumer'; | ||
| import type Store from '@ember-data/store'; | ||
| import Logstream from 'codecrafters-frontend/utils/logstream'; | ||
| import Modifier, { type ArgsFor } from 'ember-modifier'; | ||
| import { inject as service } from '@ember/service'; | ||
| import { registerDestructor } from '@ember/destroyable'; | ||
| import type { Owner } from '@ember/test-helpers/build-owner'; | ||
|
|
||
| interface Signature { | ||
| Args: { | ||
| Positional: [(logstream: Logstream) => void, string]; | ||
| }; | ||
| } | ||
|
|
||
| function cleanup(instance: LogstreamDidUpdateModifier) { | ||
| if (instance.logstream) { | ||
| instance.logstream.unsubscribe(); | ||
| instance.logstream = undefined; | ||
| } | ||
| } | ||
|
|
||
| export default class LogstreamDidUpdateModifier extends Modifier<Signature> { | ||
| @service declare actionCableConsumer: ActionCableConsumerService; | ||
| @service declare store: Store; | ||
|
|
||
| logstream?: Logstream; | ||
|
|
||
| constructor(owner: unknown, args: ArgsFor<Signature>) { | ||
| super(owner as Owner, args); | ||
| registerDestructor(this, cleanup); | ||
| } | ||
|
|
||
| modify(_element: HTMLElement, [callback, logstreamId]: Signature['Args']['Positional']) { | ||
| cleanup(this); | ||
|
|
||
| this.logstream = new Logstream(logstreamId, this.actionCableConsumer, this.store, () => { | ||
| callback(this.logstream!); | ||
| }); | ||
|
|
||
| this.logstream.subscribe(); | ||
| } | ||
| } | ||
|
|
||
| declare module '@glint/environment-ember-loose/registry' { | ||
| export default interface Registry { | ||
| 'logstream-did-update': typeof LogstreamDidUpdateModifier; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,10 +35,6 @@ export default class Logstream { | |
| } | ||
|
|
||
| subscribeTask = task({ drop: true }, async (): Promise<void> => { | ||
| if (this.isSubscribed) { | ||
| return; | ||
| } | ||
|
|
||
| this.isTerminated = false; | ||
| this.isSubscribed = false; | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: ActionCable Subscription Overwriting BugRemoving the |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Logstream Modifier Fails to Unsubscribe Properly
The
logstream-did-updatemodifier creates a newLogstreamsubscription each time itslogstreamIdargument changes, but doesn't unsubscribe the previous instance. This causes memory leaks and multiple active subscriptions, as the destructor only cleans up the finalLogstream.