Skip to content

Commit 79ed87e

Browse files
Code at the end of the live stream: https://www.youtube.com/watch?v=i5smyibHf5o
1 parent ae63ee5 commit 79ed87e

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

demo/typescriptImport/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
import WarpRouter from 'warp-router'
22
import {Configuration} from "../../src/Configuration";
33
import {Route} from "../../src/Route";
4+
import {myFunction} from "./page2";
45

56
function createDemo() {
67
const configuration = new Configuration()
78
configuration.defaultRoute = ""
89
const router = new WarpRouter('.container', configuration)
910
let routes: Map<string,Route> = new Map()
10-
routes.set("", new Route(function () {
11+
routes.set("", new Route((): string => {
1112
return "This is the home page"
1213
}))
13-
routes.set("#page1", new Route(() => {
14-
router.hostElement.innerHTML = `<p>This content was generated by a routing function</p>`
14+
routes.set("#page1", new Route((): void => {
15+
router.hostElement.innerHTML = `<p>This content was generated by a routing function page 1</p>`
16+
}
17+
))
18+
routes.set("#page2", new Route((): void => {
19+
myFunction(router.hostElement)
1520
}
1621
))
1722

1823
router.setRoutes(routes)
24+
25+
26+
router.attach()
1927
}
2028

2129
createDemo()

demo/typescriptImport/page2.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const myFunction = (hostElement) => {
2+
hostElement.innerHTML = `
3+
<p>This content was generated by a routing function page 2</p>
4+
<button id="page2btn">This button will do something</button>
5+
`
6+
7+
function addListeners() {
8+
document.querySelector('#page2btn').addEventListener('click', function () {
9+
alert("It workew")
10+
})
11+
}
12+
13+
addListeners()
14+
}

src/Route.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export class Route {
66
constructor(public routingFunction: RoutingFunction, public context= null) {
77

88
}
9+
10+
run(){
11+
return this.routingFunction()
12+
}
913
}

0 commit comments

Comments
 (0)