Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flippiecoetser/events
Typescript Event Emitter complied as ES6 Module
https://github.com/flippiecoetser/events
Last synced: 4 days ago
JSON representation
Typescript Event Emitter complied as ES6 Module
- Host: GitHub
- URL: https://github.com/flippiecoetser/events
- Owner: FlippieCoetser
- License: mit
- Created: 2022-06-21T14:21:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-07T13:48:28.000Z (over 2 years ago)
- Last Synced: 2025-01-03T08:19:45.590Z (7 days ago)
- Language: JavaScript
- Size: 111 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Events
Implementation of a Node.Events in Typescript compiled to an ES6 Browser Module[API Documentation](https://flippiecoetser.github.io/Events/)
### Example
Open `./demo/index.html` by **right-click** on file in VS Code and select: **Open with Live Server**.
The console output in chrome developer tools should display: `event emitted: eventIdentifier`.To reproduce this demo follow the steps below:
1. After `npm install` make sure `./demo/index.html` contains importmap for dependencies:
```html{
"imports": {
"@browser-modules/dictionary":
"../node_modules/@browser-modules/dictionary/lib/dictionary.js",
"@browser-modules/events":
"../node_modules/@browser-modules/dictionary/lib/events.js"
}
}```
note: *importmaps make bare imports possible, see use case in step 4.*2. Add ES6 Modules in browser:
```html
```
3. Create `./demo/index.js` file
4. Import the module:```javascript
import { Event } from '@browser-modules/events';
```5. Create emitter:
```javascript
class Emitter extends Event {}
const emitter = new Emitter()
```6. Register a listener:
```javascript
emitter.on('event', event =>
console.log(`event emitted: ${event}`)
)
```7. Trigger event with eventIdentifier as argument:
```javascript
emitter.emit('event','eventIdentifier')
```