Skip to content

Commit a978568

Browse files
committed
fix enum names
1 parent 0512a0c commit a978568

File tree

7 files changed

+49
-49
lines changed

7 files changed

+49
-49
lines changed

packages/react-async-devtools/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react"
2-
import { actionTypes, reducer, globalScope } from "react-async"
2+
import { ActionTypes, reducer, globalScope } from "react-async"
33

44
import { Root, Range, Checkbox, Label, Small, Ol, Li, Button } from "./components"
55

@@ -17,14 +17,14 @@ globalScope.__REACT_ASYNC__.devToolsDispatcher = (action, dispatch) => {
1717
state.update(action)
1818
}
1919
switch (action.type) {
20-
case actionTypes.start:
20+
case ActionTypes.start:
2121
if (state.intercept) {
2222
dispatch({ ...action, payload: undefined })
2323
state.update(action, run)
2424
} else run()
2525
break
26-
case actionTypes.fulfill:
27-
case actionTypes.reject:
26+
case ActionTypes.fulfill:
27+
case ActionTypes.reject:
2828
setTimeout(run, state.latency * 1000)
2929
break
3030
default:

packages/react-async/src/Async.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from "react"
33
import globalScope from "./globalScope"
44
import { IfInitial, IfPending, IfFulfilled, IfRejected, IfSettled } from "./helpers"
55
import propTypes from "./propTypes"
6-
import { actionTypes, init, dispatchMiddleware, reducer as asyncReducer } from "./reducer"
6+
import { ActionTypes, init, dispatchMiddleware, reducer as asyncReducer } from "./reducer"
77
import {
88
AsyncProps,
99
AsyncState,
@@ -176,7 +176,7 @@ export const createInstance = <T extends {}>(
176176
return (this.promise = new Promise((resolve, reject) => {
177177
if (!this.mounted) return
178178
const executor = () => promiseFn().then(resolve, reject)
179-
this.dispatch({ type: actionTypes.start, payload: executor, meta: this.getMeta() })
179+
this.dispatch({ type: ActionTypes.start, payload: executor, meta: this.getMeta() })
180180
}))
181181
}
182182

@@ -212,7 +212,7 @@ export const createInstance = <T extends {}>(
212212
onCancel && onCancel()
213213
this.counter++
214214
this.abortController.abort()
215-
this.mounted && this.dispatch({ type: actionTypes.cancel, meta: this.getMeta() })
215+
this.mounted && this.dispatch({ type: ActionTypes.cancel, meta: this.getMeta() })
216216
}
217217

218218
onResolve(counter: Number) {
@@ -237,14 +237,14 @@ export const createInstance = <T extends {}>(
237237

238238
setData(data: T, callback?: () => void) {
239239
this.mounted &&
240-
this.dispatch({ type: actionTypes.fulfill, payload: data, meta: this.getMeta() }, callback)
240+
this.dispatch({ type: ActionTypes.fulfill, payload: data, meta: this.getMeta() }, callback)
241241
return data
242242
}
243243

244244
setError(error: Error, callback?: () => void) {
245245
this.mounted &&
246246
this.dispatch(
247-
{ type: actionTypes.reject, payload: error, error: true, meta: this.getMeta() },
247+
{ type: ActionTypes.reject, payload: error, error: true, meta: this.getMeta() },
248248
callback
249249
)
250250
return error

packages/react-async/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export { default as Async, createInstance } from "./Async"
33
export * from "./types"
44
export { default as useAsync, useFetch, FetchOptions, FetchError } from "./useAsync"
55
export default Async
6-
export { statusTypes } from "./status"
6+
export { StatusTypes } from "./status"
77
export { default as globalScope } from "./globalScope"
88
export * from "./helpers"
99
export * from "./reducer"

packages/react-async/src/reducer.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInitialStatus, getIdleStatus, getStatusProps, statusTypes } from "./status"
1+
import { getInitialStatus, getIdleStatus, getStatusProps, StatusTypes } from "./status"
22
import {
33
PromiseFn,
44
AsyncAction,
@@ -18,7 +18,7 @@ import {
1818
*/
1919
declare type ImportWorkaround<T> = AbstractState<T>
2020

21-
export enum actionTypes {
21+
export enum ActionTypes {
2222
start = "start",
2323
cancel = "cancel",
2424
fulfill = "fulfill",
@@ -48,16 +48,16 @@ export const init = <T>({
4848

4949
export const reducer = <T>(state: ReducerAsyncState<T>, action: AsyncAction<T>) => {
5050
switch (action.type) {
51-
case actionTypes.start:
51+
case ActionTypes.start:
5252
return {
5353
...state,
5454
startedAt: new Date(),
5555
finishedAt: undefined,
56-
...getStatusProps(statusTypes.pending),
56+
...getStatusProps(StatusTypes.pending),
5757
counter: action.meta.counter,
5858
promise: action.meta.promise,
5959
} as AsyncPending<T, ReducerBaseState<T>>
60-
case actionTypes.cancel:
60+
case ActionTypes.cancel:
6161
return {
6262
...state,
6363
startedAt: undefined,
@@ -69,23 +69,23 @@ export const reducer = <T>(state: ReducerAsyncState<T>, action: AsyncAction<T>)
6969
| AsyncInitial<T, ReducerBaseState<T>>
7070
| AsyncFulfilled<T, ReducerBaseState<T>>
7171
| AsyncRejected<T, ReducerBaseState<T>>
72-
case actionTypes.fulfill:
72+
case ActionTypes.fulfill:
7373
return {
7474
...state,
7575
data: action.payload,
7676
value: action.payload,
7777
error: undefined,
7878
finishedAt: new Date(),
79-
...getStatusProps(statusTypes.fulfilled),
79+
...getStatusProps(StatusTypes.fulfilled),
8080
promise: action.meta.promise,
8181
} as AsyncFulfilled<T, ReducerBaseState<T>>
82-
case actionTypes.reject:
82+
case ActionTypes.reject:
8383
return {
8484
...state,
8585
error: action.payload,
8686
value: action.payload,
8787
finishedAt: new Date(),
88-
...getStatusProps(statusTypes.rejected),
88+
...getStatusProps(StatusTypes.rejected),
8989
promise: action.meta.promise,
9090
} as AsyncRejected<T, ReducerBaseState<T>>
9191
default:
@@ -97,7 +97,7 @@ export const dispatchMiddleware = <T>(
9797
dispatch: (action: AsyncAction<T>, ...args: any[]) => void
9898
) => (action: AsyncAction<T>, ...args: unknown[]) => {
9999
dispatch(action, ...args)
100-
if (action.type === actionTypes.start && typeof action.payload === "function") {
100+
if (action.type === ActionTypes.start && typeof action.payload === "function") {
101101
action.payload()
102102
}
103103
}

packages/react-async/src/status.spec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22

33
import "@testing-library/jest-dom/extend-expect"
44

5-
import { getInitialStatus, getIdleStatus, statusTypes } from "./status"
5+
import { getInitialStatus, getIdleStatus, StatusTypes } from "./status"
66

77
describe("getInitialStatus", () => {
88
test("returns 'initial' when given an undefined value", () => {
9-
expect(getInitialStatus(undefined)).toEqual(statusTypes.initial)
9+
expect(getInitialStatus(undefined)).toEqual(StatusTypes.initial)
1010
})
1111
test("returns 'pending' when given only a promise", () => {
12-
expect(getInitialStatus(undefined, Promise.resolve("foo"))).toEqual(statusTypes.pending)
12+
expect(getInitialStatus(undefined, Promise.resolve("foo"))).toEqual(StatusTypes.pending)
1313
})
1414
test("returns 'rejected' when given an Error value", () => {
15-
expect(getInitialStatus(new Error("oops"))).toEqual(statusTypes.rejected)
15+
expect(getInitialStatus(new Error("oops"))).toEqual(StatusTypes.rejected)
1616
})
1717
test("returns 'fulfilled' when given any other value", () => {
18-
expect(getInitialStatus(null)).toEqual(statusTypes.fulfilled)
18+
expect(getInitialStatus(null)).toEqual(StatusTypes.fulfilled)
1919
})
2020
})
2121

2222
describe("getIdleStatus", () => {
2323
test("returns 'initial' when given an undefined value", () => {
24-
expect(getIdleStatus(undefined)).toEqual(statusTypes.initial)
24+
expect(getIdleStatus(undefined)).toEqual(StatusTypes.initial)
2525
})
2626
test("returns 'rejected' when given an Error value", () => {
27-
expect(getIdleStatus(new Error("oops"))).toEqual(statusTypes.rejected)
27+
expect(getIdleStatus(new Error("oops"))).toEqual(StatusTypes.rejected)
2828
})
2929
test("returns 'fulfilled' when given any other value", () => {
30-
expect(getIdleStatus(null)).toEqual(statusTypes.fulfilled)
30+
expect(getIdleStatus(null)).toEqual(StatusTypes.fulfilled)
3131
})
3232
})

packages/react-async/src/status.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import { PromiseFn } from "./types"
22

3-
export enum statusTypes {
3+
export enum StatusTypes {
44
initial = "initial",
55
pending = "pending",
66
fulfilled = "fulfilled",
77
rejected = "rejected",
88
}
99

1010
export const getInitialStatus = <T>(value?: T | Error, promise?: Promise<T> | PromiseFn<T>) => {
11-
if (value instanceof Error) return statusTypes.rejected
12-
if (value !== undefined) return statusTypes.fulfilled
13-
if (promise) return statusTypes.pending
14-
return statusTypes.initial
11+
if (value instanceof Error) return StatusTypes.rejected
12+
if (value !== undefined) return StatusTypes.fulfilled
13+
if (promise) return StatusTypes.pending
14+
return StatusTypes.initial
1515
}
1616

1717
export const getIdleStatus = <T>(value?: T | Error) => {
18-
if (value instanceof Error) return statusTypes.rejected
19-
if (value !== undefined) return statusTypes.fulfilled
20-
return statusTypes.initial
18+
if (value instanceof Error) return StatusTypes.rejected
19+
if (value !== undefined) return StatusTypes.fulfilled
20+
return StatusTypes.initial
2121
}
2222

23-
export const getStatusProps = (status: statusTypes) => ({
23+
export const getStatusProps = (status: StatusTypes) => ({
2424
status,
25-
isInitial: status === statusTypes.initial,
26-
isPending: status === statusTypes.pending,
27-
isLoading: status === statusTypes.pending, // alias
28-
isFulfilled: status === statusTypes.fulfilled,
29-
isResolved: status === statusTypes.fulfilled, // alias
30-
isRejected: status === statusTypes.rejected,
31-
isSettled: status === statusTypes.fulfilled || status === statusTypes.rejected,
25+
isInitial: status === StatusTypes.initial,
26+
isPending: status === StatusTypes.pending,
27+
isLoading: status === StatusTypes.pending, // alias
28+
isFulfilled: status === StatusTypes.fulfilled,
29+
isResolved: status === StatusTypes.fulfilled, // alias
30+
isRejected: status === StatusTypes.rejected,
31+
isSettled: status === StatusTypes.fulfilled || status === StatusTypes.rejected,
3232
})

packages/react-async/src/useAsync.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useCallback, useDebugValue, useEffect, useMemo, useRef, useReducer } from "react"
22

33
import globalScope from "./globalScope"
4-
import { actionTypes, init, dispatchMiddleware, reducer as asyncReducer } from "./reducer"
4+
import { ActionTypes, init, dispatchMiddleware, reducer as asyncReducer } from "./reducer"
55

66
import {
77
AsyncOptions,
@@ -88,7 +88,7 @@ function useAsync<T extends {}>(
8888
(data, callback = noop) => {
8989
if (isMounted.current) {
9090
dispatch({
91-
type: actionTypes.fulfill,
91+
type: ActionTypes.fulfill,
9292
payload: data,
9393
meta: getMeta(),
9494
})
@@ -103,7 +103,7 @@ function useAsync<T extends {}>(
103103
(error, callback = noop) => {
104104
if (isMounted.current) {
105105
dispatch({
106-
type: actionTypes.reject,
106+
type: ActionTypes.reject,
107107
payload: error,
108108
error: true,
109109
meta: getMeta(),
@@ -138,7 +138,7 @@ function useAsync<T extends {}>(
138138
if (!isMounted.current) return
139139
const executor = () => promiseFn().then(resolve, reject)
140140
dispatch({
141-
type: actionTypes.start,
141+
type: ActionTypes.start,
142142
payload: executor,
143143
meta: getMeta(),
144144
})
@@ -185,7 +185,7 @@ function useAsync<T extends {}>(
185185
abortController.current.abort()
186186
isMounted.current &&
187187
dispatch({
188-
type: actionTypes.cancel,
188+
type: ActionTypes.cancel,
189189
meta: getMeta(),
190190
})
191191
}, [onCancel, dispatch, getMeta])

0 commit comments

Comments
 (0)