File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,13 @@ export interface JoinPageRoomResult {
13
13
* `update()`で現在の本文から書き換え後の本文を作ってもらう。
14
14
* serverには書き換え前後の差分だけを送信する
15
15
*
16
- * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される
16
+ * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される。undefinedを返すと書き換えを中断する
17
17
*/
18
18
patch : (
19
- update : ( before : Line [ ] , metadata : HeadData ) => string [ ] ,
19
+ update : (
20
+ before : Line [ ] ,
21
+ metadata : HeadData ,
22
+ ) => string [ ] | undefined | Promise < string [ ] | undefined > ,
20
23
) => Promise < void > ;
21
24
/** ページの更新情報を購読する */
22
25
listenPageUpdate : ( ) => AsyncGenerator < CommitNotification , void , unknown > ;
@@ -68,13 +71,15 @@ export async function joinPageRoom(
68
71
update : (
69
72
before : Line [ ] ,
70
73
metadata : HeadData ,
71
- ) => string [ ] | Promise < string [ ] > ,
74
+ ) => string [ ] | undefined | Promise < string [ ] | undefined > ,
72
75
) => {
73
76
for ( let i = 0 ; i < 3 ; i ++ ) {
74
77
try {
75
78
const pending = update ( head . lines , head ) ;
76
79
const newLines = pending instanceof Promise ? await pending : pending ;
77
80
81
+ if ( ! newLines ) return ;
82
+
78
83
if ( newLines . length === 0 ) {
79
84
await pushWithRetry ( request , [ { deleted : true } ] , {
80
85
projectId,
Original file line number Diff line number Diff line change @@ -50,12 +50,15 @@ export async function deletePage(
50
50
*
51
51
* @param project 書き換えたいページのproject
52
52
* @param title 書き換えたいページのタイトル
53
- * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される
53
+ * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される。undefinedを返すと書き換えを中断する
54
54
*/
55
55
export async function patch (
56
56
project : string ,
57
57
title : string ,
58
- update : ( lines : Line [ ] , metadata : HeadData ) => string [ ] | Promise < string [ ] > ,
58
+ update : (
59
+ lines : Line [ ] ,
60
+ metadata : HeadData ,
61
+ ) => string [ ] | undefined | Promise < string [ ] | undefined > ,
59
62
) : Promise < void > {
60
63
const [
61
64
head_ ,
@@ -79,6 +82,8 @@ export async function patch(
79
82
const pending = update ( head . lines , head ) ;
80
83
const newLines = pending instanceof Promise ? await pending : pending ;
81
84
85
+ if ( ! newLines ) return ;
86
+
82
87
if ( newLines . length === 0 ) {
83
88
await pushWithRetry ( request , [ { deleted : true } ] , {
84
89
projectId,
You can’t perform that action at this time.
0 commit comments