Skip to content

Commit 72586af

Browse files
committed
fix: free _getEditorEventStream
1 parent 669f20a commit 72586af

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/CodeFormatManager.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class CodeFormatManager {
7878

7979
// Events from editor actions (saving, typing).
8080
const editorEvents = observableFromSubscribeFunction((cb) => atom.workspace.observeTextEditors(cb)).mergeMap(
81-
(editor) => this._getEditorEventStream(editor)
81+
(editor) => _getEditorEventStream(editor)
8282
)
8383

8484
return (
@@ -97,22 +97,6 @@ export default class CodeFormatManager {
9797
)
9898
}
9999

100-
/** Returns a stream of all typing and saving operations from the editor. */
101-
_getEditorEventStream(editor: TextEditor): Observable<FormatEvent> {
102-
const changeEvents = observableFromSubscribeFunction((callback) => editor.getBuffer().onDidChangeText(callback))
103-
104-
// We need to capture when editors are about to be destroyed in order to
105-
// interrupt any pending formatting operations. (Otherwise, we may end up
106-
// attempting to save a destroyed editor!)
107-
const willDestroyEvents = observableFromSubscribeFunction((cb) => atom.workspace.onWillDestroyPaneItem(cb)).filter(
108-
(event) => event.item === editor
109-
)
110-
111-
return Observable.merge(changeEvents.map((edit) => ({ type: "type", editor, edit }))).takeUntil(
112-
Observable.merge(observeEditorDestroy(editor), willDestroyEvents)
113-
)
114-
}
115-
116100
_handleEvent(event: FormatEvent): Observable<unknown> {
117101
const { editor } = event
118102
switch (event.type) {
@@ -396,3 +380,19 @@ function _checkContentsAreSame(before: string, after: string): void {
396380
throw new Error("The file contents were changed before formatting was complete.")
397381
}
398382
}
383+
384+
/** Returns a stream of all typing and saving operations from the editor. */
385+
function _getEditorEventStream(editor: TextEditor): Observable<FormatEvent> {
386+
const changeEvents = observableFromSubscribeFunction((callback) => editor.getBuffer().onDidChangeText(callback))
387+
388+
// We need to capture when editors are about to be destroyed in order to
389+
// interrupt any pending formatting operations. (Otherwise, we may end up
390+
// attempting to save a destroyed editor!)
391+
const willDestroyEvents = observableFromSubscribeFunction((cb) => atom.workspace.onWillDestroyPaneItem(cb)).filter(
392+
(event) => event.item === editor
393+
)
394+
395+
return Observable.merge(changeEvents.map((edit) => ({ type: "type", editor, edit }))).takeUntil(
396+
Observable.merge(observeEditorDestroy(editor), willDestroyEvents)
397+
)
398+
}

0 commit comments

Comments
 (0)