Skip to content

Commit 7f00a68

Browse files
fvgsfasterthanlime
authored andcommitted
1 parent 9863ea3 commit 7f00a68

File tree

4 files changed

+15
-31
lines changed

4 files changed

+15
-31
lines changed

package.json

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

src/custom-operators.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ 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-
3327
retryAtIntervals: function(maxRetries = 3) {
3428
return this.retryWhen((errors) => retryWithDelayOrError(errors, maxRetries));
3529
},

src/live-reload.js

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

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

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

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

8381
return weShouldReload
8482
.switchMap(() => Observable.defer(() => Observable.fromPromise(triggerHMRInRenderers()).catch(() => Observable.empty())))

src/pathwatcher-rx.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
1-
import fs from 'fs';
21
import {Observable} from 'rxjs/Observable';
32
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;
1110
let dead = false;
1211

13-
try {
14-
watcher = fs.watch(directory, {}, (eventType, fileName) => {
15-
if (dead) return;
16-
subj.next({eventType, fileName});
17-
});
18-
19-
watcher.on('error', (e) => {
20-
dead = true;
21-
subj.error(e);
22-
});
23-
} catch (e) {
12+
const watcher = new Gaze();
13+
watcher.on('error', (err) => {
2414
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(); } });
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+
});
22+
23+
return new Subscription(() => { if (!dead) { watcher.close(); } });
3324
});
3425
}
3526

0 commit comments

Comments
 (0)