Skip to content

Commit 297e898

Browse files
committed
2 parents 7cc4deb + ae6d72b commit 297e898

53 files changed

Lines changed: 1750 additions & 11 deletions

Some content is hidden

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

hooks/05_Refactor/Readme.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,50 @@ export const App = () => {
163163
};
164164
```
165165

166+
- Now let's jump into _NameEditComponent_ and update the contract and
167+
implementation:
168+
169+
```diff
170+
interface Props {
171+
initialUserName: string;
172+
+ editingName: string;
173+
- onNameUpdated: (newName: string) => any;
174+
+ onNameUpdated: () => any;
175+
+ onEditingNameUpdated: (newEditingName: string) => any;
176+
}
177+
```
178+
179+
```diff
180+
export const NameEditComponent = (props: Props) => {
181+
- const [editingName, setEditingName] = React.useState(props.initialUserName);
182+
183+
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
184+
- setEditingName(e.target.value);
185+
+ props.onEditingNameUpdated(e.target.value);
186+
};
187+
188+
const onNameSubmit = (event: any): any => {
189+
- props.onNameUpdated(editingName);
190+
+ props.onNameUpdated();
191+
};
192+
193+
- if(props.initialUserName !== lastInitialName) {
194+
- setLastInitialName(props.initialUserName);
195+
- setEditingName(props.initialUserName);
196+
- }
197+
198+
199+
return (
200+
<>
201+
<label>Update name:</label>
202+
- <input value={editingName} onChange={onChange} />
203+
+ <input value={props.editingName} onChange={onChange} />
204+
<button onClick={onNameSubmit}>Change</button>
205+
</>
206+
);
207+
};
208+
```
209+
166210
# About Basefactor + Lemoncode
167211

168212
We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.
@@ -172,4 +216,3 @@ We are an innovating team of Javascript experts, passionate about turning your i
172216
[Lemoncode](http://lemoncode.net/services/en/#en-home) provides training services.
173217

174218
For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend
175-

hooks/08_ColorPickerRefactor/Readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 09 Colorpicker Refactor
1+
# 08 Colorpicker Refactor
22

33
In this example we are going to review the colorpicker component we have created and simplify it. Right now we have three slider controls with many details that make our HTML hard to read. Let's componentize this scenario.
44

@@ -219,13 +219,13 @@ export const ColorPicker = (props: Props) => {
219219
}
220220
```
221221

222-
- Now we got a great result !! we have enhanced code quality in our component.
222+
- Now we got a great result!! We have enhanced code quality in our component.
223223

224224
```bash
225225
npm start
226226
```
227227

228-
- Could we go one step furhter refactoring? The answer is yes, could it be worth? That's
228+
- Could we go one step further refactoring? The answer is yes, could it be worth? That's
229229
worth a discussion, sometimes is a good idea to keep on refactoring, and then rollback
230230
one step, let's apply the following trick, let's replace our color picker with this code:
231231

hooks/13_LoginForm/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ _./src/pages/loginPage.tsx_
424424
```diff
425425
interface PropsForm {
426426
onLogin: () => void;
427-
+ onUpdateField: (string, any) => void;
427+
+ onUpdateField: (name: string, value: any) => void;
428428
+ loginInfo : LoginEntity;
429429
}
430430

hooks/13_LoginForm/src/pages/loginPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const LoginPage = withStyles(styles)(withRouter<Props>(LoginPageInner));
7070

7171
interface PropsForm {
7272
onLogin: () => void;
73-
onUpdateField: (string, any) => void;
73+
onUpdateField: (name: string, value: any) => void;
7474
loginInfo: LoginEntity;
7575
}
7676

hooks/14_FormValidation/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const loginFormValidation = createFormValidation(
108108

109109
- Let's create now a class to hold the dataFormErrors.
110110

111-
_./src/login/loginPage.viewmodel.ts_
111+
_./src/pages/loginPage.viewmodel.ts_
112112

113113
```typescript
114114
import { FieldValidationResult } from "lc-form-validation";

hooks/15_Context/Readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const createDefaultUser = (): SessionContextProps => ({
3232
});
3333

3434
export const SessionContext =
35-
React.createContext < SessionContextProps > createDefaultUser();
35+
React.createContext < SessionContextProps >(createDefaultUser());
3636
```
3737

3838
- This session context will expose a _provider_ (it will serve us to set the login name in the context), and a _consumer_ (that will let us consume the login name from the context at any point of the application).
@@ -122,8 +122,8 @@ import { Link } from "react-router-dom";
122122
_./src/pages/loginPage.tsx_
123123

124124
```diff
125-
+ import { TextFieldForm } from "../common";
126-
import { TextFieldForm, SessionContext } from "../common";
125+
- import { TextFieldForm } from "../common";
126+
+ import { TextFieldForm, SessionContext } from "../common";
127127

128128
```
129129

hooks/15_Context/src/common/sessionContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const SessionContext = React.createContext<SessionContextProps>(
1818
createDefaultUser()
1919
);
2020

21-
export const SessionProvider: React.StatelessComponent = props => {
21+
export const SessionProvider: React.FunctionComponent = props => {
2222
const [login, setLogin] = React.useState<string>("");
2323

2424
return (
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"modules": false
7+
}
8+
]
9+
]
10+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "react-typescript-samples",
3+
"version": "1.0.0",
4+
"description": "Sample working with React,TypeScript and Webpack)",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "webpack-dev-server --mode development --inline --hot --open",
9+
"build": "webpack --mode development"
10+
},
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@material-ui/core": "^3.9.0",
15+
"@material-ui/icons": "^3.0.2",
16+
"@types/react": "^16.4.7",
17+
"@types/react-dom": "^16.0.6",
18+
"@types/react-router-dom": "^4.3.0",
19+
"@types/toastr": "^2.1.35",
20+
"awesome-typescript-loader": "^5.2.0",
21+
"babel-core": "^6.26.3",
22+
"babel-preset-env": "^1.7.0",
23+
"css-loader": "^1.0.0",
24+
"file-loader": "^1.1.11",
25+
"html-webpack-plugin": "^3.2.0",
26+
"mini-css-extract-plugin": "^0.4.1",
27+
"style-loader": "^0.21.0",
28+
"url-loader": "^1.0.1",
29+
"webpack": "^4.16.2",
30+
"webpack-cli": "^3.1.0",
31+
"webpack-dev-server": "^3.1.5"
32+
},
33+
"dependencies": {
34+
"bootstrap": "^4.1.2",
35+
"lc-form-validation": "^1.0.0",
36+
"react": "16.7.0-alpha.0",
37+
"react-dom": "16.7.0-alpha.0",
38+
"react-router-dom": "^4.2.2",
39+
"toastr": "^2.1.4",
40+
"typescript": "^3.0.1"
41+
}
42+
}

0 commit comments

Comments
 (0)