-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathparcel_watcher.dart
49 lines (42 loc) · 1.63 KB
/
parcel_watcher.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2024 Google Inc. Use of this source code is governed by an
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'dart:js_interop';
@JS()
extension type ParcelWatcherSubscription(JSObject _) implements JSObject {
external void unsubscribe();
}
@JS()
extension type ParcelWatcherEvent(JSObject _) implements JSObject {
external String get type;
external String get path;
}
/// The @parcel/watcher module.
///
/// See [the docs on npm](https://www.npmjs.com/package/@parcel/watcher).
@JS()
extension type ParcelWatcher(JSObject _) implements JSObject {
@JS('subscribe')
external JSPromise<ParcelWatcherSubscription> _subscribe(
String path, JSFunction callback);
Future<ParcelWatcherSubscription> subscribe(String path,
void Function(Object? error, List<ParcelWatcherEvent>) callback) =>
_subscribe(
path,
(JSObject? error, JSArray<ParcelWatcherEvent> events) {
callback(error, events.toDart);
}.toJS)
.toDart;
@JS('getEventsSince')
external JSPromise<JSArray<ParcelWatcherEvent>> _getEventsSince(
String path, String snapshotPath);
Future<List<ParcelWatcherEvent>> getEventsSince(
String path, String snapshotPath) async =>
(await _getEventsSince(path, snapshotPath).toDart).toDart;
@JS('writeSnapshot')
external JSPromise<JSAny> _writeSnapshot(String path, String snapshotPath);
Future<void> writeSnapshot(String path, String snapshotPath) =>
_writeSnapshot(path, snapshotPath).toDart;
}
@JS('parcel_watcher')
external ParcelWatcher? get parcelWatcher;