Skip to content

Commit 4f55cb7

Browse files
koji-1009simolus3
andauthored
fix: Add conditional export to support --wasm build (#3363)
* fix: Add conditional export to support --wasm build * Add stubs for extension --------- Co-authored-by: Simon Binder <[email protected]>
1 parent 3581453 commit 4f55cb7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:stream_channel/stream_channel.dart';
2+
3+
/// Extension to transform a raw `MessagePort` from web workers into a Dart
4+
/// [StreamChannel].
5+
extension PortToChannel on dynamic {
6+
/// Converts this port to a two-way communication channel, exposed as a
7+
/// [StreamChannel].
8+
///
9+
/// This can be used to implement a remote database connection over service
10+
/// workers.
11+
///
12+
/// The [explicitClose] parameter can be used to control whether a close
13+
/// message should be sent through the channel when it is closed. This will
14+
/// cause it to be closed on the other end as well. Note that this is not a
15+
/// reliable way of determining channel closures though, as there is no event
16+
/// for channels being closed due to a tab or worker being closed.
17+
/// Both "ends" of a JS channel calling [channel] on their part must use the
18+
/// value for [explicitClose].
19+
@Deprecated(
20+
'Please use MessagePorts from package:web instead of those from dart:html. '
21+
'This extension will be removed from drift once `dart:html` is removed '
22+
'from the SDK.',
23+
)
24+
StreamChannel<Object?> channel({bool explicitClose = false}) {
25+
throw 'If this import was resolved, dart:html is not available.';
26+
}
27+
}

drift/lib/web.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ library drift.web;
1212
export 'src/web/sql_js.dart';
1313
export 'src/web/storage.dart' hide CustomSchemaVersionSave;
1414
export 'src/web/web_db.dart';
15-
export 'src/web/channel_legacy.dart';
15+
export 'src/web/channel_legacy_dummy.dart'
16+
if (dart.library.html) 'src/web/channel_legacy.dart';
1617
export 'src/web/channel_new.dart';

0 commit comments

Comments
 (0)