Skip to content

Commit c51eb04

Browse files
committed
added examples
1 parent 69ede84 commit c51eb04

File tree

6 files changed

+526
-0
lines changed

6 files changed

+526
-0
lines changed

examples/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"scripts": {
3+
"rei": "rm -rf node_modules && yarn install",
4+
"clear": "rm -rf out",
5+
"build": "npm run clean && tsc -p ./",
6+
"tsc": "tsc -p ./ --noEmit",
7+
"lint": "tslint -p ./"
8+
},
9+
"dependencies": {
10+
"react": "^15.5.4",
11+
"react-dom": "^15.5.4",
12+
"react-redux-typescript": "^2.3.0",
13+
"tslib": "^1.7.0"
14+
},
15+
"devDependencies": {
16+
"@types/react": "^15.0.24",
17+
"@types/react-dom": "^15.5.0",
18+
"tslint": "^5.2.0",
19+
"tslint-react": "^3.0.0",
20+
"typescript": "^2.3.2"
21+
}
22+
}

examples/src/class-component.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as React from 'react';
2+
3+
type Props = {
4+
className?: string,
5+
style?: React.CSSProperties,
6+
initialCount?: number,
7+
};
8+
9+
type State = {
10+
counter: number,
11+
};
12+
13+
class MyComponent extends React.Component<Props, State> {
14+
// default props using Property Initializers
15+
static defaultProps: Partial<Props> = {
16+
className: 'default-class',
17+
};
18+
19+
// initial state using Property Initializers
20+
state: State = {
21+
counter: this.props.initialCount || 0,
22+
};
23+
24+
// lifecycle methods should be declared as normal instance methods and it's fine
25+
componentDidMount() {
26+
// tslint:disable-next-line:no-console
27+
console.log('Mounted!');
28+
}
29+
30+
// handlers using Class Fields with arrow functions
31+
increaseCounter = () => { this.setState({ counter: this.state.counter + 1 }); };
32+
33+
render() {
34+
const { children, initialCount, ...restProps } = this.props;
35+
36+
return (
37+
<div {...restProps} onClick={this.increaseCounter} >
38+
Clicks: {this.state.counter}
39+
<hr />
40+
{children}
41+
</div>
42+
);
43+
}
44+
}
45+
46+
export default MyComponent;

examples/src/stateless-component.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
3+
type Props = {
4+
className?: string,
5+
style?: React.CSSProperties,
6+
};
7+
8+
const MyComponent: React.StatelessComponent<Props> = (props) => {
9+
const { children, ...restProps } = props;
10+
return (
11+
<div {...restProps} >
12+
{children}
13+
</div>
14+
);
15+
};
16+
17+
export default MyComponent;

examples/tsconfig.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "src/", // enables relative imports to root
4+
"outDir": "out/", // target for compiled files
5+
"allowSyntheticDefaultImports": true, // no errors on commonjs default import
6+
"allowJs": true, // include js files
7+
"checkJs": true, // typecheck js files
8+
"declaration": false, // don't emit declarations
9+
"emitDecoratorMetadata": true,
10+
"experimentalDecorators": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"importHelpers": true, // importing helper functions from tslib
13+
"noEmitHelpers": true, // disable emitting inline helper functions
14+
"jsx": "react", // process JSX
15+
"lib": [
16+
"dom",
17+
"es2016",
18+
"es2017.object"
19+
],
20+
"target": "es5",
21+
"module": "es2015",
22+
"moduleResolution": "node",
23+
"noEmitOnError": true,
24+
"noFallthroughCasesInSwitch": true,
25+
"noImplicitAny": true,
26+
"noImplicitReturns": true,
27+
"noImplicitThis": true,
28+
"strictNullChecks": true,
29+
"pretty": true,
30+
"removeComments": true,
31+
"sourceMap": true
32+
},
33+
"include": [
34+
"src/**/*"
35+
],
36+
"exclude": [
37+
"node_modules"
38+
]
39+
}

examples/tslint.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"extends": [
3+
"tslint:latest",
4+
"tslint-react"
5+
],
6+
"rules": {
7+
"arrow-parens": false,
8+
"arrow-return-shorthand": [
9+
false
10+
],
11+
"comment-format": [
12+
true,
13+
"check-space"
14+
],
15+
"import-blacklist": [
16+
true,
17+
"rxjs"
18+
],
19+
"interface-over-type-literal": false,
20+
"member-access": false,
21+
"member-ordering": [
22+
true,
23+
{
24+
"order": "statics-first"
25+
}
26+
],
27+
"newline-before-return": false,
28+
"no-any": false,
29+
"no-inferrable-types": [
30+
true
31+
],
32+
"no-import-side-effect": [
33+
true,
34+
{
35+
"ignore-module": "^rxjs/"
36+
}
37+
],
38+
"no-invalid-this": [
39+
true,
40+
"check-function-in-method"
41+
],
42+
"no-null-keyword": false,
43+
"no-require-imports": false,
44+
"no-switch-case-fall-through": true,
45+
"no-trailing-whitespace": true,
46+
"no-unused-variable": [
47+
true,
48+
"react"
49+
],
50+
"object-literal-sort-keys": false,
51+
"only-arrow-functions": [
52+
true,
53+
"allow-declarations"
54+
],
55+
"ordered-imports": [
56+
false
57+
],
58+
"prefer-method-signature": false,
59+
"prefer-template": [
60+
true,
61+
"allow-single-concat"
62+
],
63+
"quotemark": [
64+
true,
65+
"single",
66+
"jsx-double"
67+
],
68+
"triple-equals": [
69+
true,
70+
"allow-null-check"
71+
],
72+
"typedef": [
73+
true,
74+
"parameter",
75+
"property-declaration",
76+
"member-variable-declaration"
77+
],
78+
"variable-name": [
79+
true,
80+
"ban-keywords",
81+
"check-format",
82+
"allow-pascal-case"
83+
]
84+
}
85+
}

0 commit comments

Comments
 (0)