lila/ui/round/src/main.ts

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-04-24 06:57:06 -06:00
import { Chessground } from 'chessground';
2017-04-24 11:43:35 -06:00
import { init } from 'snabbdom';
import { VNode } from 'snabbdom/vnode'
import klass from 'snabbdom/modules/class';
import attributes from 'snabbdom/modules/attributes';
2017-07-08 06:49:10 -06:00
import { RoundOpts } from './interfaces';
import RoundController from './ctrl';
2017-07-09 03:30:02 -06:00
import MoveOn from './moveOn';
2017-07-08 16:22:48 -06:00
import { main as view } from './view/main';
2017-08-16 18:39:52 -06:00
import * as chat from 'chat';
2017-07-09 03:30:02 -06:00
import boot from './boot';
2017-07-08 06:49:10 -06:00
2017-07-09 03:30:02 -06:00
export interface RoundApi {
socketReceive(typ: string, data: any): boolean;
moveOn: MoveOn;
}
2017-07-12 07:38:36 -06:00
export interface RoundMain {
app: (opts: RoundOpts) => RoundApi;
}
2017-07-09 03:30:02 -06:00
export function app(opts: RoundOpts): RoundApi {
2017-04-24 11:43:35 -06:00
2017-07-28 17:51:27 -06:00
const patch = init([klass, attributes]);
2017-07-08 06:49:10 -06:00
let vnode: VNode, ctrl: RoundController;
2017-04-24 11:43:35 -06:00
function redraw() {
2017-07-08 16:22:48 -06:00
vnode = patch(vnode, view(ctrl));
2017-04-24 11:43:35 -06:00
}
2017-04-24 06:57:06 -06:00
2017-07-08 06:49:10 -06:00
ctrl = new RoundController(opts, redraw);
2017-04-24 06:57:06 -06:00
2017-07-08 16:22:48 -06:00
const blueprint = view(ctrl);
2017-04-25 16:29:55 -06:00
opts.element.innerHTML = '';
vnode = patch(opts.element, blueprint);
2017-04-24 06:57:06 -06:00
return {
2017-04-24 11:43:35 -06:00
socketReceive: ctrl.socket.receive,
moveOn: ctrl.moveOn
2017-04-24 06:57:06 -06:00
};
};
2017-04-24 07:18:00 -06:00
export { boot };
2017-08-16 18:39:52 -06:00
window.LichessChat = chat;
2017-04-24 06:57:06 -06:00
// that's for the rest of lichess to access chessground
// without having to include it a second time
window.Chessground = Chessground;