Skip to content

Commit ef8deff

Browse files
author
Lenz Weber
committed
alias AsyncState<T> & AsyncConstructor<T> for readability
1 parent 2cb5c78 commit ef8deff

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/react-async/src/Async.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ export const createInstance = <T extends {}>(
8585
}
8686

8787
type Props = AsyncProps<T>
88+
type State = AsyncState<T>
89+
type Constructor = AsyncConstructor<T>
8890

89-
class Async extends React.Component<Props, AsyncState<T>> {
91+
class Async extends React.Component<Props, State> {
9092
private mounted = false
9193
private counter = 0
9294
private args: any[] = []
@@ -108,7 +110,7 @@ export const createInstance = <T extends {}>(
108110
this.setError = this.setError.bind(this)
109111

110112
const promise = props.promise
111-
const promiseFn = props.promiseFn || defaultProps.promiseFn
113+
const promiseFn = props.promiseFn || defaultProps.promiseFConstructorn
112114
const initialValue = props.initialValue || defaultProps.initialValue
113115

114116
this.state = {
@@ -269,7 +271,7 @@ export const createInstance = <T extends {}>(
269271
render() {
270272
const { children } = this.props
271273
if (typeof children === "function") {
272-
const render = children as (state: AsyncState<T>) => React.ReactNode
274+
const render = children as (state: State) => React.ReactNode
273275
return <Provider value={this.state}>{render(this.state)}</Provider>
274276
}
275277
if (children !== undefined && children !== null) {
@@ -281,19 +283,19 @@ export const createInstance = <T extends {}>(
281283

282284
if (propTypes) (Async as React.ComponentClass).propTypes = propTypes.Async
283285

284-
const AsyncInitial: AsyncConstructor<T>["Initial"] = props => (
286+
const AsyncInitial: Constructor["Initial"] = props => (
285287
<Consumer>{st => <IfInitial {...props} state={st} />}</Consumer>
286288
)
287-
const AsyncPending: AsyncConstructor<T>["Pending"] = props => (
289+
const AsyncPending: Constructor["Pending"] = props => (
288290
<Consumer>{st => <IfPending {...props} state={st} />}</Consumer>
289291
)
290-
const AsyncFulfilled: AsyncConstructor<T>["Fulfilled"] = props => (
292+
const AsyncFulfilled: Constructor["Fulfilled"] = props => (
291293
<Consumer>{st => <IfFulfilled {...props} state={st} />}</Consumer>
292294
)
293-
const AsyncRejected: AsyncConstructor<T>["Rejected"] = props => (
295+
const AsyncRejected: Constructor["Rejected"] = props => (
294296
<Consumer>{st => <IfRejected {...props} state={st} />}</Consumer>
295297
)
296-
const AsyncSettled: AsyncConstructor<T>["Settled"] = props => (
298+
const AsyncSettled: Constructor["Settled"] = props => (
297299
<Consumer>{st => <IfSettled {...props} state={st} />}</Consumer>
298300
)
299301

0 commit comments

Comments
 (0)