Skip to content

Commit

Permalink
Merge pull request #113 from jolocom/feat/events
Browse files Browse the repository at this point in the history
Basic event system + Interaction updated/created events
  • Loading branch information
mnzaki authored Jun 2, 2021
2 parents cf7e829 + a4011ba commit 4f746f8
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 67 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
},
},
moduleFileExtensions: ['ts', 'node', 'js', 'json'],
testMatch: ['**/tests/*.test.ts'],
testMatch: ['**/tests/**/*.test.ts'],
testPathIgnorePatterns: ['/node_modules/.*'],
moduleNameMapper: pathsToModuleNameMapper(
compilerOptions.paths,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"tslib": "^1.7.1",
"typed-emitter": "^1.3.1",
"typedoc": "^0.19.2",
"typeorm": "0.2.24",
"typescript": "^3.7.5",
Expand Down
23 changes: 23 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { EventEmitter } from 'events'
import TypedEmitter from 'typed-emitter'

export type Unsubscriber = () => void

/**
* This class wraps TypedEmitter, which is a typescript overlay on
* the standard EventEmitter class; typings only, no code
*/
export class Emitter<T> extends (EventEmitter as {
new <T>(): Omit<TypedEmitter<T>, 'on'>
})<T> {
on<E extends (string | symbol) & keyof T>(
event: E,
listener: T[E],
): Unsubscriber {
// @ts-ignore
EventEmitter.prototype.on.call(this, event, listener)
return () => {
super.off(event, listener)
}
}
}
Loading

0 comments on commit 4f746f8

Please sign in to comment.