Skip to content

Instantly share code, notes, and snippets.

@kylebuch8
Last active March 20, 2019 17:13
Show Gist options
  • Save kylebuch8/41cddb6eae056094486191bf03fcf6a9 to your computer and use it in GitHub Desktop.
Save kylebuch8/41cddb6eae056094486191bf03fcf6a9 to your computer and use it in GitHub Desktop.
Simple PFElement Constructor with delayRender
// the location of pfelement.js may be different if you're not building an element in the
// PatternFly elements repository
import PFElement from "../pfelement/pfelement.js";
class MySimplePfelement extends PFElement {
constructor() {
// make sure we call super() first with the class we're using
// as the first argument
// the second argument in super() is an object with delayRender: true
// because we don't want the HTML template to be rendered immediately
super(MySimplePfelement, { delayRender: true });
this.data = {};
this._fetchData();
}
_fetchData() {
fetch("someapi.json")
.then(res => res.json())
.then(() => this._handleFetch);
}
_handleFetch(data) {
this.data = data;
// be sure to call this when you are ready for the HTML template
// to be displayed in the shadow root
// render() is a method on the PFElement class
this.render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment