Skip to content

Commit 2885747

Browse files
committed
Rename 'waiting' to 'initial'.
1 parent 3960837 commit 2885747

File tree

7 files changed

+44
-44
lines changed

7 files changed

+44
-44
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,12 @@ is set to `"application/json"`.
384384
- `initialValue` The data or error that was provided through the `initialValue` prop.
385385
- `startedAt` When the current/last promise was started.
386386
- `finishedAt` When the last promise was resolved or rejected.
387-
- `status` One of: `waiting`, `pending`, `fulfilled`, `rejected`.
388-
- `isWaiting` true when no promise has ever started, or one started but was cancelled.
387+
- `status` One of: `initial`, `pending`, `fulfilled`, `rejected`.
388+
- `isInitial` true when no promise has ever started, or one started but was cancelled.
389389
- `isPending` true when a promise is currently awaiting settlement. Alias: `isLoading`
390390
- `isFulfilled` true when the last promise was fulfilled with a value. Alias: `isResolved`
391391
- `isRejected` true when the last promise was rejected with a reason.
392-
- `isSettled` true when the last promise was fulfilled or rejected (not waiting or pending).
392+
- `isSettled` true when the last promise was fulfilled or rejected (not initial or pending).
393393
- `counter` The number of times a promise was started.
394394
- `cancel` Cancel any pending promise.
395395
- `run` Invokes the `deferFn`.
@@ -431,10 +431,10 @@ Tracks when the last promise was resolved or rejected.
431431

432432
> `string`
433433
434-
One of: `waiting`, `pending`, `fulfilled`, `rejected`.
434+
One of: `initial`, `pending`, `fulfilled`, `rejected`.
435435
These are available for import as `statusTypes`.
436436

437-
#### `isWaiting`
437+
#### `isInitial`
438438

439439
> `boolean`
440440
@@ -466,7 +466,7 @@ Alias: `isResolved`
466466

467467
> `boolean`
468468
469-
`true` when the last promise was either fulfilled or rejected (i.e. not waiting or pending)
469+
`true` when the last promise was either fulfilled or rejected (i.e. not initial or pending)
470470

471471
#### `counter`
472472

@@ -511,7 +511,7 @@ invoked after the state update is completed. Returns the error to enable chainin
511511
React Async provides several helper components that make your JSX more declarative and less cluttered.
512512
They don't have to be direct children of `<Async>` and you can use the same component several times.
513513

514-
### `<Async.Waiting>`
514+
### `<Async.Initial>`
515515

516516
Renders only while the deferred promise is still waiting to be run, or you have not provided any promise.
517517

@@ -524,14 +524,14 @@ Renders only while the deferred promise is still waiting to be run, or you have
524524

525525
```js
526526
<Async deferFn={deferFn}>
527-
<Async.Waiting>
527+
<Async.Initial>
528528
<p>This text is only rendered while `run` has not yet been invoked on `deferFn`.</p>
529-
</Async.Waiting>
529+
</Async.Initial>
530530
</Async>
531531
```
532532

533533
```js
534-
<Async.Waiting persist>
534+
<Async.Initial persist>
535535
{({ error, isLoading, run }) => (
536536
<div>
537537
<p>This text is only rendered while the promise has not resolved yet.</p>
@@ -541,7 +541,7 @@ Renders only while the deferred promise is still waiting to be run, or you have
541541
{error && <p>{error.message}</p>}
542542
</div>
543543
)}
544-
</Async.Waiting>
544+
</Async.Initial>
545545
```
546546

547547
### `<Async.Pending>`

src/Async.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ export const createInstance = (defaultProps = {}, displayName = "Async") => {
179179
}
180180

