Last active
October 25, 2020 19:43
-
-
Save psygo/602f2c06b9125db8d4177180a79513c4 to your computer and use it in GitHub Desktop.
Attempts at Creating Web Components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<h1>Web Component Dart Test</h1> | |
<script src="main.dart.js"> | |
main(); | |
</script> | |
<!-- <app-drawer></app-drawer> --> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JS('window.customElements') | |
library web_components_interop; | |
import 'package:js/js.dart'; | |
@JS('define') | |
external void registerWebComponent(String name, Object constructor, [Map<dynamic, dynamic> options]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:html'; | |
main() { | |
try { | |
// registerWebComponent(GraphButton.tag, GraphButton); | |
document.registerElement(GraphButton.tag, GraphButton); | |
// window.customElements.define('graph-button', GraphButton); | |
final GraphButton button = GraphButton(); | |
document.body.append(button); | |
button.changeInnerHtml(); | |
} catch (e, s) { | |
print(e); | |
print(s); | |
} | |
} | |
class GraphButton extends HtmlElement { | |
static const String tag = 'graph-button'; | |
factory GraphButton() => Element.tag(GraphButton.tag); | |
GraphButton.created() : super.created(); | |
changeInnerHtml() => innerHtml = 'foo'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment