lila/ui/msg/src/main.ts

29 lines
620 B
TypeScript

import view from './view';
import { init } from 'snabbdom';
import { VNode } from 'snabbdom/vnode'
import klass from 'snabbdom/modules/class';
import attributes from 'snabbdom/modules/attributes';
import { MsgOpts } from './interfaces'
import MsgCtrl from './ctrl';
const patch = init([klass, attributes]);
export function app(element: HTMLElement, opts: MsgOpts) {
let vnode: VNode, ctrl: MsgCtrl;
function redraw() {
vnode = patch(vnode, view(ctrl));
}
ctrl = new MsgCtrl(opts, redraw);
const blueprint = view(ctrl);
element.innerHTML = '';
vnode = patch(element, blueprint);
redraw();
};