File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -11,9 +11,42 @@ export default function (parentClass) {
1111 }
1212
1313 _trigger ( method ) {
14+ this . dispatch ( method ) ;
1415 super . _trigger ( self . C3 [ AddonTypeMap [ addonType ] ] [ id ] . Cnds [ method ] ) ;
1516 }
1617
18+ on ( tag , callback , options ) {
19+ if ( ! this . events [ tag ] ) {
20+ this . events [ tag ] = [ ] ;
21+ }
22+ this . events [ tag ] . push ( { callback, options } ) ;
23+ }
24+
25+ off ( tag , callback ) {
26+ if ( this . events [ tag ] ) {
27+ this . events [ tag ] = this . events [ tag ] . filter (
28+ ( event ) => event . callback !== callback
29+ ) ;
30+ }
31+ }
32+
33+ dispatch ( tag ) {
34+ if ( this . events [ tag ] ) {
35+ this . events [ tag ] . forEach ( ( event ) => {
36+ if ( event . options && event . options . params ) {
37+ const fn = self . C3 [ AddonTypeMap [ addonType ] ] [ id ] . Cnds [ tag ] ;
38+ if ( fn && ! fn . call ( this , ...event . options . params ) ) {
39+ return ;
40+ }
41+ }
42+ event . callback ( ) ;
43+ if ( event . options && event . options . once ) {
44+ this . off ( tag , event . callback ) ;
45+ }
46+ } ) ;
47+ }
48+ }
49+
1750 _release ( ) {
1851 super . _release ( ) ;
1952 }
You can’t perform that action at this time.
0 commit comments