@@ -2,38 +2,49 @@ import eventManager from '../../utils/eventManager.js';
22import wrap from '../../utils/2.pokemon.js' ;
33import { registerModule } from '../../utils/plugin.js' ;
44import { capturePluginError } from '../../utils/sentry.js' ;
5+ import compoundEvent from '../../utils/compoundEvent.js' ;
56
67wrap ( ( ) => {
78 const options = [ 'cancelable' , 'canceled' , 'singleton' , 'async' ] ;
89
910 const name = 'events' ;
1011 function mod ( plugin ) {
12+ function wrapper ( fn , event ) {
13+ function listener ( ...args ) {
14+ try {
15+ fn . call ( this , ...args ) ;
16+ } catch ( e ) {
17+ capturePluginError ( plugin , e , {
18+ args,
19+ ...this ,
20+ } ) ;
21+ plugin . logger . error ( `Event error (${ event } ):\n` , e , '\n' , JSON . stringify ( {
22+ args,
23+ event : this ,
24+ } ) ) ;
25+ }
26+ }
27+ listener . plugin = plugin ;
28+ return listener ;
29+ }
1130 const obj = {
1231 ...eventManager ,
13- on ( event = '' , fn ) {
32+ compound ( ...events ) {
33+ const fn = events . pop ( ) ;
1434 if ( typeof fn !== 'function' ) throw new Error ( 'Must pass a function' ) ;
35+ if ( ! events . length ) throw new Error ( 'Must pass events' ) ;
36+ if ( events . length === 1 ) throw new Error ( 'Use `events.on` for single events' ) ;
1537
16- function pluginListener ( ...args ) {
17- try {
18- fn . call ( this , ...args ) ;
19- } catch ( e ) {
20- capturePluginError ( plugin , e , {
21- args,
22- ...this ,
23- } ) ;
24- plugin . logger . error ( `Event error (${ event } ):\n` , e , '\n' , JSON . stringify ( {
25- args,
26- event : this ,
27- } ) ) ;
28- }
29- }
30- pluginListener . plugin = plugin ;
38+ compoundEvent ( ...events , wrapper ( fn , `Compound[${ events . join ( ';' ) } ]` ) ) ;
39+ } ,
40+ on ( event , fn ) {
41+ if ( typeof fn !== 'function' ) throw new Error ( 'Must pass a function' ) ;
3142
3243 if ( event . split ( ' ' ) . includes ( ':loaded' ) ) {
3344 plugin . logger . warn ( 'Event manager: `:loaded` is deprecated, ask author to update to `:preload`!' ) ;
3445 }
3546
36- eventManager . on . call ( obj , event , pluginListener ) ;
47+ eventManager . on . call ( obj , event , wrapper ( fn , event ) ) ;
3748 } ,
3849 emit ( ...args ) {
3950 return eventManager . emit ( ...args ) ;
0 commit comments