-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ref-imp): #989 - added event emitter support
- Loading branch information
1 parent
fa7a4fd
commit 099e52a
Showing
12 changed files
with
82 additions
and
11 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,31 @@ | ||
import IEventEmitter from './interfaces/IEventEmitter'; | ||
import LogColor from './LogColor'; | ||
|
||
/** | ||
* Event emitter used in Sidetree. | ||
* Intended to be machine readable for triggering custom handlers. | ||
*/ | ||
export default class EventEmitter { | ||
// Default to basic console log. | ||
private static singleton: IEventEmitter = { | ||
emit: async (eventCode) => { | ||
console.log(LogColor.lightBlue(`Event emitted: ${LogColor.green(eventCode)}`)); | ||
} | ||
}; | ||
|
||
/** | ||
* Overrides the default event emitter if given. | ||
*/ | ||
static initialize (customEventEmitter?: IEventEmitter) { | ||
if (customEventEmitter !== undefined) { | ||
EventEmitter.singleton = customEventEmitter; | ||
} | ||
} | ||
|
||
/** | ||
* Emits an event. | ||
*/ | ||
public static async emit (eventName: string, eventData?: {[property: string]: any}): Promise<void> { | ||
await EventEmitter.singleton.emit(eventName, eventData); | ||
} | ||
} |
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,9 @@ | ||
/** | ||
* Custom event emitter interface. | ||
*/ | ||
export default interface IEventEmitter { | ||
/** | ||
* Emits an event. | ||
*/ | ||
emit (eventName: string, eventData?: {[property: string]: any}): Promise<void>; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* Logging interface used in Sidetree. | ||
* Custom logger interface. | ||
*/ | ||
export default interface ILogger { | ||
/** | ||
|
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,7 @@ | ||
/** | ||
* Event codes used by Sidetree core service. | ||
*/ | ||
export default { | ||
BatchWriterProcessingLoopSuccess: 'batch_writer_processing_loop_success', | ||
ObserverProcessingLoopSuccess: 'observer_processing_loop_success' | ||
}; |
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