We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
scrapbox.Page.lines
1 parent 45d200f commit e1ccbd4Copy full SHA for e1ccbd4
browser/dom/getCachedLines.ts
@@ -0,0 +1,22 @@
1
+import { Line, Scrapbox } from "../../deps/scrapbox.ts";
2
+declare const scrapbox: Scrapbox;
3
+
4
+let isLatestData = false;
5
+let lines: typeof scrapbox.Page.lines = null;
6
7
+scrapbox.addListener("lines:changed", () => isLatestData = false);
8
+scrapbox.addListener("layout:changed", () => isLatestData = false);
9
10
+/** scrapbox.Page.linesをcacheして取得する
11
+ *
12
+ * scrapbox.Page.linesの生成には時間がかかるので、実際に必要になるまで呼び出さないようにする
13
14
+ * @return `scrapbox.Page.lines`と同じ。常に最新のものが返される
15
+ */
16
+export const getCachedLines = (): readonly Line[] | null => {
17
+ if (!isLatestData) {
18
+ lines = scrapbox.Page.lines;
19
+ isLatestData = true;
20
+ }
21
+ return lines;
22
+};
0 commit comments