| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 1 | import mitt from 'mitt'; |
| Konstantin | fb6c6de | 2023-06-14 17:23:14 +0300 | [diff] [blame] | 2 | |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 3 | const emitter = mitt(); |
| Konstantin | fb6c6de | 2023-06-14 17:23:14 +0300 | [diff] [blame] | 4 | |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 5 | function once(event, handler) { |
| 6 | const wrapper = (...args) => { |
| 7 | emitter.off(event, wrapper); |
| 8 | handler(...args); |
| 9 | }; |
| 10 | emitter.on(event, wrapper); |
| 11 | } |
| 12 | |
| 13 | export default { |
| 14 | // Vue 2-style alias |
| 15 | $on: emitter.on, |
| 16 | $off: emitter.off, |
| 17 | $emit: emitter.emit, |
| 18 | $once: once, |
| 19 | // Plain methods used by PS4 branch |
| 20 | on: emitter.on, |
| 21 | off: emitter.off, |
| 22 | emit: emitter.emit, |
| 23 | once, |
| 24 | }; |