Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Final version of the plugin interface
After alot of back and forth I think we landed a good plugin design. The premise was to remove event emission (since it was attached hackily throught the codebase) and instead use explicit APIs. However the one thing error events worked well with was namespacing issues from plugins. Which lead me to think, why on earth is that just an error thing? So new API (again, like millionth refactor/iteration to cure itch) ``` export abstract class DeepstreamPlugin { public abstract description: string public async whenReady (): Promise<void> {} public init? (): void public async close (): Promise<void> {} public setRecordHandler? (recordHandler: any): void } ``` Doesn't look very different does it? The main aspect is the fact we no longer care if its sync or not. Plugin developers conceal that by just using whenReady (which is always async but could be a millisecond and could be up to initialization timeout). So what changed? ``` interface DeepstreamExamplePluginOptions { } class DeepstreamExample extends DeepstreamPlugin { public description = 'An Example Plugin' public logger = this.sevices.logger.getNameSpace('DEEPSTREAM_EXAMPLE_PLUGIN') constructor (pluginSettings: DeepstreamExamplePluginOptions, private services: DeepstreamServices) {} public async whenReady (): Promise<void> { return setTimeout(resolve, 10) // to wait for async dependencies, like opening a server, loading a file, etc } public init (): void { // This just allows you to move logic out of the constructor and guarantees its called after // the whenReady is already being waited upon. // If something failed, you can either this.logger.fatal(ERROR_EVENT, 'descriptive message') // or this.logger.error(ERROR_EVENT, 'descriptive message') this.services.onFatalException() } public async close (): Promise<void> { return setTimeout(resolve, 10) // closing a server for example } }
- Loading branch information
Showing
21 changed files
with
242 additions
and
258 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
Submodule rethinkdb
updated
3 files
+1 −1 | package-lock.json | |
+1 −1 | package.json | |
+18 −4 | src/connector.ts |
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
Oops, something went wrong.