@ -8,6 +8,37 @@ define('hooks', [], () => {
deprecated : {
} ,
logs : {
_collection : new Set ( ) ,
} ,
} ;
Hooks . logs . collect = ( ) => {
if ( Hooks . logs . _collection ) {
return ;
}
Hooks . logs . _collection = new Set ( ) ;
} ;
Hooks . logs . log = ( ... args ) => {
if ( Hooks . logs . _collection ) {
Hooks . logs . _collection . add ( args ) ;
} else {
console . log . apply ( console , args ) ;
}
} ;
Hooks . logs . flush = ( ) => {
if ( Hooks . logs . _collection && Hooks . logs . _collection . size ) {
console . groupCollapsed ( '[hooks] Changes to hooks on this page …' ) ;
Hooks . logs . _collection . forEach ( ( args ) => {
console . log . apply ( console , args ) ;
} ) ;
console . groupEnd ( ) ;
}
delete Hooks . logs . _collection ;
} ;
Hooks . register = ( hookName , method ) => {
@ -27,7 +58,7 @@ define('hooks', [], () => {
console . groupEnd ( ) ;
}
console. debu g( ` [hooks] Registered ${ hookName } ` , method ) ;
Hooks. logs . lo g( ` [hooks] Registered ${ hookName } ` , method ) ;
} ;
Hooks . on = Hooks . register ;
Hooks . one = ( hookName , method ) => {
@ -51,9 +82,9 @@ define('hooks', [], () => {
Hooks . unregister = ( hookName , method ) => {
if ( Hooks . loaded [ hookName ] && Hooks . loaded [ hookName ] . has ( method ) ) {
Hooks . loaded [ hookName ] . delete ( method ) ;
console. debu g( ` [hooks] Unregistered ${ hookName } ` , method ) ;
Hooks. logs . lo g( ` [hooks] Unregistered ${ hookName } ` , method ) ;
} else {
console. debu g( ` [hooks] Unregistration of ${ hookName } failed, passed-in method is not a registered listener or the hook itself has no listeners, currently. ` ) ;
Hooks. logs . lo g( ` [hooks] Unregistration of ${ hookName } failed, passed-in method is not a registered listener or the hook itself has no listeners, currently. ` ) ;
}
} ;
Hooks . off = Hooks . unregister ;