Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit b808795

Browse files
committed
initial version of jspm sample
1 parent 723baaf commit b808795

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

jspm/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
**Install and initialize jspm**
2+
```
3+
npm install -g jspm@beta
4+
jspm init
5+
6+
```
7+
Pick default answer for all questions except `Which ES6 transpiler would you like to use?`, as an answer type `typescript`.
8+
9+
**run:**
10+
- install http-server package via
11+
```
12+
npm install -g http-server
13+
```
14+
- run server (if port 8080 it taken, pick any port that is free)
15+
```
16+
http-server -p 8080
17+
```

jspm/app.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Greeter } from 'greeter'
2+
3+
export function main(el: HTMLElement): void {
4+
let greeter = new Greeter(el);
5+
greeter.start();
6+
}

jspm/greeter.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export class Greeter
2+
{
3+
element: HTMLElement;
4+
span: HTMLElement;
5+
timerToken: number;
6+
7+
constructor (element: HTMLElement)
8+
{
9+
this.element = element;
10+
this.element.innerText += "The time is: ";
11+
this.span = document.createElement('span');
12+
this.element.appendChild(this.span);
13+
this.span.innerText = new Date().toUTCString();
14+
}
15+
16+
start()
17+
{
18+
this.timerToken = setInterval(() => this.span.innerText = new Date().toUTCString(), 500);
19+
}
20+
21+
stop()
22+
{
23+
clearTimeout(this.timerToken);
24+
}
25+
}

jspm/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<html>
2+
<head>
3+
<title>Jspm sample</title>
4+
<script src="jspm_packages/system.src.js"></script>
5+
<script src="config.js"></script>
6+
</head>
7+
<body>
8+
<div id="content"></div>
9+
<script>
10+
System.config({
11+
"paths": {
12+
"app.js":"app.ts",
13+
"greeter.js":"greeter.ts"
14+
}
15+
});
16+
System.import('app').then(function(m) {
17+
var element = document.getElementById("content");
18+
m.main(element);
19+
});
20+
</script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)