drift/moor/lib/moor_web.dart

39 lines
1.2 KiB
Dart
Raw Normal View History

/// A version of moor that runs on the web by using [sql.js](https://github.com/sql-js/sql.js)
2019-07-03 12:51:56 -07:00
/// You manually need to include that library into your website to use the
/// web version of moor. See [the documentation](https://moor.simonbinder.eu/web)
/// for a more detailed instruction.
@experimental
library moor_web;
import 'dart:async';
import 'dart:html';
import 'dart:indexed_db';
import 'dart:js';
import 'package:meta/meta.dart';
2021-01-31 12:50:12 -08:00
import 'package:stream_channel/stream_channel.dart';
import 'backends.dart';
import 'moor.dart';
import 'src/web/binary_string_conversion.dart';
import 'src/web/sql_js.dart';
part 'src/web/storage.dart';
part 'src/web/web_db.dart';
2021-01-31 12:50:12 -08:00
/// Extension to transform a raw [MessagePort] from web workers into a Dart
/// [StreamChannel].
extension PortToChannel on MessagePort {
/// Converts this port to a two-way communication channel, exposed as a
/// [StreamChannel].
///
/// This can be used to implement
StreamChannel<Object?> channel() {
final controller = StreamChannelController();
onMessage.map((event) => event.data).pipe(controller.local.sink);
controller.local.stream.listen(postMessage, onDone: close);
return controller.foreign;
}
}