-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
142 lines (116 loc) · 3.93 KB
/
index.d.ts
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
130
131
132
133
134
135
136
137
138
139
140
141
142
import { ComponentType, Node } from 'react'
type KeyValueObject = { [key: string]: any }
type Props = { [prop: string]: any | undefined }
type Action<T, P> = {
type: T,
payload?: P
}
declare var INIT: 'conventional-component/INIT'
declare var RECEIVE_NEXT_PROPS: 'conventional-component/RECEIVE_NEXT_PROPS'
declare var DESTROY: 'conventional-component/DESTROY'
type Init = Action<typeof INIT, Props>
type NextProps = Action<typeof RECEIVE_NEXT_PROPS, Props>
type Destroy = Action<typeof DESTROY, void>
type LifecycleActions = Init | NextProps | Destroy
type ActionCreator<Action> = (...args: Array<any>) => Action
type Identity = string
type WithIdentity<Action> = { identity: Identity } & Action
interface WithIdentityState<ReducerState> {
// @ts-ignore: mountedIdentities is erroring...
mountedIdentities: Array<string>;
[key: string]: ReducerState | undefined;
}
type IdentifierProps = { [key: string]: any }
type Identifier = (props: IdentifierProps) => string
type IdentifierPredicate = (identity: Identity) => boolean
type Reducer<ReducerState, Actions> = (
state: ReducerState,
action: Actions
) => ReducerState
type ComponentActions<A> = { [actionCreatorKey: string]: ActionCreator<A> }
type InitialState = { [key: string]: any }
interface LifecyleStateConfiguration {
shouldDispatchReceiveNextProps: boolean;
}
interface WithLifecycleStateLogicProps {
init: ActionCreator<WithIdentity<Init>>;
receiveNextProps: ActionCreator<WithIdentity<NextProps>>;
destroy: ActionCreator<WithIdentity<Destroy>>;
}
declare var init: WithIdentity<Init>
declare var receiveNextProps: WithIdentity<NextProps>
declare var destroy: WithIdentity<Destroy>
declare function connectToState<S, OP, A>(
reducer: Reducer<S, OP>,
actionCreators: ComponentActions<A>,
initialState: InitialState | void
): <P>(BaseComponent: ComponentType<P>) => ComponentType<P>
type ConventionalActionCreators = {
[actionName: string]: ActionCreator<LifecycleActions | Action<string, any>>
}
type WithLogic = <CTP>(
TemplateComponent: ComponentType<CTP>
) => ComponentType<CTP>
type ComponentName = string
type ComponentKey = string
type ReducerName = string
interface ConventionalConfig {
actions: ConventionalActionCreators;
withLogic: WithLogic;
Template: ComponentType<any>;
reducer: Reducer<any, any>;
REDUCER_NAME?: ReducerName;
COMPONENT_NAME?: ComponentName;
COMPONENT_KEY: ComponentKey;
}
declare function asConnectedComponent<NewProps>(
conventionalConfig: ConventionalConfig
): ComponentType<NewProps>
declare function createIdentifier(
componentName: ComponentName,
propName: string
): Identifier
declare function createIdentifiedActionCreators<Actions>(
identifier: Identifier,
componentActions: ComponentActions<Actions>
)
declare function receiveChildrenAsFunction(props: { children: Function, [key: string]: any }): Node
declare function withActionIdentity<Action extends KeyValueObject>(
actionCreator: ActionCreator<Action>
): ActionCreator<WithIdentity<Action>>
declare function createMapStateToProps<
State extends KeyValueObject,
OwnProps extends KeyValueObject
>(
reducerName: string,
identifier: Identifier,
structuredSelector: Function
)
declare function withReducerIdentity<ReducerState, ReducerActions>(
identifierPredicate: string | IdentifierPredicate,
identifiedReducer: Reducer<ReducerState, ReducerActions>
): (
state: WithIdentityState<ReducerState>,
action: WithIdentity<ReducerActions>
) => WithIdentityState<ReducerState>
declare function withLifecycleStateLogic(
lifecycleStateConfiguration: LifecyleStateConfiguration
): <P>(BaseComponent: ComponentType<P>) => ComponentType<P>
export {
init,
receiveNextProps,
destroy,
INIT,
RECEIVE_NEXT_PROPS,
DESTROY,
asConnectedComponent,
createIdentifier,
createIdentifiedActionCreators,
connectToState,
receiveChildrenAsFunction,
withActionIdentity,
createMapStateToProps,
withReducerIdentity,
withLifecycleStateLogic
}
export default connectToState