-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js.flow
More file actions
129 lines (107 loc) 路 5.25 KB
/
Copy pathindex.js.flow
File metadata and controls
129 lines (107 loc) 路 5.25 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// @flow
/* eslint-disable no-undef */
/* --------------------------------------------------------------------------------------------- */
/* Common used types */
/* --------------------------------------------------------------------------------------------- */
declare type Extended$SetState<Values, Props> = (
$Shape<Values> | ((state: Values, props: Props) => $Shape<Values>),
) => void;
declare type Extended$State<Values, Mutators> = Values & Mutators;
declare type Extended$StateDefinition<Values, Mutators> = {
initial: Values,
mutators: (Extended$SetState<Values, any>) => Mutators,
};
/* --------------------------------------------------------------------------------------------- */
/* React component types for the future */
/* --------------------------------------------------------------------------------------------- */
// declare class Extended$React$Component<Props, AdvancedState = void> extends React$Component<
// Props,
// $Shape<AdvancedState>,
// > {}
// declare type Extended$React$FunctionalComponent<Props, AdvancedState = void> = {
// ...React$StatelessFunctionalComponent<Props>,
// (props: Props, state: AdvancedState): React$Node,
// };
// declare type Extended$React$ComponentType<Props, AdvancedState> =
// | Extended$React$FunctionalComponent<Props, AdvancedState>
// | Class<Extended$React$Component<Props, AdvancedState>>;
/* --------------------------------------------------------------------------------------------- */
/* Module type */
/* --------------------------------------------------------------------------------------------- */
declare module 'extended-components' {
// HOC
declare type HOC<Props, AdvancedState: {}> = <Component: React$ComponentType<Props>>(
Component,
) => Component;
// Export defaultProps
// ----------------------------------------------------------------------------------------------
// TODO: Fix it. DefaultProps type does not copy statics, so it always has to be used after
// WithStatics.
/* eslint-disable flowtype/generic-spacing */
declare type ExtractRequiredProps<Props, Values> = $Exact<
$Diff<Props, $ObjMap<Values, <V>(V) => any>>,
>;
declare type ExtractDefaultProps<Props, Values> = $Exact<
$Diff<Props, ExtractRequiredProps<Props, Values>>,
>;
// PseudoDefaultProps will always be of type {}, it just checks if Values is a type subset of
// Props. Maybe this check will be possible without a pseudo check like this someday.
declare type PseudoCheckDefaultProps<Props, Values> = $Exact<
$Diff<Values, ExtractDefaultProps<Props, Values>>,
>;
declare type ComponentWithDefaultProps<Props, Values> = React$ComponentType<
$Diff<Props, PseudoCheckDefaultProps<Props, Values> & $ObjMap<Values, <V>(V) => any>>,
>;
/* eslint-enable */
declare type DefaultProps = <Values, Component: React$ComponentType<*>>(
defaultProps: Values,
) => (
ComponentWithoutDefaultProps: Component,
) => ComponentWithDefaultProps<React$ElementProps<Component>, Values>;
// Export getDerivedStateFromProps
// ----------------------------------------------------------------------------------------------
// TODO: Fix it. Inner function with props and state does not work.
declare type GetDerivedStateFromProps = <Props, AdvancedState>(
(nextProps: Props, prevState: AdvancedState) => void,
) => HOC<Props, AdvancedState>;
// Export lifecycle
// ----------------------------------------------------------------------------------------------
// TODO: Fix it. Inner function with props and state does not work.
declare type Lifecycle = <Props, AdvancedState>(
(
props: Props,
state: AdvancedState,
) => $Exact<{
componentDidMount?: () => void,
shouldComponentUpdate?: (nextProps: Props, nextState: AdvancedState) => boolean,
componentDidUpdate?: (prevProps: Props, prevState: AdvancedState) => void,
componentWillUnmount?: () => void,
}>,
) => HOC<Props, AdvancedState>;
// Export pure
// ----------------------------------------------------------------------------------------------
declare type Pure = <Props, AdvancedState>() => HOC<Props, AdvancedState>;
// Export withState
// ----------------------------------------------------------------------------------------------
declare type WithState = <Props, AdvancedState>({
[string]: Extended$StateDefinition<any, any>,
}) => HOC<Props, AdvancedState>;
// Export statics
// ----------------------------------------------------------------------------------------------
declare type ComponentWithStatics<Props, Values> =
| (React$StatelessFunctionalComponent<Props> & Values)
| (Class<React$Component<Props>> & Values);
declare type Statics = <Values, Props>(
statics: Values,
) => (ComponentWithoutStatics: React$ComponentType<Props>) => ComponentWithStatics<Props, Values>;
declare module.exports: {
compose: $Compose,
defaultProps: DefaultProps,
getDerivedStateFromProps: GetDerivedStateFromProps,
lifecycle: Lifecycle,
pure: Pure,
withState: WithState,
statics: Statics,
};
}
/* eslint-enable */