/
custom_element.js
34 lines (32 loc) · 1.35 KB
/
custom_element.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) 2019 the Rampage Project Authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by a zlib license that can be found in
// the LICENSE file.
class CustomElementInterop {
constructor() {
this.constructorCallbacks = {};
this.connectedCallback = (d) => { throw new Error('connectedCallback not set') };
this.disconnectedCallback = (d) => { throw new Error('disconnectedCallback not set') };
this.attributeChangedCallback = (d, attr, oldVal, newVal) => { throw new Error('attributeChangedCallback not set') };
}
define(name, construct, observed) {
let that = this;
customElements.define(name, class extends HTMLElement {
constructor() {
super();
this.dartObject = construct(this);
}
connectedCallback() {
that.connectedCallback(this.dartObject);
}
disconnectedCallback() {
that.disconnectedCallback(this.dartObject);
}
attributeChangedCallback(attr, oldVal, newVal) {
that.attributeChangedCallback(this.dartObject, attr, oldVal, newVal);
}
static get observedAttributes() { return observed; }
});
}
}
window.CustomElementInterop = CustomElementInterop;