Skip to content

Commit 799fd05

Browse files
committed
use FileStub and DirectoryStub instead of File/Directory
1 parent a348c2e commit 799fd05

File tree

7 files changed

+20
-16
lines changed

7 files changed

+20
-16
lines changed

src/lib/client/viewer/Editor.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
77
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
88
9-
/** @type {import('$lib/types').File | null} */
9+
/** @type {import('$lib/types').FileStub | null} */
1010
export let file;
1111
1212
const dispatch = createEventDispatcher();

src/lib/client/viewer/FileTree/File.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
import { getContext } from 'svelte';
33
4-
/** @type {import('$lib/types').File} */
4+
/** @type {import('$lib/types').FileStub} */
55
export let file;
66
77
const { select, selected } = getContext('filetree');

src/lib/client/viewer/FileTree/Folder.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
/** @type {number} */
1414
export let depth;
1515
16-
/** @type {Array<import('$lib/types').File | import('$lib/types').Directory>} */
16+
/** @type {Array<import('$lib/types').Stub>} */
1717
export let files;
1818
1919
$: children = files.filter((file) => file.name.startsWith(prefix));
2020
$: child_directories = children.filter(
2121
(child) => child.depth === depth + 1 && child.type === 'directory'
2222
);
23-
$: child_files = /** @type {import('$lib/types').File[]} */ (
23+
$: child_files = /** @type {import('$lib/types').FileStub[]} */ (
2424
children.filter((child) => child.depth === depth + 1 && child.type === 'file')
2525
);
2626

src/lib/server/content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function extract_frontmatter(markdown, dir) {
143143
* @param {string} cwd - the directory to walk
144144
*/
145145
export function walk(cwd) {
146-
/** @type {Record<string, import('$lib/types').File | import('$lib/types').Directory>} */
146+
/** @type {Record<string, import('$lib/types').FileStub | import('$lib/types').DirectoryStub>} */
147147
const result = {};
148148

149149
if (!fs.existsSync(cwd)) return result;

src/lib/types/index.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface File {
1+
export interface FileStub {
22
type: 'file';
33
name: string;
44
basename: string;
@@ -7,16 +7,18 @@ export interface File {
77
depth: number;
88
}
99

10-
export interface Directory {
10+
export interface DirectoryStub {
1111
type: 'directory';
1212
name: string;
1313
basename: string;
1414
depth: number;
1515
}
1616

17+
export type Stub = FileStub | DirectoryStub;
18+
1719
export interface Adapter {
1820
base: string;
19-
update(files: Array<File | Directory>): Promise<void>;
21+
update(files: Array<Stub>): Promise<void>;
2022
destroy(): Promise<void>;
2123
}
2224

@@ -34,8 +36,8 @@ export interface Section {
3436
prev: string | null;
3537
next: string | null;
3638
html: string;
37-
a: Record<string, File | Directory>;
38-
b: Record<string, File | Directory>;
39+
a: Record<string, Stub>;
40+
b: Record<string, Stub>;
3941
}
4042

4143
export type SectionIndex = Array<{

src/routes/backend/[id].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function put({ request, params, url }) {
3333

3434
const dir = `.apps/${id}`;
3535

36-
/** @type {Array<import('$lib/types').File | import('$lib/types').Directory>} */
36+
/** @type {Array<import('$lib/types').FileStub | import('$lib/types').DirectoryStub>} */
3737
const files = await request.json();
3838

3939
const app = apps.get(id);

src/routes/tutorial/[slug]/index.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131
/** @type {import('svelte/store').Writable<import('$lib/types').Section>}*/
3232
const current = writable(section);
3333
34-
/** @type {import('svelte/store').Writable<Array<import('$lib/types').File | import('$lib/types').Directory>>} */
34+
/** @type {import('svelte/store').Writable<import('$lib/types').Stub[]>} */
3535
const files = writable([]);
3636
3737
/** @type {import('svelte/store').Writable<import('monaco-editor').editor.ITextModel[]>} */
3838
const models = writable([]);
3939
40-
/** @type {import('svelte/store').Writable<import('$lib/types').File | null>} */
40+
/** @type {import('svelte/store').Writable<import('$lib/types').Stub | null>} */
4141
const selected = writable(null);
4242
4343
const started = writable(false);
4444
4545
const base = writable('');
4646
4747
setContext('filetree', {
48-
/** @param {import('$lib/types').File} file */
48+
/** @param {import('$lib/types').FileStub} file */
4949
select: (file) => {
5050
selected.set(file);
5151
},
@@ -62,7 +62,7 @@
6262
6363
base,
6464
65-
/** @param {Array<import('$lib/types').File | import('$lib/types').Directory>} data */
65+
/** @param {import('$lib/types').Stub[]} data */
6666
async update(data) {
6767
await ready;
6868
await adapter.update(data);
@@ -116,6 +116,8 @@
116116
afterNavigate(async () => {
117117
const data = Object.values(section.a);
118118
119+
console.log(section.a);
120+
119121
files.set(data);
120122
121123
for (const model of $models) model.dispose();
@@ -141,7 +143,7 @@
141143
});
142144
143145
selected.set(
144-
/** @type {import('$lib/types').File} */ (
146+
/** @type {import('$lib/types').FileStub} */ (
145147
data.find((file) => file.name === section.chapter.focus)
146148
)
147149
);

0 commit comments

Comments
 (0)