forked from yysun/apprun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
28 lines (23 loc) · 919 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import app from './app';
import { createElement, render } from './vdom';
import { Component } from './component';
import Router from './router';
import { on, update } from './decorator';
export type Model = any;
export type View = (model: Model) => string | Function;
export type Action = (model: Model, ...p) => Model;
export type Update = { [name: string]: Action };
app.createElement = createElement;
app.render = render;
app.start = (element: HTMLElement | string, model: Model, view: View, update: Update, options?: { history }) => {
const opts = Object.assign(options || {}, { render: true, global_event: true} )
const component = new Component(model, view, update);
component.mount(element, opts);
return component;
}
if (typeof window === 'object') {
window['app'] = app;
document.addEventListener("DOMContentLoaded", () => new Router());
}
export default app;
export { Component, on, update };