Skip to content

Commit

Permalink
migrate imports to package:universal_web
Browse files Browse the repository at this point in the history
  • Loading branch information
schultek committed Jan 7, 2025
1 parent d7e2cb1 commit 9bf98be
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 49 deletions.
6 changes: 6 additions & 0 deletions packages/jaspr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased minor

- Added `GlobalNodeKey<T extends Node>` to access native dom nodes using `currentNode`.
- **BREAKING** Removed `currentState` from `GlobalKey`, use `GlobalStateKey` instead.
- Migrated all web imports from `package:web` to `package:universal_web`.

## 0.16.4

- Added `--dart-define`, `--dart-define-client` and `--dart-define-server` to `serve` and `build` commands.
Expand Down
2 changes: 1 addition & 1 deletion packages/jaspr/lib/src/browser/browser_binding.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:web/web.dart';
import 'package:universal_web/web.dart';

import '../foundation/basic_types.dart';
import '../foundation/binding.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/jaspr/lib/src/browser/clients.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import 'dart:convert';

import 'package:web/web.dart' as web;
import 'package:universal_web/web.dart' as web;

import '../foundation/marker_utils.dart';
import '../framework/framework.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/jaspr/lib/src/browser/utils.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:web/web.dart' as web;
import 'package:universal_web/web.dart' as web;

