Skip to content

Commit 4eb01ac

Browse files
committed
fix: deprecate Cmd.none
1 parent 39387c3 commit 4eb01ac

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Cmd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Cmd<TMessage> = Sub<TMessage> [];
1818
interface Command<TMessage> {
1919
/**
2020
* Represents an empty command.
21+
* @deprecated Do return nothing (`undefined`) instead.
2122
*/
2223
none: [],
2324
/**

tests/useElmish.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, RenderResult, waitFor } from "@testing-library/react";
22
import { useEffect } from "react";
3-
import { Cmd, createCmd, SubscriptionResult, UpdateReturnType, useElmish } from "../src";
3+
import { Cmd, createCmd, InitResult, SubscriptionResult, UpdateReturnType, useElmish } from "../src";
44

55
type Message =
66
| { name: "Test" }
@@ -14,12 +14,12 @@ interface Model {
1414
}
1515

1616
interface Props {
17-
init: () => [Model, Cmd<Message>],
17+
init: () => InitResult<Model, Message>,
1818
update: (model: Model, msg: Message, props: Props) => UpdateReturnType<Model, Message>,
1919
subscription?: (model: Model) => SubscriptionResult<Message>,
2020
}
2121

22-
function defaultInit (msg: Cmd<Message>): [Model, Cmd<Message>] {
22+
function defaultInit (msg?: Cmd<Message>): InitResult<Model, Message> {
2323
return [
2424
{
2525
value1: "",
@@ -100,7 +100,7 @@ describe("useElmish", () => {
100100
it("updates the model correctly with multiple commands delayed", async () => {
101101
// arrange
102102
const props: Props = {
103-
init: () => defaultInit(cmd.none),
103+
init: () => defaultInit(),
104104
update (_model: Model, msg: Message): UpdateReturnType<Model, Message> {
105105
// eslint-disable-next-line jest/no-conditional-in-test
106106
switch (msg.name) {
@@ -134,7 +134,7 @@ describe("useElmish", () => {
134134
// arrange
135135
const mockSub = jest.fn();
136136
const mockSubscription = jest.fn().mockReturnValue([cmd.ofSub(mockSub)]);
137-
const [initModel, initCmd] = defaultInit(cmd.none);
137+
const [initModel, initCmd] = defaultInit();
138138
const props: Props = {
139139
init: () => [initModel, initCmd],
140140
update: defaultUpdate,
@@ -153,8 +153,8 @@ describe("useElmish", () => {
153153
it("calls the subscriptions destructor if provided", () => {
154154
// arrange
155155
const mockDestructor = jest.fn();
156-
const mockSubscription = jest.fn().mockReturnValue([cmd.none, mockDestructor]);
157-
const [initModel, initCmd] = defaultInit(cmd.none);
156+
const mockSubscription = jest.fn().mockReturnValue([[], mockDestructor]);
157+
const [initModel, initCmd] = defaultInit();
158158
const props: Props = {
159159
init: () => [initModel, initCmd],
160160
update: defaultUpdate,

0 commit comments

Comments
 (0)