Skip to content

Commit

Permalink
react-experiment: improve run typing (#211)
Browse files Browse the repository at this point in the history
* react-experiment: improve run typing

* changeset
  • Loading branch information
QuentinRoy authored Dec 15, 2023
1 parent f6a7a82 commit 6ee33d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-bees-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/react-experiment': patch
---

Run's elements prop must now support every tasks in timeline, even when no task types have been provided or registered
11 changes: 6 additions & 5 deletions packages/react-experiment/src/run.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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, {
Expand All @@ -15,13 +16,13 @@ export type RunElements<T extends Typed> = {
export type Logger<Log> = (log: Log) => Promise<void>;

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

// This component uses explicit return type to prevent the function from
// returning undefined, which could indicate a state isn't being handled.
export function Run<T extends RegisteredTask>({
export function Run<const T extends RegisteredTask>({
elements,
confirmBeforeUnload = true,
...useRunParameter
Expand Down Expand Up @@ -74,13 +75,13 @@ type UseRunParameter<Task extends { type: string }, Log> = {
onLog?: Logger<Log>;
resumeAfter?: { type: Task['type']; number: number };
} & (
| { timeline: Timeline<Task>; loading?: boolean }
| { timeline?: Timeline<Task> | null; loading: true }
| { timeline: ReadonlyDeep<Timeline<Task>>; loading?: boolean }
| { timeline?: ReadonlyDeep<Timeline<Task>> | null; loading: true }
);
type RunState<Task, Log> = Exclude<TimelineState<Task>, { status: 'error' }> & {
onLog: ((newLog: Log) => void) | null;
};
function useRun<T extends { type: string }, L>({
function useRun<const T extends { type: string }, L>({
onCompleted,
timeline,
resumeAfter,
Expand Down

0 comments on commit 6ee33d3

Please sign in to comment.