-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(views): engine events; update DendronTreeView reliably (#2269)
* fix: add Engine Events Interface in EngineAPIService * spike: dendron tree view update * fix: moving DendronTreeViewV1 to utilize new engine events * spike: adding tests; fixing engine bugs * spike: mark NoteSyncService onNoteChange as deprecated * spike: fixing bugs in extension and engineAPIService * fix: moving EngineEvents to engine-server * fix: some fixes on NoteChangeEntry payloads from storev2 * fix: update EngineEvent event name * spike: fix build issues * fix: test adjustments * spike: fixing unused import * spike: cr feedback * spike: testAssertsInsideCallback util fn
- Loading branch information
1 parent
d590cde
commit 147cce8
Showing
31 changed files
with
1,445 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Disposable } from "./compat"; | ||
import { EventEmitter as NodeEventEmitter } from "events"; | ||
|
||
/** | ||
* Represents a typed event that can be subscribed to. | ||
* | ||
* This has an indentical interface signature to vscode.Event, but can be used | ||
* outside of plugin-core. | ||
*/ | ||
export interface Event<T> { | ||
/** | ||
* A function that represents an event to which you subscribe by calling it with | ||
* a listener function as argument. | ||
* | ||
* @param listener The listener function will be called when the event happens. | ||
* @param thisArgs The `this`-argument which will be used when calling the event listener. | ||
*/ | ||
(listener: (e: T) => any, thisArgs?: any): Disposable; | ||
} | ||
|
||
/** | ||
* An event emitter can be used to create and manage an {@link Event} for others | ||
* to subscribe to. One emitter always owns one event. | ||
* | ||
* This mimics the interface signature of vscode.EventEmitter but can be used | ||
* outside of plugin-core. | ||
*/ | ||
export class EventEmitter<T> { | ||
_emitter: NodeEventEmitter = new NodeEventEmitter(); | ||
_EVENT_CHANNEL = "default"; | ||
|
||
/** | ||
* The event listeners can subscribe to. | ||
*/ | ||
event: Event<T> = (listener, thisArgs?: any): Disposable => { | ||
let callback = listener; | ||
if (thisArgs) { | ||
callback = callback.bind(thisArgs); | ||
} | ||
|
||
this._emitter.on(this._EVENT_CHANNEL, callback); | ||
|
||
const disposable: Disposable = { | ||
dispose: () => { | ||
this._emitter.removeListener(this._EVENT_CHANNEL, callback); | ||
}, | ||
}; | ||
|
||
return disposable; | ||
}; | ||
|
||
/** | ||
* Notify all subscribers of the {@link EventEmitter.event event}. Failure | ||
* of one or more listener will not fail this function call. | ||
* | ||
* @param data The event object. | ||
*/ | ||
fire(data: T): void { | ||
this._emitter.emit(this._EVENT_CHANNEL, data); | ||
} | ||
|
||
/** | ||
* Dispose this object and free resources. | ||
*/ | ||
dispose(): void { | ||
this._emitter.removeAllListeners(this._EVENT_CHANNEL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Disposable, Event, NoteChangeEntry } from "@dendronhq/common-all"; | ||
|
||
/** | ||
* Interface providing events signaling changes that have been made to engine | ||
* state | ||
*/ | ||
export interface EngineEventEmitter extends Disposable { | ||
/** | ||
* Event that fires upon the changing of note state in the engine. | ||
*/ | ||
get onEngineNoteStateChanged(): Event<NoteChangeEntry[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.