Skip to content

Instantly share code, notes, and snippets.

@davros85
Created October 17, 2016 09:51
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/2ed81a50fb738e1c2ce9696663e935f8 to your computer and use it in GitHub Desktop.
Save davros85/2ed81a50fb738e1c2ce9696663e935f8 to your computer and use it in GitHub Desktop.
import * as ko from 'knockout';
// ...other imports omitted...
import { EventBus } from './EventBus';
let _instance: number = 0;
export default class CoffeeRoundWebPart extends BaseClientSideWebPart<any> {
private _id: number;
private eventBus = EventBus.getInstance();
public constructor(context: IWebPartContext) {
super(context);
this._id = _instance++;
}
private initWorkaround():void{
const tagName: string = `CoffeeRoundComponent-${this._id}`;
const componentElement: HTMLElement = this._createComponentElement(tagName);
this._registerComponent(tagName);
this.domElement.appendChild(componentElement);
var vm = new CoffeeRoundViewModel();
ko.applyBindings(vm, this.domElement);
}
public render(): void {
console.log('render');
if (!this.renderedOnce)
{
this.initWorkaround();
}
// push vals into eventbus with new values
this.eventBus.myProp(this.properties.myProp || '');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment