Skip to content

Commit 3487d33

Browse files
committed
feat: pass props to subscription function
1 parent c6baf2a commit 3487d33

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/useElmish.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { MessageBase, Nullable, UpdateMap } from "./ElmUtilities";
55
import { useCallback, useEffect, useState } from "react";
66

77
export type SubscriptionResult<TMessage> = [Cmd<TMessage>, (() => void)?];
8-
type Subscription<TModel, TMessage> = (model: TModel) => SubscriptionResult<TMessage>;
8+
type Subscription<TProps, TModel, TMessage> = (model: TModel, props: TProps) => SubscriptionResult<TMessage>;
99

1010
interface UseElmishOptions<TProps, TModel, TMessage extends MessageBase> {
1111
name: string,
1212
props: TProps,
1313
init: InitFunction<TProps, TModel, TMessage>,
1414
update: UpdateFunction<TProps, TModel, TMessage> | UpdateMap<TProps, TModel, TMessage>,
15-
subscription?: Subscription<TModel, TMessage>,
15+
subscription?: Subscription<TProps, TModel, TMessage>,
1616
}
1717

1818
/**
@@ -108,7 +108,7 @@ export function useElmish<TProps, TModel, TMessage extends MessageBase> ({ name,
108108

109109
useEffect(() => {
110110
if (subscription) {
111-
const [subCmd, destructor] = subscription(initializedModel as TModel);
111+
const [subCmd, destructor] = subscription(initializedModel as TModel, props);
112112

113113
execCmd(subCmd);
114114

tests/useElmish.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe("useElmish", () => {
146146
renderComponent(props);
147147

148148
// assert
149-
expect(mockSubscription).toHaveBeenCalledWith(initModel);
149+
expect(mockSubscription).toHaveBeenCalledWith(initModel, props);
150150
expect(mockSub).toHaveBeenCalledWith(expect.anything());
151151
});
152152

0 commit comments

Comments
 (0)