Skip to content

Commit

Permalink
fix: allow undefined for subscription in runSubscription, always re…
Browse files Browse the repository at this point in the history
…turn a dispose function (#35)
  • Loading branch information
atheck committed Sep 23, 2023
1 parent 0cc7d4c commit b763e7a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Testing/runSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import { Subscription } from "../useElmish";
import { execCmdWithDispatch } from "./execCmd";

function runSubscription<TProps, TModel, TMessage extends Message>(
subscription: Subscription<TProps, TModel, TMessage>,
subscription: Subscription<TProps, TModel, TMessage> | undefined,
dispatch: Dispatch<TMessage>,
model: TModel,
props: TProps,
): (() => void) | undefined {
): () => void {
const noop = (): void => {
// do nothing
};

if (!subscription) {
return noop;
}

const [cmd, dispose] = subscription(model, props);

execCmdWithDispatch<TMessage>(dispatch, cmd);

return dispose;
return dispose ?? noop;
}

export { runSubscription };

0 comments on commit b763e7a

Please sign in to comment.