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

Commit 0d50006

Browse files
committed
Add jsx/react sample
1 parent 120a409 commit 0d50006

File tree

12 files changed

+4254
-0
lines changed

12 files changed

+4254
-0
lines changed

jsx/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/*
2+
node_modules/*

jsx/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# jsx-demo
2+
3+
## Overview
4+
A demo project for showing off JSX in TypeScript
5+
6+
## Install dependencies
7+
```
8+
npm install
9+
```
10+
11+
## Compile
12+
```
13+
node node_modules/typescript/bin/tsc
14+
```
15+
16+
## Start http server
17+
```
18+
node node_modules/http-server/bin/http-server -o
19+
```
20+

jsx/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>JSX and TypeScript</title>
5+
<script src="node_modules/requirejs/require.js" data-main="bin/app"></script>
6+
<script src="require-config.js"></script>
7+
</head>
8+
<body>
9+
<div id="output"></div>
10+
</body>
11+
</html>

jsx/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "jsx-demo",
3+
"version": "0.0.1",
4+
"description": "JSX in TypeScript Demo Project",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/RyanCavanaugh/jsx-demo.git"
12+
},
13+
"keywords": [
14+
"jsx",
15+
"tsx",
16+
"typescript",
17+
"ts",
18+
"react"
19+
],
20+
"author": "Ryan Cavanaugh (Microsoft)",
21+
"license": "Apache",
22+
"bugs": {
23+
"url": "https://github.com/RyanCavanaugh/jsx-demo/issues"
24+
},
25+
"homepage": "https://github.com/RyanCavanaugh/jsx-demo",
26+
"devDependencies": {
27+
"typescript": "latest",
28+
"http-server": "0.8.0"
29+
},
30+
"dependencies": {
31+
"jquery": "^2.1.4",
32+
"react": "^0.13.3",
33+
"requirejs": "^2.1.20"
34+
}
35+
}

jsx/require-config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
requirejs.config({
2+
paths: {
3+
react: ['/node_modules/react/dist/react'],
4+
jquery: ['/node_modules/jquery/dist/jquery']
5+
}
6+
});

jsx/src/app.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React = require('react');
2+
import $ = require('jquery');
3+
import {Greeter as Greetifier, GreeterProps as GreeterProps} from 'greeter';
4+
5+
function getRandomGreeting() {
6+
switch(Math.floor(Math.random() * 4)) {
7+
case 0: return 'Hello';
8+
case 1: return 'Howdy';
9+
case 2: return 'Greetings to you';
10+
case 3: return 'Hail';
11+
}
12+
}
13+
14+
$(() => {
15+
let props: GreeterProps = {
16+
whomToGreet: 'world!',
17+
};
18+
19+
React.render(<Greetifier {...props} />, $('#output').get(0));
20+
});
21+

jsx/src/greeter.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React = require('react');
2+
3+
export interface GreeterProps extends React.Props<Greeter> {
4+
whomToGreet: string;
5+
greeting?: string|(() => string);
6+
}
7+
8+
export class Greeter extends React.Component<GreeterProps, {}> {
9+
render() {
10+
let g = this.props.greeting;
11+
12+
let greeting = 'Hello';
13+
if(typeof g === 'string') {
14+
greeting = g;
15+
} else if(g) {
16+
greeting = g();
17+
}
18+
19+
return <div>{greeting}, {this.props.whomToGreet}</div>;
20+
}
21+
}

jsx/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react",
4+
"outDir": "bin",
5+
"module": "amd"
6+
},
7+
"exclude": [
8+
"node_modules"
9+
]
10+
}

jsx/tsd.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "v4",
3+
"repo": "borisyankov/DefinitelyTyped",
4+
"ref": "master",
5+
"path": "typings",
6+
"bundle": "typings/tsd.d.ts",
7+
"installed": {
8+
"react/react.d.ts": {
9+
"commit": "77ec1408257c677f8fd8d6798ebaf6bd87c11b9d"
10+
},
11+
"jquery/jquery.d.ts": {
12+
"commit": "77ec1408257c677f8fd8d6798ebaf6bd87c11b9d"
13+
}
14+
}
15+
}

jsx/typings/jquery/jquery.d.ts

Lines changed: 3174 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)