Skip to content

Commit

Permalink
Fix compat check button in Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Jan 31, 2025
1 parent b1577fb commit 087afb8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/docs/Platforms/web.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ browser in that case.
Clicking on the button will start a feature detection run, so you can see which file system
implementation drift would pick on this browser and which web APIs are missing.

<button class="md-button" id="drift-compat-btn">Check compatibility</button>
<button class="md-button" id="drift-compat-btn" onClick="start_compat_check()">Check compatibility</button>

<pre id="drift-compat-results", style="display: flex; flex-direction: column;">
Compatibility check not started yet
Expand Down
3 changes: 2 additions & 1 deletion docs/lib/snippets/_shared/todo_tables.drift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ class $$CategoriesTableTableManager extends i0.RootTableManager<
getPrefetchedDataCallback: (items) async {
return [
if (todoItemsRefs)
await i0.$_getPrefetchedData(
await i0.$_getPrefetchedData<i1.Category,
i1.$CategoriesTable, i1.TodoItem>(
currentTable: table,
referencedTable: i1.$$CategoriesTableReferences
._todoItemsRefsTable(db),
Expand Down
3 changes: 2 additions & 1 deletion docs/lib/snippets/modular/drift/example.drift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ class $CategoriesTableManager extends i0.RootTableManager<
getPrefetchedDataCallback: (items) async {
return [
if (todosRefs)
await i0.$_getPrefetchedData(
await i0.$_getPrefetchedData<i1.Category, i1.Categories,
i1.Todo>(
currentTable: table,
referencedTable:
i1.$CategoriesReferences._todosRefsTable(db),
Expand Down
3 changes: 2 additions & 1 deletion docs/lib/snippets/modular/many_to_many/relational.drift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class $$ShoppingCartsTableTableManager extends i0.RootTableManager<
getPrefetchedDataCallback: (items) async {
return [
if (shoppingCartEntriesRefs)
await i0.$_getPrefetchedData(
await i0.$_getPrefetchedData<i2.ShoppingCart,
i2.$ShoppingCartsTable, i2.ShoppingCartEntry>(
currentTable: table,
referencedTable: i2.$$ShoppingCartsTableReferences
._shoppingCartEntriesRefsTable(db),
Expand Down
1 change: 1 addition & 0 deletions docs/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
drift_postgres:
path: ^1.8.2
json_annotation: ^4.9.0
web: ^1.1.0
# used in snippets
http: ^1.1.0
sqlite3: ^2.0.0
Expand Down
50 changes: 29 additions & 21 deletions docs/web/compatibility.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
import 'dart:html';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';

import 'package:drift/wasm.dart';
import 'package:web/web.dart';

void main() async {
final btn = querySelector('#drift-compat-btn')!;
final results = querySelector('#drift-compat-results')!;
window.setProperty(
'start_compat_check'.toJS,
() {
Future(() async {
final btn = document.querySelector('#drift-compat-btn')!;
final results =
document.querySelector('#drift-compat-results') as HTMLElement;

await for (final _ in btn.onClick) {
btn.attributes['disabled'] = 'true';
results.innerText = '';
btn.attributes['disabled'] = 'true'.toJS;
results.innerText = '';

try {
final db = await WasmDatabase.open(
databaseName: 'test_db',
// These URLs need to be absolute because we're serving this JS file
// under `/web`.
sqlite3Uri: Uri.parse('/sqlite3.wasm'),
driftWorkerUri: Uri.parse('/drift_worker.dart.js'),
);
try {
final db = await WasmDatabase.open(
databaseName: 'test_db',
// These URLs need to be absolute because we're serving this JS file
// under `/web`.
sqlite3Uri: Uri.parse('/sqlite3.wasm'),
driftWorkerUri: Uri.parse('/drift_worker.dart.js'),
);

results.innerText += '''
results.innerText += '''
Chosen implementation: ${db.chosenImplementation}
Features missing: ${db.missingFeatures}
''';
} catch (e, s) {
results.innerText += 'Error: $e, Trace: \n$s';
} finally {
btn.attributes.remove('disabled');
}
}
await db.resolvedExecutor.close();
} catch (e, s) {
results.innerText += 'Error: $e, Trace: \n$s';
} finally {
btn.attributes['disabled'] = 'false'.toJS;
}
});
}.toJS);
}

0 comments on commit 087afb8

Please sign in to comment.