Implementation of a Node.Events in Typescript compiled to an ES6 Browser Module
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:
npm install
make sure ./demo/index.html
contains importmap for dependencies:<script type="importmap">
{
"imports": {
"@browser-modules/dictionary":
"../node_modules/@browser-modules/dictionary/lib/dictionary.js",
"@browser-modules/events":
"../node_modules/@browser-modules/dictionary/lib/events.js"
}
}
</script>
note: importmaps make bare imports possible, see use case in step 4.
<script src="index.js" type="module"></script>
./demo/index.js
fileimport { Event } from '@browser-modules/events';
class Emitter extends Event {}
const emitter = new Emitter()
emitter.on('event', event =>
console.log(`event emitted: ${event}`)
)
emitter.emit('event','eventIdentifier')