Skip to content

Commit d7f0ab3

Browse files
authored
Merge pull request #85 from github/fix-controller-call-bind-this-after-initial-connectedcallback
fix(controller): call bind(this) after initial connectedCallback
2 parents aa74e83 + d544151 commit d7f0ab3

3 files changed

Lines changed: 4 additions & 52 deletions

File tree

src/controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {register} from './register'
22
import {bind} from './bind'
33
import {autoShadowRoot} from './auto-shadow-root'
4-
import {wrap} from './wrap'
54

65
interface CustomElement {
76
new (): HTMLElement
@@ -14,10 +13,12 @@ interface CustomElement {
1413
* wrapping the classes `connectedCallback` method if needed.
1514
*/
1615
export function controller(classObject: CustomElement): void {
17-
wrap(classObject.prototype, 'connectedCallback', function (this: HTMLElement) {
16+
const connect = classObject.prototype.connectedCallback
17+
classObject.prototype.connectedCallback = function (this: HTMLElement) {
1818
this.toggleAttribute('data-catalyst', true)
1919
autoShadowRoot(this)
20+
if (connect) connect.call(this)
2021
bind(this)
21-
})
22+
}
2223
register(classObject)
2324
}

src/wrap.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/wrap.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)