Skip to content

Commit

Permalink
react-experiment: fix type regression from 6ee33d3 (#213)
Browse files Browse the repository at this point in the history
* react-experiment: fix type regression from 6ee33d3

* changeset
  • Loading branch information
QuentinRoy authored Dec 18, 2023
1 parent a1fe75d commit 3b71a26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-fireants-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/react-experiment': patch
---

Fix Run props type regression introduced in 6ee33d3d21882c2e6d8cc12ec0cfda5506fce46a.
11 changes: 5 additions & 6 deletions packages/react-experiment/src/run.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from 'react';
import { ReadonlyDeep } from 'type-fest';
import { RegisteredTask, Typed, RegisteredLog } from './config.js';
import { loggerContext, noLoggerSymbol, timelineContext } from './contexts.js';
import useManagedTimeline, {
Timeline,
AnyIteratorOrIterable,
TimelineState,
} from './useManagedTimeline.js';

Expand All @@ -16,7 +15,7 @@ export type RunElements<T extends Typed> = {
export type Logger<Log> = (log: Log) => Promise<void>;

export type RunProps<Task extends Typed, Log> = {
elements: Readonly<RunElements<Task>>;
elements: RunElements<Task>;
confirmBeforeUnload?: boolean;
} & UseRunParameter<Task, Log>;

Expand Down Expand Up @@ -75,13 +74,13 @@ type UseRunParameter<Task extends { type: string }, Log> = {
onLog?: Logger<Log>;
resumeAfter?: { type: Task['type']; number: number };
} & (
| { timeline: ReadonlyDeep<Timeline<Task>>; loading?: boolean }
| { timeline?: ReadonlyDeep<Timeline<Task>> | null; loading: true }
| { timeline: AnyIteratorOrIterable<Task>; loading?: boolean }
| { timeline?: AnyIteratorOrIterable<Task> | null; loading: true }
);
type RunState<Task, Log> = Exclude<TimelineState<Task>, { status: 'error' }> & {
onLog: ((newLog: Log) => void) | null;
};
function useRun<const T extends { type: string }, L>({
function useRun<T extends { type: string }, L>({
onCompleted,
timeline,
resumeAfter,
Expand Down
12 changes: 6 additions & 6 deletions packages/react-experiment/src/useManagedTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ export type TimelineState<Task> =
| { status: 'error'; error: Error }
| { status: 'running'; task: Task; onTaskCompleted: () => void };

export type AsyncTimeline<Task> = AsyncIterator<Task> | AsyncIterable<Task>;

export type SyncTimeline<Task> = Iterator<Task> | Iterable<Task>;

export type Timeline<Task> = AsyncTimeline<Task> | SyncTimeline<Task>;
export type AnyIteratorOrIterable<Task> =
| AsyncIterator<Task>
| AsyncIterable<Task>
| Iterator<Task>
| Iterable<Task>;

type Options<Task extends { type: string }> = {
onTimelineCompleted?: () => void;
onTimelineStarted?: () => void;
onTaskStarted?: (task: Task) => void;
onTaskCompleted?: (task: Task) => void;
onTaskLoadingError?: (error: unknown) => void;
timeline?: Timeline<Task> | null;
timeline?: AnyIteratorOrIterable<Task> | null;
resumeAfter?: { type: Task['type']; number: number };
};

Expand Down

0 comments on commit 3b71a26

Please sign in to comment.