Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fvgs authored and fasterthanlime committed Aug 24, 2017
1 parent 9863ea3 commit 7f00a68
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@types/node": "^7.0.12",
"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",
Expand Down
6 changes: 0 additions & 6 deletions src/custom-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
Expand Down
6 changes: 2 additions & 4 deletions src/live-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
Expand All @@ -77,8 +76,7 @@ function enableReactHMR(blacklist) {
.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())))
Expand Down
33 changes: 12 additions & 21 deletions src/pathwatcher-rx.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
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';

export function watchPathDirect(directory) {
return Observable.create((subj) => {
let watcher = null;
let dead = false;

try {
watcher = fs.watch(directory, {}, (eventType, fileName) => {
if (dead) return;
subj.next({eventType, fileName});
});

watcher.on('error', (e) => {
dead = true;
subj.error(e);
});
} catch (e) {
const watcher = new Gaze();
watcher.on('error', (err) => {
dead = true;
if (e.code === "ENOENT") {
// that's ok, we just won't watch the non-existent directory
} else {
// if it's not that, let's log and continue
console.warn(e.message);
}
}
return new Subscription(() => { if (!dead && watcher) { watcher.close(); } });
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(); } });
});
}

Expand Down

0 comments on commit 7f00a68

Please sign in to comment.