From 7aab9925a89480960c300a7ada6dc3deaa82fb80 Mon Sep 17 00:00:00 2001 From: Ash Wilson Date: Mon, 31 Jul 2017 14:54:10 -0400 Subject: [PATCH] Rename filesystem-manager to path-watcher --- ...{filesystem-manager.js => path-watcher.js} | 48 ++++++++----------- 1 file changed, 20 insertions(+), 28 deletions(-) rename src/{filesystem-manager.js => path-watcher.js} (92%) diff --git a/src/filesystem-manager.js b/src/path-watcher.js similarity index 92% rename from src/filesystem-manager.js rename to src/path-watcher.js index 14273423c..4a0e435ec 100644 --- a/src/filesystem-manager.js +++ b/src/path-watcher.js @@ -24,6 +24,22 @@ export const WATCHER_STATE = { STOPPING: Symbol('stopping') } +const LIVE = new Set() + +const REGISTRY = new NativeWatcherRegistry( + normalizedPath => { + const nativeWatcher = new NativeWatcher(normalizedPath) + + LIVE.add(nativeWatcher) + const sub = nativeWatcher.onWillStop(() => { + LIVE.delete(nativeWatcher) + sub.dispose() + }) + + return nativeWatcher + } +) + // Private: Interface with and normalize events from a native OS filesystem watcher. class NativeWatcher { @@ -173,8 +189,8 @@ class NativeWatcher { } } -class Watcher { - constructor (watchedPath, nativeWatcherRegistry) { +export default class PathWatcher { + constructor (watchedPath, options) { this.watchedPath = watchedPath this.nativeWatcherRegistry = nativeWatcherRegistry @@ -297,34 +313,10 @@ class Watcher { } } -export default class FileSystemManager { - constructor () { - this.liveWatchers = new Set() - - this.nativeWatchers = new NativeWatcherRegistry( - normalizedPath => { - const nativeWatcher = new NativeWatcher(normalizedPath) - - this.liveWatchers.add(nativeWatcher) - const sub = nativeWatcher.onWillStop(() => { - this.liveWatchers.delete(nativeWatcher) - sub.dispose() - }) - - return nativeWatcher - } - ) - } - - getWatcher (rootPath) { - return new Watcher(rootPath, this.nativeWatchers) - } -} - // Private: Return a Promise that resolves when all {NativeWatcher} instances associated with a FileSystemManager // have stopped listening. This is useful for `afterEach()` blocks in unit tests. -export function stopAllWatchers (manager) { +export function stopAllWatchers () { return Promise.all( - Array.from(manager.liveWatchers, watcher => watcher.stop()) + Array.from(LIVE, watcher => watcher.stop()) ) }