Skip to content

Commit 0527130

Browse files
fix: improve TypeScript types in documentation examples and simplify code
1 parent aa3d525 commit 0527130

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

browser/websocket/listen.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ export type ListenStreamError =
4141
* - once: Listen only once if true
4242
*
4343
* Example:
44-
* ```ts
45-
* listen(socket, "project:update", (data: ProjectUpdateData) => {
44+
* ```typescript
45+
* import { type ScrapboxSocket } from "./socket.ts";
46+
* import { type ListenEvents } from "./listen-events.ts";
47+
*
48+
* // Setup socket and controller
49+
* const socket: ScrapboxSocket = /* ... */;
50+
* const controller = new AbortController();
51+
*
52+
* // Listen for project updates
53+
* listen<"project:updates">(socket, "project:updates", (data) => {
4654
* console.log("Project updated:", data);
4755
* }, { signal: controller.signal });
4856
* ```

browser/websocket/pin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export const pin = (
4343
) return [];
4444
// Create page and pin it in a single operation
4545
// Note: The server accepts combined creation and pin operations
46-
const pinChange: Change = { pin: pinNumber() };
47-
const changes: Change[] = [pinChange];
46+
const changes: Change[] = [{ pin: pinNumber() }];
4847
if (!page.persistent) changes.unshift({ title });
4948
return changes;
5049
},

rest/getCodeBlocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const getCodeBlocks = (
9797
const codeBlocks: TinyCodeBlock[] = [];
9898

9999
let currentCode: CodeTitle & {
100-
/** 読み取り中の行がコードブロックかどうか */
100+
/** Whether the current line is part of a code block */
101101
isCodeBlock: boolean;
102102
} = {
103103
isCodeBlock: false,
@@ -137,7 +137,7 @@ export const getCodeBlocks = (
137137
return codeBlocks.filter((codeBlock) => isMatchFilter(codeBlock, filter));
138138
};
139139

140-
/** コードブロックのフィルターに合致しているか検証する */
140+
/** Verify if a code block matches the specified filter criteria */
141141
const isMatchFilter = (
142142
codeBlock: TinyCodeBlock,
143143
filter?: GetCodeBlocksFilter,

0 commit comments

Comments
 (0)