Skip to content

Commit ae63ee5

Browse files
more updates
1 parent 05a8554 commit ae63ee5

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

demo/typescriptImport/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import {Configuration} from "../../src/Configuration";
33
import {Route} from "../../src/Route";
44

55
function createDemo() {
6+
const configuration = new Configuration()
7+
configuration.defaultRoute = ""
8+
const router = new WarpRouter('.container', configuration)
69
let routes: Map<string,Route> = new Map()
710
routes.set("", new Route(function () {
811
return "This is the home page"
912
}))
10-
routes.set("#page1", new Route(function () {
11-
return "This uses a custom context"
12-
}))
13+
routes.set("#page1", new Route(() => {
14+
router.hostElement.innerHTML = `<p>This content was generated by a routing function</p>`
15+
}
16+
))
1317

14-
const configuration = new Configuration()
15-
configuration.defaultRoute = ""
16-
const component = new WarpRouter('.container', routes, configuration)
18+
router.setRoutes(routes)
1719
}
1820

1921
createDemo()

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "warp-router",
3-
"version": "0.1.1",
3+
"version": "0.1.3",
44
"description": "",
55
"main": "build/warp-router.js",
66
"types": "build/src/WarpRouter.d.ts",
@@ -31,7 +31,7 @@
3131
"html-webpack-plugin": "^2.24.1",
3232
"ts-loader": "^1.0.0",
3333
"typescript": "^2.1.5",
34-
"webpack": "2.2.0-rc.7",
34+
"webpack": "^2.2.0",
3535
"webpack-build-notifier": "^0.1.13"
3636
}
3737
}

src/WarpRouter.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@ import {Configuration} from "./Configuration";
22
import {Route} from "./Route";
33
export default class WarpRouter {
44

5-
private hostElement: HTMLElement
5+
public hostElement: HTMLElement
6+
public routes: Map<string, Route>
7+
68

79
/**
810
*
911
* @param selector where the router will be embedded
1012
* @param routes can take a function that will generate a string
1113
*/
1214
constructor(public selector: string,
13-
public routes: Map<string, Route>,
1415
public configuration: Configuration = new Configuration()) {
15-
1616
this.hostElement = <HTMLElement> document.querySelector(selector)
17+
1718
if (!window.location.hash && configuration.defaultRoute !== null) {
1819
window.location.hash = configuration.defaultRoute
1920
}
20-
this.applyRouteContentFunction(window.location.hash)
21-
this.addListeners()
2221
}
2322

23+
setRoutes(routes: Map<string, Route>) {
24+
this.routes = routes
25+
}
2426

2527
applyRouteContentFunction(routeString: string) {
2628
try {
@@ -40,5 +42,9 @@ export default class WarpRouter {
4042
this.applyRouteContentFunction(window.location.hash)
4143
});
4244
}
45+
46+
attach() {
47+
this.addListeners()
48+
}
4349
}
4450

0 commit comments

Comments
 (0)