Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Rename and enhance AtomicComponent.init #666

Open
anselmbradford opened this issue Oct 19, 2017 · 0 comments
Open

Rename and enhance AtomicComponent.init #666

anselmbradford opened this issue Oct 19, 2017 · 0 comments

Comments

@anselmbradford
Copy link
Member

Current behavior

  • AtomicComponent.init does not convey that it is for querying the whole document for a component and does not allow attaching a callback to an element.

Expected behavior

  • @sebworks suggested this structure by renaming the method for clarity and including an HTMLNode and callback function as a parameter:
AtomicComponent.instantiateAll = function( dom, callback ) {
  var elements = ( dom || document ).querySelectorAll( this.selector );
  var element;
  var components = [];
  for ( var i = 0; i < elements.length; ++i ) {
    element = elements[i];
    if ( element.hasAttribute( 'data-bound' ) === false ) {
      var instance = new this( element );
      components.push( instance );
      callback ( index, instance)
    }
  }
  return components;
};
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant