packages/js-toolkit/abstracts/Base/events.js
/**
 * Bind event handler methods to children Base instance.
 * @param  {Base}  instance     A Base instance.
 * @param  {Array} eventMethods A list of methods to bind.
 * @return {Array}              A list of unbind functions.
 */
Bind event handler methods to children Base instance.
@param  {Base}  instance     A Base instance.
@param  {Array} eventMethods A list of methods to bind.
@return {Array}              A list of unbind functions.
Bind event handler methods to children Base instance . @param { Base } instance A Base instance . @param { Array } eventMethods A list of methods to bind . @return { Array } A list of unbind functions .
function bindChildrenEvents(instance, eventMethods) {
  const unbindMethods = [];
  Object.entries(instance.$children).forEach(([childName, $children]) => {
    const childEventMethod = `on${childName.replace(/^\w/, (c) => c.toUpperCase())}`;
    eventMethods
      .filter((eventMethod) => eventMethod.startsWith(childEventMethod))
      .forEach((eventMethod) => {
        $children.forEach(
          ($child, index) => {
            const eventName = eventMethod.replace(childEventMethod, '').toLowerCase();
            const handler = (...args) => {
              if (__DEV__) {
                debug(instance, eventMethod, $child, ...args, index);
              }
              instance[eventMethod](...args, index);
            };
            if (__DEV__) {
              debug(instance, 'binding child event', childName, eventName);
            }
            const unbindMethod = $child.$on(eventName, handler);
            unbindMethods.push(() => {
              if (__DEV__) {
                debug(instance, 'unbinding child event', childName, eventName);
              }
              unbindMethod();
            });
          }
        );
      });
  });
  return unbindMethods;
}
function bindChildrenEvents ( instance , eventMethods ) { const unbindMethods = [ ] ; Object . entries ( instance . $children ) . forEach ( ( [ childName , $children ] ) => { const childEventMethod = ` ${ childName . replace ( / ^\w / , ( c ) => c . toUpperCase ( ) ) } ` ; eventMethods . filter ( ( eventMethod ) => eventMethod . startsWith ( childEventMethod ) ) . forEach ( ( eventMethod ) => { $children . forEach ( ( $child , index ) => { const eventName = eventMethod . replace ( childEventMethod , '' ) . toLowerCase ( ) ; const handler = ( ... args ) => { if ( __DEV__ ) { debug ( instance , eventMethod , $child , ... args , index ) ; } instance [ eventMethod ] ( ... args , index ) ; } ; if ( __DEV__ ) { debug ( instance , 'binding child event' , childName , eventName ) ; } const unbindMethod = $child . $on ( eventName , handler ) ; unbindMethods . push ( ( ) => { if ( __DEV__ ) { debug ( instance , 'unbinding child event' , childName , eventName ) ; } unbindMethod ( ) ; } ) ; } ) ; } ) ; } ) ; return unbindMethods ; }
Bind event handler methods to children Base instance.
Bind event handler methods to children Base instance .
/**
           * @param {Base} $child
           * @param {Number} index
           */