Skip to content

code/editor/useFileDocument

import { … } from 'zidane-ui/code/editor'ui/src/code/editor/useFileDocument.ts

Functions#

useFileDocumentFunction#

Loads one adapter file for useCodeDocument and keeps it fresh as the adapter reports changes.

TypeScript
function useFileDocument(fs: FileSystemAdapter, path: string): FileDocumentState
Parameters
NameTypeDescription
fsFileSystemAdapter

Where the file lives.

pathstring

The file, from the adapter's root.

ui/src/code/editor/useFileDocument.ts:31

Interfaces#

FileDocumentStateInterface#

What useFileDocument returns: the file as a CodeDoc plus the save and reload useCodeDocument takes.

TypeScript
interface FileDocumentState
FileDocumentState properties
NameTypeDescription
docCodeDoc | null

The latest read; null until the first one lands.

errorstring | null

Why the file could not be read.

reload() => Promise<CodeDoc | null>

Reads the file again; null when it cannot be read.

save(text: string, base: CodeDoc, force: boolean) => Promise<SaveOutcome<CodeDoc>>

Writes text; unless force, first checks the file still has base's version and reports changed if not.

ui/src/code/editor/useFileDocument.ts:12