Skip to content

Instantly share code, notes, and snippets.

@davros85
Created October 17, 2016 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davros85/62cbc43c9c0380cb90c2210b4b7029a3 to your computer and use it in GitHub Desktop.
Save davros85/62cbc43c9c0380cb90c2210b4b7029a3 to your computer and use it in GitHub Desktop.
// remove everything else in constructor, except the super call
public constructor(context: IWebPartContext) {
super(context);
this._id = _instance++;
}
// create your own 'init' function, to be called a little later in the lifecycle:
private doInitStuff() : void
{
const tagName: string = `ComponentElement-${this._id}`;
const componentElement: HTMLElement = this._createComponentElement(tagName);
this._registerComponent(tagName);
this.domElement.appendChild(componentElement);
const bindings: IHelloWorldBindingContext = {
description: this.properties.description,
shouter: this._shouter
};
ko.applyBindings(bindings, this.domElement);
this._koDescription.subscribe((newValue: string) => {
this._shouter.notifySubscribers(newValue, 'description');
});
}
// update the render method to do init too
public render(): void {
if ( !this.renderedOnce )
{
this.doInitStuff();
}
this._koDescription(this.properties.description);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment