-
Notifications
You must be signed in to change notification settings - Fork 0
/
108.tsx
107 lines (61 loc) · 1.7 KB
/
108.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// # A Few Extra Tips
// ---
// SLIDE
// ---
// ## Type the JSON object
// eslint-disable-next-line
interface _Stringified<T> { }
type Stringified<T> = string & _Stringified<T>;
declare interface JSON {
parse<T = any>(text: Stringified<T>, reviver?: (key: string, value: any) => any): T;
stringify<T = any>(value: T, replacer?: (key: string, value: any) => any, space?: string | number): Stringified<T>;
stringify<T = any>(value: T, replacer?: (number | string)[] | null, space?: string | number): Stringified<T>;
}
// ---
// SLIDE
// ---
// ## Export your constants `as const`
// ...so you can mouseover their value
export const APP_MIN_WIDTH = 420 as const;
// and will get a deep readonly:
export const GUEST = {
ACCOUNT: { id: -1 },
PERMISSIONS: ['read'],
PERMISSIONS_AS_STRING: ['read'] as ReadonlyArray<string>,
} as const;
// ---
// SLIDE
// ---
// ## How to write connected props
// store.ts
interface RootStoreState {
targetReducer: {
lookup: {
[id: string]: { id: number; name: string; };
};
};
}
// ComponentToConnect/index.tsx
import * as React from 'react';
import { connect, ConnectedProps } from 'react-redux';
interface OwnProps {
id: number;
}
function mapStateToProps(rootState: RootStoreState, ownProps: OwnProps) {
return {
value: rootState.targetReducer.lookup[ownProps.id]
}
}
const connector = connect(mapStateToProps);
type Props = OwnProps & ConnectedProps<typeof connector>;
class ComponentToConnect extends React.Component<Props> {}
// ---
// SLIDE
// ---
// ## Final words
// 1. Mouseover everything
// 2. Don't be afraid to enter the d.ts files
// 3. Take your time
// ---
// FIN
// ---