Created
October 17, 2016 09:23
-
-
Save davros85/62cbc43c9c0380cb90c2210b4b7029a3 to your computer and use it in GitHub Desktop.
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
// 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