-
-
Notifications
You must be signed in to change notification settings - Fork 140
feat: add comprehensive FileSystem observer API types with full MDN spec compliance #1171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -126,3 +126,32 @@ export type Data = | |||||
| | DataView | ||||||
| | Blob | ||||||
| | string; | ||||||
|
|
||||||
| /** | ||||||
| * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemChangeRecord | ||||||
| */ | ||||||
| export interface FileSystemChangeRecord { | ||||||
| /** The changed file system handle. */ | ||||||
| changedHandle: IFileSystemHandle; | ||||||
| /** Path components from the observed directory to the changed handle. */ | ||||||
| relativePathComponents: string[]; | ||||||
| /** The type of change that occurred. */ | ||||||
| type: 'appeared' | 'disappeared' | 'modified'; | ||||||
| } | ||||||
|
|
||||||
| export interface FileSystemObserverObserveOptions { | ||||||
| /** Whether to observe changes recursively in subdirectories. */ | ||||||
| recursive?: boolean; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemObserver | ||||||
| */ | ||||||
| export interface FileSystemObserver { | ||||||
|
||||||
| export interface FileSystemObserver { | |
| export interface IFileSystemObserver { |
The observer also needs its constructor to be typed:
js
Copy
const observer = new FileSystemObserver(callback);
The [callback function](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemObserver/FileSystemObserver#callback) body can be specified to return and process file change observations in any way you want:
js
Copy
const callback = (records, observer) => {
for (const record of records) {
console.log("Change detected:", record);
const reportContent = `Change observed to ${record.changedHandle.kind} ${record.changedHandle.name}. Type: ${record.type}.`;
sendReport(reportContent); // Some kind of user-defined reporting function
}
observer.disconnect();
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated interface name to IFileSystemObserver and added constructor signature with callback function as specified in the MDN documentation. Changes implemented in commit 38e2f13.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface is lacking types, see docs:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added all missing properties from the MDN spec:
relativePathMovedFrom,root, nullablechangedHandle, and completetypevalues including "errored", "moved", and "unknown". Also added support forIFileSystemSyncAccessHandlefor OPFS compatibility. Changes implemented in commit 38e2f13.