File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,13 @@ export interface JoinPageRoomResult {
1313 * `update()`で現在の本文から書き換え後の本文を作ってもらう。
1414 * serverには書き換え前後の差分だけを送信する
1515 *
16- * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される
16+ * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される。undefinedを返すと書き換えを中断する
1717 */
1818 patch : (
19- update : ( before : Line [ ] , metadata : HeadData ) => string [ ] ,
19+ update : (
20+ before : Line [ ] ,
21+ metadata : HeadData ,
22+ ) => string [ ] | undefined | Promise < string [ ] | undefined > ,
2023 ) => Promise < void > ;
2124 /** ページの更新情報を購読する */
2225 listenPageUpdate : ( ) => AsyncGenerator < CommitNotification , void , unknown > ;
@@ -68,13 +71,15 @@ export async function joinPageRoom(
6871 update : (
6972 before : Line [ ] ,
7073 metadata : HeadData ,
71- ) => string [ ] | Promise < string [ ] > ,
74+ ) => string [ ] | undefined | Promise < string [ ] | undefined > ,
7275 ) => {
7376 for ( let i = 0 ; i < 3 ; i ++ ) {
7477 try {
7578 const pending = update ( head . lines , head ) ;
7679 const newLines = pending instanceof Promise ? await pending : pending ;
7780
81+ if ( ! newLines ) return ;
82+
7883 if ( newLines . length === 0 ) {
7984 await pushWithRetry ( request , [ { deleted : true } ] , {
8085 projectId,
Original file line number Diff line number Diff line change @@ -50,12 +50,15 @@ export async function deletePage(
5050 *
5151 * @param project 書き換えたいページのproject
5252 * @param title 書き換えたいページのタイトル
53- * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される
53+ * @param update 書き換え後の本文を作成する函数。引数には現在の本文が渡される。空配列を返すとページが削除される。undefinedを返すと書き換えを中断する
5454 */
5555export async function patch (
5656 project : string ,
5757 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 > ,
5962) : Promise < void > {
6063 const [
6164 head_ ,
@@ -79,6 +82,8 @@ export async function patch(
7982 const pending = update ( head . lines , head ) ;
8083 const newLines = pending instanceof Promise ? await pending : pending ;
8184
85+ if ( ! newLines ) return ;
86+
8287 if ( newLines . length === 0 ) {
8388 await pushWithRetry ( request , [ { deleted : true } ] , {
8489 projectId,
You can’t perform that action at this time.
0 commit comments