Created
March 14, 2021 11:17
-
-
Save Lcfvs/c307b7ea102193ab8ea6dc8d2ed2e4ef to your computer and use it in GitHub Desktop.
A simple event emitter, without any lib dedicated to.
This file contains hidden or 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
| import * as etched from 'https://unpkg.com/@etchedjs/etched@latest/etched.min.js' | |
| const emitter = etched.model({ | |
| set event (value) { | |
| console.log('event `event` emitted on `emitter` with value', value) | |
| } | |
| }) | |
| const emitter2 = etched.model(emitter, { | |
| set event (value) { | |
| console.log('event `event` emitted on `emitter2` with value', value) | |
| } | |
| }) | |
| etched.etch(emitter, { event: 123 }) // 'event `event` emitted on `emitter` with value', 123 | |
| etched.etch(emitter, { event: 456 }) // 'event `event` emitted on `emitter` with value', 456 | |
| etched.etch(emitter, { event: 789 }) // 'event `event` emitted on `emitter` with value', 789 | |
| etched.etch(emitter2, { event: 123 }) // 'event `event` emitted on `emitter` with value', 123 AND 'event `event` emitted on `emitter2` with value', 123 | |
| etched.etch(emitter2, { event: 456 }) // 'event `event` emitted on `emitter` with value', 456 AND 'event `event` emitted on `emitter2` with value', 456 | |
| etched.etch(emitter2, { event: 789 }) // 'event `event` emitted on `emitter` with value', 789 AND 'event `event` emitted on `emitter2` with value', 789 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment