Skip to content

Commit 7fffd4f

Browse files
committed
refactor: Extract the type of makeCommit and document it
1 parent d05693c commit 7fffd4f

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

browser/websocket/push.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ export type PushError =
6868
| NetworkError
6969
| AbortError;
7070

71+
/**
72+
* pushしたいcommitを作る関数
73+
*
74+
* {@linkcode push} で使う
75+
*
76+
* @param page ページのメタデータ
77+
* @param attempts 何回目の試行か
78+
* @param prev 前回のcommitの変更
79+
* @param reason 再試行した場合、その理由が渡される
80+
* @returns commits
81+
*/
82+
export type CommitMakeHandler = (
83+
page: PushMetadata,
84+
attempts: number,
85+
prev: Change[] | [DeletePageChange] | [PinChange],
86+
reason?: "NotFastForwardError" | "DuplicateTitleError",
87+
) =>
88+
| Promise<Change[] | [DeletePageChange] | [PinChange]>
89+
| Change[]
90+
| [DeletePageChange]
91+
| [PinChange];
92+
7193
/** 特定のページのcommitをpushする
7294
*
7395
* serverからpush errorが返ってきた場合、エラーに応じてpushを再試行する
@@ -81,16 +103,7 @@ export type PushError =
81103
export const push = async (
82104
project: string,
83105
title: string,
84-
makeCommit: (
85-
page: PushMetadata,
86-
attempts: number,
87-
prev: Change[] | [DeletePageChange] | [PinChange],
88-
reason?: "NotFastForwardError" | "DuplicateTitleError",
89-
) =>
90-
| Promise<Change[] | [DeletePageChange] | [PinChange]>
91-
| Change[]
92-
| [DeletePageChange]
93-
| [PinChange],
106+
makeCommit: CommitMakeHandler,
94107
options?: PushOptions,
95108
): Promise<Result<string, PushError>> => {
96109
const result = await connect(options?.socket);

0 commit comments

Comments
 (0)