runem / web-component-analyzer

CLI that analyzes web components and emits documentation
https://runem.github.io/web-component-analyzer
MIT License
504 stars 64 forks source link

Support for Private/Internal events #126

Closed kylewelsby closed 4 years ago

kylewelsby commented 4 years ago

I have come across a scenario where I would like to emit an event from a host element to a child element in reaction to something which is intended to be internal only and not display in the documented output.

Perhaps using the @private tag as referenced in #106

Example:

@customElement('testing')
export default class Testing extends LitElement {
  render() {
    return html`<child-element></child-element>`
  }
  firstUpdated() {
    let child = document.querySelector('child-element')
    setTimeout(() => {
      child.dispatchEvent(new CustomEvent('ping'))
    }, 1000)
  }
}

Expected:

omit eventName ping from the documentation.

runem commented 4 years ago

Hi Kyle, thanks for opening this issue and thanks for using WCA!

I agree that this is needed :+1: I have implemented it on the branch https://github.com/runem/web-component-analyzer/tree/refactor and is being tracked with the issue https://github.com/runem/web-component-analyzer/issues/125

In future you will be able to mark you events private or protected using jsdoc private like this:

@customElement('testing')
export default class Testing extends LitElement {
  render() {
    return html`<child-element></child-element>`
  }
  firstUpdated() {
    let child = document.querySelector('child-element')
    setTimeout(() => {
      /**
       * @private
       */
      child.dispatchEvent(new CustomEvent('ping'))
    }, 1000)
  }
}

I will close this issue when it has been released :sunny: