Skip to content

Commit 8c59543

Browse files
committed
Switch dart:js and dart:js_util usages to use static interop
1 parent 263ea61 commit 8c59543

File tree

8 files changed

+3269
-3445
lines changed

8 files changed

+3269
-3445
lines changed

lib/resources/docs.dart.js

Lines changed: 3218 additions & 3422 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/resources/docs.dart.js.map

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: A non-interactive HTML documentation generator for Dart source code
55
repository: https://github.com/dart-lang/dartdoc
66

77
environment:
8-
sdk: '>=2.17.0 <3.0.0'
8+
sdk: '>=2.18.0 <3.0.0'
99

1010
dependencies:
1111
analyzer: "^5.2.0"
@@ -35,6 +35,7 @@ dev_dependencies:
3535
dart_style: ^2.2.0
3636
grinder: ^0.9.0
3737
http: ^0.13.3
38+
js: 0.6.5
3839
lints: ^2.0.0
3940
test: ^1.19.0
4041
test_descriptor: ^2.0.0

web/docs.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:js' as js;
6-
5+
import 'highlight.dart' as highlight;
76
import 'search.dart' as search;
87
import 'sidenav.dart' as sidenav;
98
import 'theme.dart' as theme;
109

1110
void main() {
12-
inithighlightJS();
11+
highlight.init();
1312
sidenav.init();
1413
search.init();
1514
theme.init();
1615
}
17-
18-
void inithighlightJS() {
19-
js.JsObject hljs = js.context['hljs'];
20-
hljs.callMethod('highlightAll');
21-
}

web/highlight.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:js/js.dart';
2+
3+
void init() {
4+
highlight?.highlightAll();
5+
}
6+
7+
@JS()
8+
@staticInterop
9+
class HighlightJs {}
10+
11+
extension HighlightJsExtension on HighlightJs {
12+
external void highlightAll();
13+
}
14+
15+
@JS('hljs')
16+
external HighlightJs? get highlight;

web/search.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import 'dart:convert';
66
import 'dart:html';
7-
import 'dart:js_util' as js_util;
7+
8+
import 'web_interop.dart';
89

910
final String _htmlBase = () {
1011
final body = document.querySelector('body')!;
@@ -34,14 +35,14 @@ void init() {
3435
}
3536

3637
window.fetch('${_htmlBase}index.json').then((response) async {
37-
int code = js_util.getProperty(response, 'status');
38+
response = response as FetchResponse;
39+
var code = response.status;
3840
if (code == 404) {
3941
disableSearch();
4042
return;
4143
}
4244

43-
var textPromise = js_util.callMethod<Object>(response, 'text', []);
44-
var text = await promiseToFuture<String>(textPromise);
45+
var text = await response.text;
4546
var jsonIndex = (jsonDecode(text) as List).cast<Map<String, dynamic>>();
4647
final index = jsonIndex.map(_IndexItem.fromMap).toList();
4748

@@ -167,7 +168,7 @@ class _Search {
167168
..append(moreResults)
168169
..append(searchResults);
169170

170-
/// Element used in [listbox] to inform the functionality of hitting enter in
171+
/// Element used in [listBox] to inform the functionality of hitting enter in
171172
/// search box.
172173
late final moreResults = document.createElement('div')
173174
..classes.add('enter-search-message');
@@ -516,10 +517,8 @@ void _mapToContainer(Element containerElement, Element suggestion) {
516517

517518
final element = _containerMap[containerInnerHtml];
518519
if (element != null) {
519-
print('appending! ${suggestion.innerHtml}');
520520
element.append(suggestion);
521521
} else {
522-
print('appending2! ${suggestion.innerHtml}');
523522
containerElement.append(suggestion);
524523
_containerMap[containerInnerHtml] = containerElement;
525524
}

web/sig.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
469F5B013C1B0324C1F020C95013AC51
1+
2D8E7D7722AE5937479C00C043788871

web/web_interop.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:js/js.dart';
2+
import 'package:js/js_util.dart' as js_util;
3+
4+
@JS()
5+
@staticInterop
6+
class FetchResponse {}
7+
8+
extension FetchResponseExtension on FetchResponse {
9+
external int get status;
10+
11+
@JS('text')
12+
external Promise _text();
13+
Future<String> get text => js_util.promiseToFuture(_text());
14+
}
15+
16+
@JS()
17+
@staticInterop
18+
class Promise {}

0 commit comments

Comments
 (0)