Re: [WICG/webcomponents] [element-internals] How to get internals in base class and subclass, without leaking it to public (Issue #962)

The work-arounds for this, for now, are to either override `attachInternals`:

```js
class Base extends HTMLElement {
  #internals
  #internalsCalled = false

  constructor() {
    super()
    this.attachInternals()
    this.#internalsCalled = false
  }

  attachInternals() {
    if (this.#internals && !this.#internalsCalled) {
      this.#internalsCalled = true
      return this.#internals
    }
    this.#internals = super.attachInternals()
    this.#internalsCalled = true
    return this.#internals
  }

}
```

Or to provide some agreed upon interface in your own libraries, like `getInternals()`, which breaks the privacy contract around `attachInternals` unless you're able to use TypeScript's `protected` property in all code.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/962#issuecomment-1195391839
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/962/1195391839@github.com>

Received on Tuesday, 26 July 2022 12:01:46 UTC