packages/js-toolkit/abstracts/Base/events.js
/**
 * Bind ref and children component's events to their corresponding method.
 *
 * @param  {Base} instance  A Base instance.
 * @return {Array}          A list of methods to unbind the events.
 */
Bind ref and children component's events to their corresponding method.
@param  {Base} instance  A Base instance.
@return {Array}          A list of methods to unbind the events.
Bind ref and children component ' s events to their corresponding method . @param { Base } instance A Base instance . @return { Array } A list of methods to unbind the events .
function bindEvents(instance) {
  const ROOT_EVENT_REGEX = /^on[A-Z][a-z]+$/;
  const REFS_CHILDREN_EVENT_REGEX = /^on([A-Z][a-z]+)([A-Z][a-z]+)+$/;
  const eventMethods = getAllProperties(instance).reduce(
    (acc, [name]) => {
      if (ROOT_EVENT_REGEX.test(name) && !acc.root.includes(name)) {
        acc.root.push(name);
        return acc;
      }
      if (REFS_CHILDREN_EVENT_REGEX.test(name) && !acc.refsOrChildren.includes(name)) {
        acc.refsOrChildren.push(name);
      }
      return acc;
    },
    { root: [], refsOrChildren: [] }
  );
  const unbindMethods = [
    ...bindRootEvents(instance, eventMethods.root),
    ...bindRefsEvents(instance, eventMethods.refsOrChildren),
    ...bindChildrenEvents(instance, eventMethods.refsOrChildren),
  ];
  return unbindMethods;
}
function bindEvents ( instance ) { const ROOT_EVENT_REGEX = / ^on[A-Z][a-z]+$ / ; const REFS_CHILDREN_EVENT_REGEX = / ^on([A-Z][a-z]+)([A-Z][a-z]+)+$ / ; const eventMethods = getAllProperties ( instance ) . reduce ( ( acc , [ name ] ) => { if ( ROOT_EVENT_REGEX . test ( name ) && ! acc . root . includes ( name ) ) { acc . root . push ( name ) ; return acc ; } if ( REFS_CHILDREN_EVENT_REGEX . test ( name ) && ! acc . refsOrChildren . includes ( name ) ) { acc . refsOrChildren . push ( name ) ; } return acc ; } , { root : [ ] , refsOrChildren : [ ] } ) ; const unbindMethods = [ ... bindRootEvents ( instance , eventMethods . root ) , ... bindRefsEvents ( instance , eventMethods . refsOrChildren ) , ... bindChildrenEvents ( instance , eventMethods . refsOrChildren ) , ] ; return unbindMethods ; }
Bind ref and children component's events to their corresponding method.
Bind ref and children component ' s events to their corresponding method .
// Get all event methods // Testing camelCase with one word: onEvent. // Testing camelCase with more than two words: onRefEvent.