Skip to content

Commit 7f39b1a

Browse files
committed
Added options object for optional router in app object
1 parent 2b22b0d commit 7f39b1a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/app.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { mountDOM } from "./mount-dom";
22
import { destroyDOM } from './destroy-dom'
33
import { hElement } from "./h";
4+
import { NoopRouter } from "./routing/hash-router";
45

5-
export function createApp(RootComponent, props = {}) {
6+
export function createApp(RootComponent, props = {}, options = {}) {
67
let parentEl = null;
78
let isMounted = false;
89
let vdom = null;
910

11+
const context = {
12+
router: options.router || new NoopRouter(),
13+
}
14+
1015
// Reset internal properties of the app.
1116
function reset() {
1217
parentEl = null;
@@ -21,15 +26,18 @@ export function createApp(RootComponent, props = {}) {
2126
}
2227
parentEl = _parentEl;
2328
vdom = hElement(RootComponent, props);
24-
mountDOM(vdom, parentEl);
29+
// mountDOM(vdom, parentEl);
30+
mountDOM(vdom, parentEl, null, { appContext: context });
2531

32+
context.router.init();
2633
isMounted = true;
2734
},
2835
unmount() {
2936
if (!isMounted) {
3037
throw new Error('The application is not mounted');
3138
}
3239
destroyDOM(vdom);
40+
context.router.destroy();
3341
reset();
3442
}
3543
}

0 commit comments

Comments
 (0)