Skip to content

Commit

Permalink
migrate to universal_web, refactor GlobalKey and add GlobalStateKey a…
Browse files Browse the repository at this point in the history
…nd GlobalNodeKey
  • Loading branch information
schultek committed Jan 5, 2025
1 parent 5d01056 commit d7e2cb1
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 104 deletions.
2 changes: 1 addition & 1 deletion packages/jaspr/lib/jaspr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export 'src/foundation/basic_types.dart';
export 'src/foundation/binding.dart';
export 'src/foundation/change_notifier.dart';
export 'src/foundation/constants.dart';
export 'src/foundation/events/events.dart';
export 'src/foundation/events.dart';
export 'src/foundation/object.dart';
export 'src/foundation/options.dart';
export 'src/foundation/scheduler.dart';
Expand Down
6 changes: 4 additions & 2 deletions packages/jaspr/lib/src/browser/dom_render_object.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:async';
import 'dart:js_interop';

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

import '../foundation/constants.dart';
import '../foundation/events/events.dart';
import '../foundation/events.dart';
import '../framework/framework.dart';
import 'utils.dart';

Expand All @@ -15,7 +15,9 @@ const xmlns = {
};

class DomRenderObject extends RenderObject {
@override
web.Node? node;

List<web.Node> toHydrate = [];

Map<String, EventBinding>? events;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ abstract class Document implements Component {
}) = AttachDocument.body;
}

// only allow a single document
const _documentKey = GlobalKey();
// Only allow a single Document.
const _documentKey = _DocumentKey();

class _DocumentKey extends GlobalKey {
const _DocumentKey() : super.constructor();
}

class BaseDocument extends StatelessComponent implements Document {
const BaseDocument({
Expand Down
2 changes: 1 addition & 1 deletion packages/jaspr/lib/src/components/html/html.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../../foundation/basic_types.dart';
import '../../foundation/events/events.dart';
import '../../foundation/events.dart';
import '../../foundation/styles/styles.dart';
import '../../framework/framework.dart';
import '../raw_text/raw_text.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '../../components/html/html.dart';
import '../basic_types.dart';
import 'web.dart' if (dart.library.io) 'web_stub.dart' as web;
import 'package:universal_web/js_interop.dart';
import 'package:universal_web/web.dart' as web;

export 'web.dart' if (dart.library.io) 'web_stub.dart' show Event;
import '../components/html/html.dart';
import 'basic_types.dart';

typedef EventCallback = void Function(web.Event event);
typedef EventCallbacks = Map<String, EventCallback>;
Expand Down
3 changes: 0 additions & 3 deletions packages/jaspr/lib/src/foundation/events/web.dart

This file was deleted.

42 changes: 0 additions & 42 deletions packages/jaspr/lib/src/foundation/events/web_stub.dart

This file was deleted.

17 changes: 17 additions & 0 deletions packages/jaspr/lib/src/foundation/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ String objectRuntimeType(Object? object, String optimizedValue) {
}());
return optimizedValue;
}

/// Returns a 5 character long hexadecimal string generated from
/// [Object.hashCode]'s 20 least-significant bits.
String shortHash(Object? object) {
return object.hashCode.toUnsigned(20).toRadixString(16).padLeft(5, '0');
}

/// Returns a summary of the runtime type and hash code of `object`.
///
/// See also:
///
/// * [Object.hashCode], a value used when placing an object in a [Map] or
/// other similar data structure, and which is also used in debug output to
/// distinguish instances of the same class (hash collisions are
/// possible, but rare enough that its use in debug output is useful).
/// * [Object.runtimeType], the [Type] of an object.
String describeIdentity(Object? object) => '${objectRuntimeType(object, '<optimized out>')}#${shortHash(object)}';
3 changes: 2 additions & 1 deletion packages/jaspr/lib/src/framework/framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import 'dart:async';
import 'dart:collection';

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

import '../foundation/basic_types.dart';
import '../foundation/binding.dart';
import '../foundation/events/events.dart';
import '../foundation/events.dart';
import '../foundation/object.dart';
import '../foundation/styles/styles.dart';

Expand Down
Loading

0 comments on commit d7e2cb1

Please sign in to comment.