[atom] Clean up FilesystemChangeEvent (#24968)

Add a type for a single FilesystemChange, have `oldPath` on rename
events only.
This commit is contained in:
Nikolay Yakimov
2018-04-13 08:49:55 -07:00
committed by Mohamed Hegazy
parent 54968ba726
commit 3b587e9ce3
2 changed files with 14 additions and 5 deletions
+1 -1
View File
@@ -3310,7 +3310,7 @@ const pathWatcherPromise = Atom.watchPath("/var/test", {}, (events) => {
for (const event of events) {
str = event.path;
str = event.action;
if (event.oldPath) str = event.oldPath;
if (event.action === "renamed") str = event.oldPath;
}
});
+13 -4
View File
@@ -5647,19 +5647,28 @@ export interface FileSavedEvent {
path: string;
}
export type FilesystemChangeEvent = Array<{
export interface FilesystemChangeBasic<
Action extends "created"|"modified"|"deleted"|"renamed"
= "created"|"modified"|"deleted"
> {
/** A string describing the filesystem action that occurred. */
action: "created"|"modified"|"deleted"|"renamed";
action: Action;
/** The absolute path to the filesystem entry that was acted upon. */
path: string;
}
export interface FilesystemChangeRename extends FilesystemChangeBasic<"renamed"> {
/**
* For rename events, a string containing the filesystem entry's former
* absolute path.
*/
oldPath?: string;
}>;
oldPath: string;
}
export type FilesystemChange = FilesystemChangeBasic|FilesystemChangeRename;
export type FilesystemChangeEvent = FilesystemChange[];
export interface FullKeybindingMatchEvent {
/** The string of keystrokes that matched the binding. */