fix(files): harden drag-and-drop uploads
Co-authored-by: Serhii Dziupin <serkraser@gmail.com> Co-authored-by: Alan Chen <2144783+alanzchen@users.noreply.github.com>
This commit is contained in:
co-authored by
Serhii Dziupin
Alan Chen
parent
0c5e183c62
commit
99873a7b12
@@ -0,0 +1,25 @@
|
||||
type FileContentInvalidation = {
|
||||
runtimeKey: string;
|
||||
paths: readonly string[];
|
||||
};
|
||||
|
||||
type FileContentInvalidationListener = (invalidation: FileContentInvalidation) => void;
|
||||
|
||||
const listeners = new Set<FileContentInvalidationListener>();
|
||||
|
||||
export const notifyFileContentInvalidated = (invalidation: FileContentInvalidation): void => {
|
||||
const runtimeKey = invalidation.runtimeKey.trim();
|
||||
const paths = Array.from(new Set(invalidation.paths.map((path) => path.trim()).filter(Boolean)));
|
||||
if (!runtimeKey || paths.length === 0) return;
|
||||
|
||||
for (const listener of listeners) {
|
||||
listener({ runtimeKey, paths });
|
||||
}
|
||||
};
|
||||
|
||||
export const subscribeToFileContentInvalidation = (
|
||||
listener: FileContentInvalidationListener,
|
||||
): (() => void) => {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
};
|
||||
Reference in New Issue
Block a user