Skip to content

Commit

Permalink
Apply review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Oct 31, 2024
1 parent b7ee917 commit 6174cdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
48 changes: 24 additions & 24 deletions lib/src/io/js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,30 @@ Future<Stream<WatchEvent>> watchDir(String path, {bool poll = false}) async {
// Don't assign the controller until after the ready event fires. Otherwise,
// Chokidar will give us a bunch of add events for files that already exist.
StreamController<WatchEvent>? controller;
if (poll || parcelWatcher == null) {
if (parcelWatcher case var parcel? when !poll) {
var subscription = await parcel.subscribe(path,
(Object? error, List<ParcelWatcherEvent> events) {
if (error != null) {
controller?.addError(error);
} else {
for (var event in events) {
switch (event.type) {
case 'create':
controller?.add(WatchEvent(ChangeType.ADD, event.path));
case 'update':
controller?.add(WatchEvent(ChangeType.MODIFY, event.path));
case 'delete':
controller?.add(WatchEvent(ChangeType.REMOVE, event.path));
}
}
}
});

return (controller = StreamController<WatchEvent>(onCancel: () {
subscription.unsubscribe();
}))
.stream;
} else {
var watcher = chokidar.watch(path, ChokidarOptions(usePolling: poll));
watcher
..on(
Expand Down Expand Up @@ -286,28 +309,5 @@ Future<Stream<WatchEvent>> watchDir(String path, {bool poll = false}) async {
}));

return completer.future;
} else {
var subscription = await parcelWatcher!.subscribe(path,
(Object? error, List<ParcelWatcherEvent> events) {
if (error != null) {
controller?.addError(error);
} else {
for (var event in events) {
switch (event.type) {
case 'create':
controller?.add(WatchEvent(ChangeType.ADD, event.path));
case 'update':
controller?.add(WatchEvent(ChangeType.MODIFY, event.path));
case 'delete':
controller?.add(WatchEvent(ChangeType.REMOVE, event.path));
}
}
}
});

return (controller = StreamController<WatchEvent>(onCancel: () {
subscription.unsubscribe();
}))
.stream;
}
}
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ dependencies:
args: ^2.0.0
async: ^2.5.0
charcode: ^1.2.0
cli_pkg:
git: https://github.com/google/dart_cli_pkg.git
cli_pkg: ^2.11.0
cli_repl: ^0.2.1
collection: ^1.16.0
http: ^1.1.0
Expand Down

0 comments on commit 6174cdf

Please sign in to comment.