Skip to content

Deprecate a few more things before we launch v2 #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.1

- Deprecated `Node.text` extension. Use `Node.textContent` instead.
- Deprecated `[]` extensions on `Storage`.
Comment on lines +3 to +4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It would be helpful to include the reason for deprecation in the changelog entry. This gives users more context as to why the change was made.


## 1.1.0

- Added `HttpStatus` class that declares http status codes. This is a copy of
Expand Down
1 change: 0 additions & 1 deletion web/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ linter:
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_runtimeType_toString
- package_api_docs
- prefer_const_declarations
- prefer_final_locals
- unnecessary_await_in_return
Expand Down
2 changes: 1 addition & 1 deletion web/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import 'package:web/web.dart';

void main() {
final div = document.querySelector('div')!;
div.text = 'Text set at ${DateTime.now()}';
div.textContent = 'Text set at ${DateTime.now()}';
}
4 changes: 2 additions & 2 deletions web/lib/src/helpers/events/streams.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ class _EventStreamSubscription<T extends html.Event>
// `dart:html` it would have printed 1, 2, 4, 3
//
// ```dart
// import 'package:web/helpers.dart';
// import 'package:web/web.dart';
//
// main() {
// void main() {
// print('1');
// final body = document.body!;
// body.onTouchStart.first.whenComplete(() {
Expand Down
9 changes: 6 additions & 3 deletions web/lib/src/helpers/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ extension HTMLCanvasElementGlue on HTMLCanvasElement {
}

extension CanvasRenderingContext2DGlue on CanvasRenderingContext2D {
@Deprecated('See CanvasRenderingContext2D.drawImage')
void drawImageScaled(
CanvasImageSource image,
double dx,
Expand All @@ -70,6 +71,7 @@ extension CanvasRenderingContext2DGlue on CanvasRenderingContext2D {
}

extension NodeGlue on Node {
@Deprecated('See Node.textContent')
set text(String s) => textContent = s;
Comment on lines +74 to 75

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a more descriptive message to the deprecation annotation, explaining why Node.text is deprecated and what the user should do instead. This will help users understand the reasoning and migrate their code more easily.

  @Deprecated('Use Node.textContent for setting text content. Node.text is deprecated for consistency with the DOM API.')

@Deprecated('See Node.appendChild()')
Node append(Node other) => appendChild(other);
Expand Down Expand Up @@ -98,7 +100,9 @@ extension TouchGlue on Touch {
}

extension StorageGlue on Storage {
@Deprecated('Use Storage.getItem instead')
String? operator [](String key) => getItem(key);
Comment on lines +103 to 104

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the previous comment, adding a more descriptive message to the deprecation annotation for StorageGlue would be beneficial. Explain why the operator is deprecated and what the recommended alternative is.

  @Deprecated('Use Storage.getItem(key) instead of the [] operator.  The operator is deprecated for clarity and consistency.')

@Deprecated('Use Storage.setItem instead')
void operator []=(String key, String value) => setItem(key, value);
Comment on lines +105 to 106

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Same comment as above, adding a more descriptive message to the deprecation annotation for StorageGlue would be beneficial. Explain why the operator is deprecated and what the recommended alternative is.

  @Deprecated('Use Storage.setItem(key, value) instead of the []= operator. The operator is deprecated for clarity and consistency.')

}

Expand All @@ -119,9 +123,8 @@ extension XMLHttpRequestGlue on XMLHttpRequest {
// from Closure's goog.net.Xhrio.getResponseHeaders.
final headers = <String, String>{};
final headersString = getAllResponseHeaders();
final headersList =
LineSplitter.split(headersString).where((header) => header.isNotEmpty);
for (final header in headersList) {
for (final header in LineSplitter.split(headersString)
.where((header) => header.isNotEmpty)) {
final split = header.split(': ');
if (split.length <= 1) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: web
version: 1.1.0
version: 1.1.1
description: Lightweight browser API bindings built around JS interop.
repository: https://github.com/dart-lang/web

Expand Down
6 changes: 3 additions & 3 deletions web/test/helpers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void main() {

test('Converts a JS list to a dart list using JSImmutableListWrapper', () {
final div = (document.createElement('div'))
..append(document.createElement('div')..text = '1')
..append(document.createElement('div')..text = '2')
..append(document.createElement('div')..text = '3');
..append(document.createElement('div')..textContent = '1')
..append(document.createElement('div')..textContent = '2')
..append(document.createElement('div')..textContent = '3');

final List<Node> dartList =
JSImmutableListWrapper<NodeList, Node>(div.querySelectorAll('div'));
Expand Down
1 change: 0 additions & 1 deletion web_generator/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linter:
- literal_only_boolean_expressions
- no_adjacent_strings_in_list
- no_runtimeType_toString
- package_api_docs
- prefer_const_declarations
- prefer_final_locals
- unnecessary_await_in_return
Expand Down
4 changes: 3 additions & 1 deletion web_generator/lib/src/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ class _PartialInterfacelike {
}
final isStatic = operation.special == 'static';
if (shouldQueryMDN &&
!_shouldGenerateMember(operationName, isStatic: isStatic)) break;
!_shouldGenerateMember(operationName, isStatic: isStatic)) {
break;
}
final docs = shouldQueryMDN
? mdnInterface?.propertyFor(operationName, isStatic: isStatic)
: null;
Expand Down
Loading