Skip to content

Commit

Permalink
Launcher: Add callback param to render and fromUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Feb 16, 2018
1 parent a6fad1f commit ef144d1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ts/Launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ export default class Launcher {
}
}

public get fullscreenSupported(): boolean {
public get fullscreenSupported(): boolean | null {
if (!this.ref) {
return null;
}
return this.ref.isFullscreenAvailable();
}

Expand All @@ -288,7 +291,7 @@ export default class Launcher {
return this;
}

public fromUrl(url: string): Launcher {
public fromUrl(url: string, cb?: () => any): Launcher {
let decoder = new HSReplayDecoder();
decoder.debug = this.opts.debug;
let tracker = new GameStateTracker();
Expand Down Expand Up @@ -385,7 +388,7 @@ export default class Launcher {

this.opts.startupTime = +Date.now();
this.ready = true;
this.render();
this.render(cb);

this.track("starting_from_turn", {fromTurn: this.startFromTurn ? true : false, turn: +this.startFromTurn});

Expand Down Expand Up @@ -433,17 +436,22 @@ export default class Launcher {
});
}

protected render(): void {
protected render(cb?: () => any): void {
if (!this.ready) {
return;
}
ReactDOM.render(
<GameWidget {...Object.assign({}, this.opts, { ref: (ref) => this.ref = ref })} /> as any,
typeof this.target === "string" ? document.getElementById(this.target as string) : this.target,
() => {
if (this.cards) {
this.ref.setCards(this.cards);
this.cards = null;
}
if(typeof cb === "function" && cb()) {
cb();
}
}
);
if (this.cards) {
this.ref.setCards(this.cards);
this.cards = null;
}
}
}

0 comments on commit ef144d1

Please sign in to comment.