Skip to content

Commit 3d450b4

Browse files
committed
Rename 'actions' to 'actionTypes'.
1 parent 2f8ba3b commit 3d450b4

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/Async.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react"
2-
import { actions, init, reducer } from "./reducer"
2+
import { actionTypes, init, reducer } from "./reducer"
33

44
let PropTypes
55
try {
@@ -83,7 +83,7 @@ export const createInstance = (defaultProps = {}, displayName = "Async") => {
8383
this.abortController = new window.AbortController()
8484
}
8585
this.counter++
86-
this.dispatch({ type: actions.start, meta: { counter: this.counter } })
86+
this.dispatch({ type: actionTypes.start, meta: { counter: this.counter } })
8787
}
8888

8989
load() {
@@ -118,7 +118,7 @@ export const createInstance = (defaultProps = {}, displayName = "Async") => {
118118
cancel() {
119119
this.counter++
120120
this.abortController.abort()
121-
this.dispatch({ type: actions.cancel, meta: { counter: this.counter } })
121+
this.dispatch({ type: actionTypes.cancel, meta: { counter: this.counter } })
122122
}
123123

124124
onResolve(counter) {
@@ -142,12 +142,13 @@ export const createInstance = (defaultProps = {}, displayName = "Async") => {
142142
}
143143

144144
setData(data, callback) {
145-
this.mounted && this.dispatch({ type: actions.fulfill, payload: data }, callback)
145+
this.mounted && this.dispatch({ type: actionTypes.fulfill, payload: data }, callback)
146146
return data
147147
}
148148

149149
setError(error, callback) {
150-
this.mounted && this.dispatch({ type: actions.reject, payload: error, error: true }, callback)
150+
this.mounted &&
151+
this.dispatch({ type: actionTypes.reject, payload: error, error: true }, callback)
151152
return error
152153
}
153154

src/reducer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const actions = {
1+
export const actionTypes = {
22
start: "start",
33
cancel: "cancel",
44
fulfill: "fulfill",
@@ -17,30 +17,30 @@ export const init = ({ initialValue, promise, promiseFn }) => ({
1717

1818
export const reducer = (state, { type, payload, meta }) => {
1919
switch (type) {
20-
case actions.start:
20+
case actionTypes.start:
2121
return {
2222
...state,
2323
isLoading: true,
2424
startedAt: new Date(),
2525
finishedAt: undefined,
2626
counter: meta.counter,
2727
}
28-
case actions.cancel:
28+
case actionTypes.cancel:
2929
return {
3030
...state,
3131
isLoading: false,
3232
startedAt: undefined,
3333
counter: meta.counter,
3434
}
35-
case actions.fulfill:
35+
case actionTypes.fulfill:
3636
return {
3737
...state,
3838
data: payload,
3939
error: undefined,
4040
isLoading: false,
4141
finishedAt: new Date(),
4242
}
43-
case actions.reject:
43+
case actionTypes.reject:
4444
return {
4545
...state,
4646
error: payload,

src/useAsync.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useCallback, useDebugValue, useEffect, useMemo, useRef, useReducer } from "react"
2-
import { actions, init, reducer } from "./reducer"
2+
import { actionTypes, init, reducer } from "./reducer"
33

44
const noop = () => {}
55

@@ -17,15 +17,15 @@ const useAsync = (arg1, arg2) => {
1717

1818
const setData = (data, callback = noop) => {
1919
if (isMounted.current) {
20-
dispatch({ type: actions.fulfill, payload: data })
20+
dispatch({ type: actionTypes.fulfill, payload: data })
2121
callback()
2222
}
2323
return data
2424
}
2525

2626
const setError = (error, callback = noop) => {
2727
if (isMounted.current) {
28-
dispatch({ type: actions.reject, payload: error, error: true })
28+
dispatch({ type: actionTypes.reject, payload: error, error: true })
2929
callback()
3030
}
3131
return error
@@ -42,7 +42,7 @@ const useAsync = (arg1, arg2) => {
4242
abortController.current = new window.AbortController()
4343
}
4444
counter.current++
45-
dispatch({ type: actions.start, meta: { counter: counter.current } })
45+
dispatch({ type: actionTypes.start, meta: { counter: counter.current } })
4646
}
4747

4848
const load = () => {
@@ -75,7 +75,7 @@ const useAsync = (arg1, arg2) => {
7575
const cancel = () => {
7676
counter.current++
7777
abortController.current.abort()
78-
dispatch({ type: actions.cancel, meta: { counter: counter.current } })
78+
dispatch({ type: actionTypes.cancel, meta: { counter: counter.current } })
7979
}
8080

8181
useEffect(() => {

0 commit comments

Comments
 (0)