diff --git a/package.json b/package.json index aa005b1..b31d5b7 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "@paulcbetts/mime-types": "^2.1.10", "btoa": "^1.1.2", "debug": "^2.5.1", + "gaze": "^1.1.2", "lru-cache": "^4.0.1", "mkdirp": "^0.5.1", "pify": "^2.3.0", diff --git a/src/custom-operators.js b/src/custom-operators.js index 7479970..b24c665 100644 --- a/src/custom-operators.js +++ b/src/custom-operators.js @@ -24,12 +24,6 @@ function retryWithDelayOrError(errors, maxRetries) { } const newCoolOperators = { - guaranteedThrottle: function(time, scheduler = async) { - return this - .map((x) => Observable.timer(time, scheduler).map(() => x)) - .switch(); - }, - retryAtIntervals: function(maxRetries = 3) { return this.retryWhen((errors) => retryWithDelayOrError(errors, maxRetries)); }, diff --git a/src/live-reload.js b/src/live-reload.js index 57360cc..57aedd6 100644 --- a/src/live-reload.js +++ b/src/live-reload.js @@ -52,8 +52,7 @@ function enableLiveReloadNaive() { .filter(x => !FileChangedCache.isInNodeModules(x.filePath)); let weShouldReload = filesWeCareAbout - .mergeMap(x => watchPath(x.filePath).map(() => x)) - .guaranteedThrottle(1*1000); + .mergeMap(x => watchPath(x.filePath).map(() => x)); return weShouldReload .switchMap(() => Observable.defer(() => Observable.fromPromise(reloadAllWindows()).timeout(5*1000).catch(() => Observable.empty()))) @@ -75,8 +74,7 @@ function enableReactHMR() { .filter(x => !FileChangedCache.isInNodeModules(x.filePath)); let weShouldReload = filesWeCareAbout - .mergeMap(x => watchPath(x.filePath).map(() => x)) - .guaranteedThrottle(1*1000); + .mergeMap(x => watchPath(x.filePath).map(() => x)); return weShouldReload .switchMap(() => Observable.defer(() => Observable.fromPromise(triggerHMRInRenderers()).catch(() => Observable.empty()))) diff --git a/src/pathwatcher-rx.js b/src/pathwatcher-rx.js index 17b0c21..2353563 100644 --- a/src/pathwatcher-rx.js +++ b/src/pathwatcher-rx.js @@ -1,6 +1,6 @@ -import fs from 'fs'; import {Observable} from 'rxjs/Observable'; import {Subscription} from 'rxjs/Subscription'; +import {Gaze} from 'gaze'; import LRU from 'lru-cache'; import 'rxjs/add/operator/publish'; @@ -9,14 +9,15 @@ export function watchPathDirect(directory) { return Observable.create((subj) => { let dead = false; - const watcher = fs.watch(directory, {}, (eventType, fileName) => { - if (dead) return; - subj.next({eventType, fileName}); - }); - - watcher.on('error', (e) => { + const watcher = new Gaze(); + watcher.on('error', (err) => { dead = true; - subj.error(e); + subj.error(err); + }); + watcher.add(directory); + watcher.on('changed', (fileName) => { + if (dead) return; + subj.next({fileName, eventType: 'changed'}); }); return new Subscription(() => { if (!dead) { watcher.close(); } });