Skip to content

Commit 29fcf7a

Browse files
authored
Merge pull request #47 from Lemoncode/#45-hooks-implementation
#45 hooks implementation
2 parents 96861ae + c14e1d5 commit 29fcf7a

163 files changed

Lines changed: 3707 additions & 275 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/launch.json

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
{
2-
"version": "0.2.0",
3-
"configurations": [
4-
{
5-
"type": "node",
6-
"request": "launch",
7-
"name": "Jest single run",
8-
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
9-
"args": [
10-
"--verbose",
11-
"-i"
12-
],
13-
"console": "integratedTerminal",
14-
"internalConsoleOptions": "neverOpen"
15-
},
16-
]
17-
}
1+
2+
{
3+
"version": "0.2.0",
4+
"configurations": [
5+
{
6+
"type": "node",
7+
"request": "launch",
8+
"name": "Jest single run",
9+
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
10+
"args": [
11+
"--verbose",
12+
"-i",
13+
"--no-cache"
14+
],
15+
"console": "integratedTerminal",
16+
"internalConsoleOptions": "neverOpen"
17+
},
18+
{
19+
"type": "node",
20+
"request": "launch",
21+
"name": "Jest watch run",
22+
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
23+
"args": [
24+
"--verbose",
25+
"-i",
26+
"--no-cache",
27+
"--watchAll"
28+
],
29+
"console": "integratedTerminal",
30+
"internalConsoleOptions": "neverOpen"
31+
}
32+
]
33+
}

examples/00-example-basic/.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
"@babel/preset-react",
4+
[
5+
"@babel/preset-env",
6+
{
7+
"useBuiltIns": "entry"
8+
}
9+
]
10+
]
11+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "webpack-by-example",
3+
"version": "1.0.0",
4+
"description": "In this sample we are going to setup a web project that can be easily managed\r by webpack.",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "webpack-dev-server --mode development --open",
8+
"build": "rimraf dist && webpack --mode development",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@babel/cli": "^7.2.3",
15+
"@babel/core": "^7.4.0",
16+
"@babel/preset-env": "^7.4.0",
17+
"@babel/preset-react": "^7.0.0",
18+
"babel-loader": "^8.0.5",
19+
"css-loader": "^2.1.1",
20+
"html-webpack-plugin": "^3.2.0",
21+
"mini-css-extract-plugin": "^0.5.0",
22+
"rimraf": "^2.6.3",
23+
"style-loader": "^0.23.1",
24+
"webpack": "^4.29.6",
25+
"webpack-cli": "^3.3.0",
26+
"webpack-dev-server": "^3.2.1"
27+
},
28+
"dependencies": {
29+
"react": "^16.8.4",
30+
"react-dom": "^16.8.4",
31+
"react-loader-spinner": "^2.3.0",
32+
"react-promise-tracker": "file:../../"
33+
}
34+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const fetchWithDelay = (url) => {
2+
const promise = new Promise((resolve, reject) => {
3+
setTimeout(() => {
4+
resolve(fetch(url, {
5+
method: 'GET',
6+
})
7+
.then((response) => response.json()));
8+
}, 3000)
9+
});
10+
11+
return promise;
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { fetchWithDelay } from './fetch';
2+
const url = 'https://jsonplaceholder.typicode.com/posts';
3+
4+
const fetchPosts = () => fetchWithDelay(url)
5+
.then((posts) => posts.slice(0, 10));
6+
7+
export const postAPI = {
8+
fetchPosts,
9+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { fetchWithDelay } from './fetch';
2+
const url = 'https://jsonplaceholder.typicode.com/users';
3+
4+
const fetchUsers = () => fetchWithDelay(url);
5+
6+
export const userAPI = {
7+
fetchUsers,
8+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.tables {
2+
display: flex;
3+
flex-direction: row;
4+
flex-wrap: nowrap;
5+
}
6+
7+
.tables > div {
8+
flex-basis: 50%;
9+
margin-left: 1rem;
10+
margin-right: 1rem;
11+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React, { Component } from 'react';
2+
import { trackPromise } from 'react-promise-tracker';
3+
import { userAPI } from './api/userAPI';
4+
import { postAPI } from './api/postAPI';
5+
import { UserTable, PostTable, LoadButton } from './components';
6+
import './app.css';
7+
8+
export class App extends Component {
9+
constructor() {
10+
super();
11+
12+
this.state = {
13+
users: [],
14+
posts: [],
15+
};
16+
17+
this.onLoadTables = this.onLoadTables.bind(this);
18+
}
19+
20+
onLoadTables() {
21+
this.setState({
22+
users: [],
23+
posts: [],
24+
});
25+
26+
trackPromise(
27+
userAPI.fetchUsers()
28+
.then((users) => {
29+
this.setState({
30+
users,
31+
})
32+
})
33+
);
34+
35+
trackPromise(
36+
postAPI.fetchPosts()
37+
.then((posts) => {
38+
this.setState({
39+
posts,
40+
})
41+
})
42+
);
43+
}
44+
45+
render() {
46+
return (
47+
<div>
48+
<LoadButton
49+
onLoad={this.onLoadTables}
50+
title="Load tables with delay"
51+
/>
52+
<div className="tables">
53+
<UserTable users={this.state.users} />
54+
<PostTable posts={this.state.posts} />
55+
</div>
56+
</div>
57+
);
58+
}
59+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './spinner';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.spinner {
2+
width: 100%;
3+
height: 100%;
4+
}
5+
6+
.spinner > div {
7+
display: flex;
8+
justify-content: center;
9+
align-items: center;
10+
}

0 commit comments

Comments
 (0)