Skip to content

Commit 67af889

Browse files
Revert "Merge electron-userland#195"
This reverts commit 7f00a68.
1 parent d7d0ecd commit 67af889

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@types/node": "^7.0.12",
3838
"btoa": "^1.1.2",
3939
"debug": "^2.5.1",
40-
"gaze": "^1.1.2",
4140
"lru-cache": "^4.0.1",
4241
"mkdirp": "^0.5.1",
4342
"pify": "^2.3.0",

src/custom-operators.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ function retryWithDelayOrError(errors, maxRetries) {
2424
}
2525

2626
const newCoolOperators = {
27+
guaranteedThrottle: function(time, scheduler = async) {
28+
return this
29+
.map((x) => Observable.timer(time, scheduler).map(() => x))
30+
.switch();
31+
},
32+
2733
retryAtIntervals: function(maxRetries = 3) {
2834
return this.retryWhen((errors) => retryWithDelayOrError(errors, maxRetries));
2935
},

src/live-reload.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function enableLiveReloadNaive() {
5252
.filter(x => !FileChangedCache.isInNodeModules(x.filePath));
5353

5454
let weShouldReload = filesWeCareAbout
55-
.mergeMap(x => watchPath(x.filePath).map(() => x));
55+
.mergeMap(x => watchPath(x.filePath).map(() => x))
56+
.guaranteedThrottle(1*1000);
5657

5758
return weShouldReload
5859
.switchMap(() => Observable.defer(() => Observable.fromPromise(reloadAllWindows()).timeout(5*1000).catch(() => Observable.empty())))
@@ -76,7 +77,8 @@ function enableReactHMR(blacklist) {
7677
.filter(x => !FileChangedCache.isInNodeModules(x.filePath));
7778

7879
let weShouldReload = filesWeCareAbout
79-
.mergeMap(x => watchPath(x.filePath).map(() => x));
80+
.mergeMap(x => watchPath(x.filePath).map(() => x))
81+
.guaranteedThrottle(1*1000);
8082

8183
return weShouldReload
8284
.switchMap(() => Observable.defer(() => Observable.fromPromise(triggerHMRInRenderers()).catch(() => Observable.empty())))

src/pathwatcher-rx.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1+
import fs from 'fs';
12
import {Observable} from 'rxjs/Observable';
23
import {Subscription} from 'rxjs/Subscription';
3-
import {Gaze} from 'gaze';
44
import LRU from 'lru-cache';
55

66
import 'rxjs/add/operator/publish';
77

88
export function watchPathDirect(directory) {
99
return Observable.create((subj) => {
10+
let watcher = null;
1011
let dead = false;
1112

12-
const watcher = new Gaze();
13-
watcher.on('error', (err) => {
14-
dead = true;
15-
subj.error(err);
16-
});
17-
watcher.add(directory);
18-
watcher.on('changed', (fileName) => {
19-
if (dead) return;
20-
subj.next({fileName, eventType: 'changed'});
21-
});
13+
try {
14+
watcher = fs.watch(directory, {}, (eventType, fileName) => {
15+
if (dead) return;
16+
subj.next({eventType, fileName});
17+
});
2218

23-
return new Subscription(() => { if (!dead) { watcher.close(); } });
19+
watcher.on('error', (e) => {
20+
dead = true;
21+
subj.error(e);
22+
});
23+
} catch (e) {
24+
dead = true;
25+
if (e.code === "ENOENT") {
26+
// that's ok, we just won't watch the non-existent directory
27+
} else {
28+
// if it's not that, let's log and continue
29+
console.warn(e.message);
30+
}
31+
}
32+
return new Subscription(() => { if (!dead && watcher) { watcher.close(); } });
2433
});
2534
}
2635

0 commit comments

Comments
 (0)