181181
/**
182-
* Renders only when deferred promise is waiting (promise has not yet run).
182+
* Renders only when no promise has started or completed yet.
183183
*
184184
* @prop {Function|Node} children Function (passing state) or React node
185185
* @prop {boolean} persist Show until we have data, even while pending (loading) or when an error occurred
186186
*/
187-
const Waiting = ({ children, persist }) => (
187+
const Initial = ({ children, persist }) => (
188188
<Consumer>
189189
{state => {
190190
if (state.data !== undefined) return null
@@ -196,7 +196,7 @@ export const createInstance = (defaultProps = {}, displayName = "Async") => {
196196
)
197197

198198
if (PropTypes) {
199-
Waiting.propTypes = {
199+
Initial.propTypes = {
200200
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
201201
persist: PropTypes.bool,
202202
}
@@ -281,7 +281,7 @@ export const createInstance = (defaultProps = {}, displayName = "Async") => {
281281
const Settled = ({ children, persist }) => (
282282
<Consumer>
283283
{state => {
284-
if (state.isWaiting) return null
284+
if (state.isInitial) return null
285285
if (state.isPending && !persist) return null
286286
return isFunction(children) ? children(state) : children || null
287287
}}
@@ -295,14 +295,14 @@ export const createInstance = (defaultProps = {}, displayName = "Async") => {
295295
}
296296
}
297297

298-
Waiting.displayName = `${displayName}.Waiting`
298+
Initial.displayName = `${displayName}.Initial`
299299
Pending.displayName = `${displayName}.Pending`
300300
Fulfilled.displayName = `${displayName}.Fulfilled`
301301
Rejected.displayName = `${displayName}.Rejected`
302302
Settled.displayName = `${displayName}.Settled`
303303

304304
Async.displayName = displayName
305-
Async.Waiting = Waiting
305+
Async.Initial = Initial
306306
Async.Pending = Pending
307307
Async.Loading = Pending // alias
308308
Async.Fulfilled = Fulfilled

src/Async.spec.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ describe("Async", () => {
3131
let two
3232
const { rerender } = render(
3333
<Async>
34-
<Async.Waiting>
34+
<Async.Initial>
3535
{value => {
3636
one = value
3737
}}
38-
</Async.Waiting>
38+
</Async.Initial>
3939
</Async>
4040
)
4141
rerender(
4242
<Async someProp>
43-
<Async.Waiting>
43+
<Async.Initial>
4444
{value => {
4545
two = value
4646
}}
47-
</Async.Waiting>
47+
</Async.Initial>
4848
</Async>
4949
)
5050
expect(one).toBe(two)
@@ -132,19 +132,19 @@ describe("Async.Pending", () => {
132132
})
133133
})
134134

135-
describe("Async.Waiting", () => {
136-
test("renders only while the deferred promise is waiting", async () => {
135+
describe("Async.Initial", () => {
136+
test("renders only while the deferred promise has not started yet", async () => {
137137
const deferFn = () => resolveTo("ok")
138138
const { getByText, queryByText } = render(
139139
<Async deferFn={deferFn}>
140-
<Async.Waiting>{({ run }) => <button onClick={run}>waiting</button>}</Async.Waiting>
140+
<Async.Initial>{({ run }) => <button onClick={run}>initial</button>}</Async.Initial>
141141
<Async.Pending>pending</Async.Pending>
142142
<Async.Fulfilled>done</Async.Fulfilled>
143143
</Async>
144144
)
145-
expect(queryByText("waiting")).toBeInTheDocument()
146-
fireEvent.click(getByText("waiting"))
147-
expect(queryByText("waiting")).toBeNull()
145+
expect(queryByText("initial")).toBeInTheDocument()
146+
fireEvent.click(getByText("initial"))
147+
expect(queryByText("initial")).toBeNull()
148148
expect(queryByText("pending")).toBeInTheDocument()
149149
await waitForElement(() => getByText("done"))
150150
expect(queryByText("pending")).toBeNull()

src/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ interface AbstractState<T> {
3030
setError: (error: Error, callback?: () => void) => Error
3131
}
3232

33-
export type AsyncWaiting<T> = AbstractState<T> & {
33+
export type AsyncInitial<T> = AbstractState<T> & {
3434
data: undefined
3535
error: undefined
3636
startedAt: undefined
3737
finishedAt: undefined
38-
status: "waiting"
39-
isWaiting: false
38+
status: "initial"
39+
isInitial: false
4040
isPending: false
4141
isLoading: false
4242
isFulfilled: false
@@ -50,7 +50,7 @@ export type AsyncPending<T> = AbstractState<T> & {
5050
startedAt: Date
5151
finishedAt: undefined
5252
status: "pending"
53-
isWaiting: false
53+
isInitial: false
5454
isPending: true
5555
isLoading: true
5656
isFulfilled: false
@@ -64,7 +64,7 @@ export type AsyncFulfilled<T> = AbstractState<T> & {
6464
startedAt: Date
6565
finishedAt: Date
6666
status: "fulfilled"
67-
isWaiting: false
67+
isInitial: false
6868
isPending: false
6969
isLoading: false
7070
isFulfilled: true
@@ -78,20 +78,20 @@ export type AsyncRejected<T> = AbstractState<T> & {
7878
startedAt: Date
7979
finishedAt: Date
8080
status: "rejected"
81-
isWaiting: false
81+
isInitial: false
8282
isPending: false
8383
isLoading: false
8484
isFulfilled: false
8585
isResolved: false
8686
isRejected: true
8787
isSettled: true
8888
}
89-
export type AsyncState<T> = AsyncWaiting<T> | AsyncPending<T> | AsyncFulfilled<T> | AsyncRejected<T>
89+
export type AsyncState<T> = AsyncInitial<T> | AsyncPending<T> | AsyncFulfilled<T> | AsyncRejected<T>
9090

9191
declare class Async<T> extends React.Component<AsyncProps<T>, AsyncState<T>> {}
9292

9393
declare namespace Async {
94-
export function Waiting<T>(props: {
94+
export function Initial<T>(props: {
9595
children?: AsyncChildren<T>
9696
persist?: boolean
9797
}): React.ReactNode

src/specs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const common = Async => () => {
1919
expect(renderProps).toHaveProperty("initialValue")
2020
expect(renderProps).toHaveProperty("startedAt")
2121
expect(renderProps).toHaveProperty("finishedAt")
22-
expect(renderProps).toHaveProperty("isWaiting")
22+
expect(renderProps).toHaveProperty("isInitial")
2323
expect(renderProps).toHaveProperty("isPending")
2424
expect(renderProps).toHaveProperty("isLoading")
2525
expect(renderProps).toHaveProperty("isFulfilled")

src/status.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const statusTypes = {
2-
waiting: "waiting",
2+
initial: "initial",
33
pending: "pending",
44
fulfilled: "fulfilled",
55
rejected: "rejected",
@@ -9,18 +9,18 @@ export const getInitialStatus = (value, promise) => {
99
if (value instanceof Error) return statusTypes.rejected
1010
if (value !== undefined) return statusTypes.fulfilled
1111
if (promise) return statusTypes.pending
12-
return statusTypes.waiting
12+
return statusTypes.initial
1313
}
1414

1515
export const getIdleStatus = value => {
1616
if (value instanceof Error) return statusTypes.rejected
1717
if (value !== undefined) return statusTypes.fulfilled
18-
return statusTypes.waiting
18+
return statusTypes.initial
1919
}
2020

2121
export const getStatusProps = status => ({
2222
status,
23-
isWaiting: status === statusTypes.waiting,
23+
isInitial: status === statusTypes.initial,
2424
isPending: status === statusTypes.pending,
2525
isLoading: status === statusTypes.pending, // alias
2626
isFulfilled: status === statusTypes.fulfilled,

src/status.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import "jest-dom/extend-expect"
55
import { getInitialStatus, getIdleStatus, statusTypes } from "./status"
66

77
describe("getInitialStatus", () => {
8-
test("returns 'waiting' when given an undefined value", () => {
9-
expect(getInitialStatus(undefined)).toEqual(statusTypes.waiting)
8+
test("returns 'initial' when given an undefined value", () => {
9+
expect(getInitialStatus(undefined)).toEqual(statusTypes.initial)
1010
})
1111
test("returns 'pending' when given only a promise", () => {
1212
expect(getInitialStatus(undefined, Promise.resolve("foo"))).toEqual(statusTypes.pending)
@@ -20,8 +20,8 @@ describe("getInitialStatus", () => {
2020
})
2121

2222
describe("getIdleStatus", () => {
23-
test("returns 'waiting' when given an undefined value", () => {
24-
expect(getIdleStatus(undefined)).toEqual(statusTypes.waiting)
23+
test("returns 'initial' when given an undefined value", () => {
24+
expect(getIdleStatus(undefined)).toEqual(statusTypes.initial)
2525
})
2626
test("returns 'rejected' when given an Error value", () => {
2727
expect(getIdleStatus(new Error("oops"))).toEqual(statusTypes.rejected)

0 commit comments

Comments
 (0)