Skip to content
This repository was archived by the owner on Jan 8, 2019. It is now read-only.

Commit 484d109

Browse files
committed
make it works on react components
1 parent 4fec3d2 commit 484d109

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ main.js
4343
main.js.map
4444

4545
.idea
46+
47+
database.sqlite

app/app.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
<body>
1919
<div id="root"></div>
2020
<script>
21-
// var typeorm = require("typeorm");
22-
// typeorm.createConnection().then(() => {
21+
var typeorm = require("typeorm");
22+
typeorm.createConnection()
23+
// .then(() => {
2324
// var post = {
2425
// name: "name 1"
2526

app/components/Counter.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import * as React from 'react';
2-
import { RouteComponentProps } from 'react-router';
3-
import { Link } from 'react-router-dom';
1+
import * as React from 'react'
2+
import { RouteComponentProps } from 'react-router'
3+
import { Link } from 'react-router-dom'
4+
// import * as orm from 'typeorm'
45

5-
let styles = require('./Counter.scss');
6+
let styles = require('./Counter.scss')
7+
8+
const orm = (window as any).typeorm
69

710
export interface IProps extends RouteComponentProps<any> {
811
increment(): void,
@@ -13,8 +16,21 @@ export interface IProps extends RouteComponentProps<any> {
1316
}
1417

1518
export class Counter extends React.Component<IProps> {
19+
async componentDidMount () {
20+
try {
21+
const data = {
22+
name: 'Roman'
23+
}
24+
await orm.getRepository('user').save(data)
25+
const result = await orm.getRepository('user').find()
26+
console.log(result)
27+
} catch (e) {
28+
console.log(e)
29+
}
30+
}
31+
1632
render() {
17-
const { increment, incrementIfOdd, incrementAsync, decrement, counter } = this.props;
33+
const { increment, incrementIfOdd, incrementAsync, decrement, counter } = this.props
1834
return (
1935
<div>
2036
<div className={styles.backButton} data-tid="backButton">
@@ -36,8 +52,8 @@ export class Counter extends React.Component<IProps> {
3652
<button className={styles.btn} onClick={() => incrementAsync()} data-tclass="btn">async</button>
3753
</div>
3854
</div>
39-
);
55+
)
4056
}
4157
}
4258

43-
export default Counter;
59+
export default Counter

app/components/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default class Home extends React.Component {
99
<div>
1010
<div className={styles.container} data-tid="container">
1111
<h2>Home</h2>
12-
<Link to="/counter">to Counter</Link>
12+
<Link to="/counter">Click to Counter</Link>
1313
</div>
1414
</div>
1515
);

app/main.development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,4 @@ app.on('ready', () => {
270270
mainWindow.setMenu(menu);
271271
}
272272
})
273-
});
273+
});

database.sqlite

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)