Unified · Split
| @@ -5,14 +5,20 @@ import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"; · 4 unmodified lines | ||
| 5 | 5 | import { isAsyncResultLoading } from "./async-result"; |
| 6 | 6 | |
| 7 | 7 | describe("isAsyncResultLoading", () => { |
| 8 | − it("treats initial and waiting async results as loading", () => { | |
| 8 | + it("treats initial and waiting-without-value async results as loading", () => { | |
| 9 | 9 | expect(isAsyncResultLoading(AsyncResult.initial())).toBe(true); |
| 10 | 10 | expect(isAsyncResultLoading(AsyncResult.initial(true))).toBe(true); |
| 11 | − expect(isAsyncResultLoading(AsyncResult.success(["cached"], { waiting: true }))).toBe(true); | |
| 11 | + expect(isAsyncResultLoading(AsyncResult.failure(Cause.fail("boom"), { waiting: true }))).toBe( | |
| 12 | + true, | |
| 13 | + ); | |
| 12 | 14 | }); |
| 13 | 15 | |
| 14 | 16 | it("does not treat settled success or failure as loading", () => { |
| 15 | 17 | expect(isAsyncResultLoading(AsyncResult.success(["ready"]))).toBe(false); |
| 16 | 18 | expect(isAsyncResultLoading(AsyncResult.failure(Cause.fail("boom")))).toBe(false); |
| 17 | 19 | }); |
| 20 | + | |
| 21 | + it("keeps stale values rendered while a refresh is waiting", () => { | |
| 22 | + expect(isAsyncResultLoading(AsyncResult.success(["cached"], { waiting: true }))).toBe(false); | |
| 23 | + }); | |
| 18 | 24 | }); |
| @@ -1,5 +1,9 @@ | ||
| 1 | 1 | import * as AsyncResult from "effect/unstable/reactivity/AsyncResult"; |
| 2 | +import * as Option from "effect/Option"; | |
| 2 | 3 | |
| 3 | 4 | export function isAsyncResultLoading<A, E>(result: AsyncResult.AsyncResult<A, E>): boolean { |
| 4 | − return AsyncResult.isInitial(result) || AsyncResult.isWaiting(result); | |
| 5 | + return ( | |
| 6 | + AsyncResult.isInitial(result) || | |
| 7 | + (AsyncResult.isWaiting(result) && Option.isNone(AsyncResult.value(result))) | |
| 8 | + ); | |
| 5 | 9 | } |