|
2 | 2 | // MIT-style license that can be found in the LICENSE file or at |
3 | 3 | // https://opensource.org/licenses/MIT. |
4 | 4 |
|
5 | | -import 'package:js/js.dart'; |
6 | | -import 'package:node_interop/js.dart'; |
7 | | -import 'package:node_interop/util.dart'; |
| 5 | +import 'dart:js_interop'; |
8 | 6 |
|
9 | 7 | @JS() |
10 | | -class ParcelWatcherSubscription { |
| 8 | +extension type ParcelWatcherSubscription(JSObject _) implements JSObject { |
11 | 9 | external void unsubscribe(); |
12 | 10 | } |
13 | 11 |
|
14 | 12 | @JS() |
15 | | -class ParcelWatcherEvent { |
| 13 | +extension type ParcelWatcherEvent(JSObject _) implements JSObject { |
16 | 14 | external String get type; |
17 | 15 | external String get path; |
18 | 16 | } |
19 | 17 |
|
20 | 18 | /// The @parcel/watcher module. |
21 | 19 | /// |
22 | 20 | /// See [the docs on npm](https://www.npmjs.com/package/@parcel/watcher). |
23 | | -@JS('parcel_watcher') |
24 | | -class ParcelWatcher { |
25 | | - external static Promise subscribe(String path, Function callback); |
26 | | - static Future<ParcelWatcherSubscription> subscribeFuture(String path, |
| 21 | +@JS() |
| 22 | +extension type ParcelWatcher(JSObject _) implements JSObject { |
| 23 | + @JS('subscribe') |
| 24 | + external JSPromise<ParcelWatcherSubscription> _subscribe( |
| 25 | + String path, JSFunction callback); |
| 26 | + Future<ParcelWatcherSubscription> subscribe(String path, |
27 | 27 | void Function(Object? error, List<ParcelWatcherEvent>) callback) => |
28 | | - promiseToFuture( |
29 | | - subscribe(path, allowInterop((Object? error, List<dynamic> events) { |
30 | | - callback(error, events.cast<ParcelWatcherEvent>()); |
31 | | - }))); |
| 28 | + _subscribe( |
| 29 | + path, |
| 30 | + (JSObject? error, JSArray<ParcelWatcherEvent> events) { |
| 31 | + callback(error, events.toDart); |
| 32 | + }.toJS) |
| 33 | + .toDart; |
32 | 34 |
|
33 | | - external static Promise getEventsSince(String path, String snapshotPath); |
34 | | - static Future<List<ParcelWatcherEvent>> getEventsSinceFuture( |
35 | | - String path, String snapshotPath) async { |
36 | | - List<dynamic> events = |
37 | | - await promiseToFuture(getEventsSince(path, snapshotPath)); |
38 | | - return events.cast<ParcelWatcherEvent>(); |
39 | | - } |
| 35 | + @JS('getEventsSince') |
| 36 | + external JSPromise<JSArray<ParcelWatcherEvent>> _getEventsSince( |
| 37 | + String path, String snapshotPath); |
| 38 | + Future<List<ParcelWatcherEvent>> getEventsSince( |
| 39 | + String path, String snapshotPath) async => |
| 40 | + (await _getEventsSince(path, snapshotPath).toDart).toDart; |
40 | 41 |
|
41 | | - external static Promise writeSnapshot(String path, String snapshotPath); |
42 | | - static Future<void> writeSnapshotFuture(String path, String snapshotPath) => |
43 | | - promiseToFuture(writeSnapshot(path, snapshotPath)); |
| 42 | + @JS('writeSnapshot') |
| 43 | + external JSPromise<JSAny> _writeSnapshot(String path, String snapshotPath); |
| 44 | + Future<void> writeSnapshot(String path, String snapshotPath) => |
| 45 | + _writeSnapshot(path, snapshotPath).toDart; |
44 | 46 | } |
| 47 | + |
| 48 | +@JS('parcel_watcher') |
| 49 | +external ParcelWatcher? get parcelWatcher; |
0 commit comments