extension NodeListIterable on web.NodeList {
Iterable<web.Node> toIterable() sync* {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:js_interop';

import 'package:web/web.dart' as web;
import 'package:universal_web/web.dart' as web;

import '../../../browser.dart';
import '../../browser/utils.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:js_interop';

import 'package:web/web.dart' as web;
import 'package:universal_web/web.dart' as web;

import '../../../browser.dart';
import '../../browser/utils.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:async';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';

import 'package:web/web.dart';
import 'package:universal_web/web.dart';

FutureOr<void> startViewTransition(void Function() callback) {
if (!document.has('startViewTransition')) {
Expand Down
24 changes: 11 additions & 13 deletions packages/jaspr/lib/src/framework/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ abstract class GlobalKey extends Key {
///
/// The label is purely for debugging and not used for comparing the identity
/// of the key.
factory GlobalKey({ String? debugLabel }) => LabeledGlobalKey(debugLabel);
factory GlobalKey({String? debugLabel}) => LabeledGlobalKey(debugLabel);

/// Creates a global key without a label.
///
Expand All @@ -166,7 +166,6 @@ abstract class GlobalKey extends Key {
/// The current component is null if there is no component in the tree that matches
/// this global key.
Component? get currentComponent => _currentElement?.component;

}

/// A global key with a debugging label.
Expand Down Expand Up @@ -247,7 +246,7 @@ class GlobalObjectKey extends GlobalKey {
/// * The discussion at [Component.key] for more information about how components use
/// keys.
class GlobalStateKey<T extends State<StatefulComponent>> extends GlobalKey {
factory GlobalStateKey({ String? debugLabel }) => LabeledGlobalStateKey(debugLabel);
factory GlobalStateKey({String? debugLabel}) => LabeledGlobalStateKey(debugLabel);

Check warning on line 249 in packages/jaspr/lib/src/framework/keys.dart

View check run for this annotation

Codecov / codecov/patch

packages/jaspr/lib/src/framework/keys.dart#L249

Added line #L249 was not covered by tests

/// Creates a global state key without a label.
///
Expand All @@ -261,9 +260,9 @@ class GlobalStateKey<T extends State<StatefulComponent>> extends GlobalKey {
/// matches this global key, (2) that component is not a [StatefulComponent], or the
/// associated [State] object is not a subtype of `T`.
T? get currentState => switch (_currentElement) {
StatefulElement(:final T state) => state,
_ => null,
};
StatefulElement(:final T state) => state,

Check warning on line 263 in packages/jaspr/lib/src/framework/keys.dart

View check run for this annotation

Codecov / codecov/patch

packages/jaspr/lib/src/framework/keys.dart#L262-L263

Added lines #L262 - L263 were not covered by tests
_ => null,
};
}

/// A global state key with a debugging label.
Expand Down Expand Up @@ -342,7 +341,6 @@ class GlobalObjectStateKey<T extends State<StatefulComponent>> extends GlobalSta
}
}


/// A global key that provides access to the dom [web.Node] that is associated with its element.
///
/// See also:
Expand All @@ -352,7 +350,7 @@ class GlobalObjectStateKey<T extends State<StatefulComponent>> extends GlobalSta
/// * The discussion at [Component.key] for more information about how components use
/// keys.
class GlobalNodeKey<T extends web.Node> extends GlobalKey {
factory GlobalNodeKey({ String? debugLabel }) => LabeledGlobalNodeKey(debugLabel);
factory GlobalNodeKey({String? debugLabel}) => LabeledGlobalNodeKey(debugLabel);

Check warning on line 353 in packages/jaspr/lib/src/framework/keys.dart

View check run for this annotation

Codecov / codecov/patch

packages/jaspr/lib/src/framework/keys.dart#L353

Added line #L353 was not covered by tests

/// Creates a global node key without a label.
///
Expand All @@ -362,12 +360,12 @@ class GlobalNodeKey<T extends web.Node> extends GlobalKey {

/// The [web.Node] for the component in the tree that currently has this global key.
///
/// The current node is null if (1) the current environment is not web, (2) there is no component
/// The current node is null if (1) the current environment is not web, (2) there is no component
/// in the tree that matches this global key, or (3) its element is not a [RenderObjectElement].
T? get currentNode => switch (_currentElement) {
RenderObjectElement(renderObject: RenderObject(: final T node)) => node,
_ => null,
};
RenderObjectElement(renderObject: RenderObject(:final T node)) => node,
_ => null,

Check warning on line 367 in packages/jaspr/lib/src/framework/keys.dart

View check run for this annotation

Codecov / codecov/patch

packages/jaspr/lib/src/framework/keys.dart#L367

Added line #L367 was not covered by tests
};
}

/// A global node key with a debugging label.
Expand Down Expand Up @@ -444,4 +442,4 @@ class GlobalObjectNodeKey<T extends web.Node> extends GlobalNodeKey<T> {
}
return '[$selfType ${describeIdentity(value)}]';

Check warning on line 443 in packages/jaspr/lib/src/framework/keys.dart

View check run for this annotation

Codecov / codecov/patch

packages/jaspr/lib/src/framework/keys.dart#L443

Added line #L443 was not covered by tests
}
}
}
1 change: 0 additions & 1 deletion packages/jaspr/lib/src/server/markup_render_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import '../../server.dart';
import 'child_nodes.dart';

class MarkupRenderObject extends RenderObject {

String? tag;
String? id;
String? classes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'dart:js_interop';
import 'package:jaspr/browser.dart';
import 'package:jaspr/src/foundation/marker_utils.dart';
import 'package:jaspr_test/browser_test.dart';
import 'package:web/web.dart';
import 'package:universal_web/web.dart';

void main() {
group('hydration browser test', () {
Expand Down
22 changes: 22 additions & 0 deletions packages/jaspr/test/browser/node_key/node_key_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@TestOn('browser')

import 'package:jaspr/jaspr.dart';
import 'package:jaspr_test/browser_test.dart';
import 'package:universal_web/web.dart';

void main() {
group('node_key test', () {
testBrowser('should access node from GlobalNodeKey', (tester) async {
final key = GlobalNodeKey<HTMLInputElement>();

tester.pumpComponent(input(key: key, type: InputType.checkbox, []));

expect(key.currentNode, isNotNull);

final node = key.currentNode!;

expect(node.type, 'checkbox');
expect(node.checked, false);
});
});
}
24 changes: 0 additions & 24 deletions packages/jaspr_test/lib/src/fakes/fake_event.dart

This file was deleted.

5 changes: 2 additions & 3 deletions packages/jaspr_test/lib/src/testers/component_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:test/test.dart';
import 'package:universal_web/web.dart' as web;

import '../binding.dart';
import '../fakes/fake_event.dart';
import '../finders.dart';

@isTest
Expand Down Expand Up @@ -64,9 +63,9 @@ class ComponentTester {
}

/// Simulates [event] on the given element.
void dispatchEvent(Finder finder, String event,[ web.Event? data]) {
void dispatchEvent(Finder finder, String event, [web.Event? data]) {
var renderObject = _findDomElement(finder).renderObject as TestRenderObject;
renderObject.events?[event]?.call(data ?? fakeEvent(event));
renderObject.events?[event]?.call(data ?? web.Event(event));
}

DomElement _findDomElement(Finder finder) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jaspr_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
jaspr: ^0.16.4
meta: ^1.7.0
test: ^1.22.0
universal_web: ^1.1.0
universal_web: ^1.1.0+1

dev_dependencies:
lints: ^4.0.0

0 comments on commit 9bf98be

Please sign in to comment.