From a53c6d9529b3d3383b18d91ee403721d2b807e57 Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Wed, 10 Jan 2024 23:22:35 +0100 Subject: [PATCH 1/2] fix incompatible build_daemon and webdev versions in jaspr_cli --- packages/jaspr/CHANGELOG.md | 1 + packages/jaspr_cli/analysis_options.yaml | 2 +- packages/jaspr_cli/pubspec.yaml | 14 ++++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/jaspr/CHANGELOG.md b/packages/jaspr/CHANGELOG.md index 5dbb8a3a..741ed328 100644 --- a/packages/jaspr/CHANGELOG.md +++ b/packages/jaspr/CHANGELOG.md @@ -3,6 +3,7 @@ - Promoted `jaspr_web_compilers` to non-experimental status and changed cli command `jaspr create --experimental-web-compilers` to `jaspr create --jaspr-web-compilers` - Fixed error on windows when running `jaspr build`. +- Fixed error with `jaspr serve` related to the use of `webdev`. ## 0.9.3 diff --git a/packages/jaspr_cli/analysis_options.yaml b/packages/jaspr_cli/analysis_options.yaml index 8735d3fc..4f191d8e 100644 --- a/packages/jaspr_cli/analysis_options.yaml +++ b/packages/jaspr_cli/analysis_options.yaml @@ -6,7 +6,7 @@ analyzer: linter: rules: - sort_pub_dependencies: true + sort_pub_dependencies: false # to group packages semantically prefer_relative_imports: true directives_ordering: true avoid_print: true diff --git a/packages/jaspr_cli/pubspec.yaml b/packages/jaspr_cli/pubspec.yaml index 310161c8..03782210 100644 --- a/packages/jaspr_cli/pubspec.yaml +++ b/packages/jaspr_cli/pubspec.yaml @@ -21,21 +21,23 @@ executables: dependencies: ansi_styles: ^0.3.2 args: ^2.3.0 - build_daemon: ^4.0.0 - cli_completion: ^0.3.0 + cli_completion: ^0.4.0 cli_util: ^0.4.0 collection: ^1.17.1 - dwds: ^19.0.0 - http: ^0.13.6 + http: ^0.13.4 io: ^1.0.4 logging: ^1.1.1 mason: ^0.1.0-dev.31 meta: ^1.7.0 path: ^1.8.0 pub_updater: ^0.3.0 - webdev: ^3.0.0 yaml: ^3.1.0 + # The following packages don't adhere to semantic versioning and might ship breaking changes in minor versions. + # Therefore, we depend on fixed versions of these packages. + build_daemon: 4.0.1 + dwds: 23.0.0 + webdev: 3.3.0 dev_dependencies: - lints: ^2.1.0 + lints: ^3.0.0 test: ^1.22.0 From 8454473fbd688bcc67dc53b460e502a0d84132a0 Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Wed, 10 Jan 2024 23:35:11 +0100 Subject: [PATCH 2/2] reorganize state mixins --- packages/jaspr/lib/src/foundation/sync.dart | 54 +++++++++++++++++ .../jaspr/lib/src/framework/framework.dart | 3 - .../jaspr/lib/src/framework/state_mixins.dart | 60 ------------------- .../lib/src/framework/stateful_component.dart | 7 +++ 4 files changed, 61 insertions(+), 63 deletions(-) delete mode 100644 packages/jaspr/lib/src/framework/state_mixins.dart diff --git a/packages/jaspr/lib/src/foundation/sync.dart b/packages/jaspr/lib/src/foundation/sync.dart index c61c19cc..792ad9b7 100644 --- a/packages/jaspr/lib/src/foundation/sync.dart +++ b/packages/jaspr/lib/src/foundation/sync.dart @@ -3,6 +3,8 @@ import 'dart:convert'; import 'package:binary_codec/binary_codec.dart'; import 'package:meta/meta.dart'; +import '../framework/framework.dart'; + mixin SyncBinding { /// Returns the accumulated data from all active [State]s that use the [SyncStateMixin] @protected @@ -102,6 +104,58 @@ abstract class SyncState { bool wantsSync(); } +/// Mixin on [State] that syncs state data from the server with the client +/// +/// Requires a [GlobalKey] on the component. +mixin SyncStateMixin on State implements SyncState { + /// Codec used to serialize the state data on the server and deserialize on the client + /// Should convert the state to any dynamic type: Null, bool, double, int, Uint8List, String, Map, List + @override + Codec? get syncCodec => null; + + /// Globally unique id used to identify the state data between server and client + /// Returns null if state should not be synced + @override + String get syncId; + + /// Called on the client when a new state value is available, either when the state is first initialized, or when the + /// state becomes available through lazy loading a route. + /// + /// On initialization, this will be called as part of the `super.initState()` call. It is recommended to start with the + /// inherited method call in you custom `initState()` implementation, however when you want to do some work before the + /// initial `updateState()` call, you can invoke the `super.initState()` later in your implementation. + /// + /// ```dart + /// @override + /// void initState() { + /// // do some pre-initialization + /// super.initState(); // this will also call your updateState() implementation + /// // do some post-initialization + /// } + /// ``` + /// + /// The framework won't call setState() for you, so you have to call it yourself if you want to rebuild the component. + /// That allows for custom update logic and reduces unnecessary builds. + @override + void updateState(U? value); + + /// Can be overridden to signal that the state should not be synced + @override + bool wantsSync() => true; + + @override + void initState() { + super.initState(); + context.binding.registerSyncState(this, initialUpdate: context.binding.isClient); + } + + @override + void dispose() { + context.binding.unregisterSyncState(this); + super.dispose(); + } +} + extension _SyncEncoding on SyncState { _update(dynamic data) { if (data == null || syncCodec == null) { diff --git a/packages/jaspr/lib/src/framework/framework.dart b/packages/jaspr/lib/src/framework/framework.dart index 3bc646c9..110e7452 100644 --- a/packages/jaspr/lib/src/framework/framework.dart +++ b/packages/jaspr/lib/src/framework/framework.dart @@ -6,13 +6,11 @@ library framework; import 'dart:async'; import 'dart:collection'; -import 'dart:convert'; import 'package:meta/meta.dart'; import '../foundation/basic_types.dart'; import '../foundation/binding.dart'; -import '../foundation/sync.dart'; import '../ui/styles/styles.dart'; part 'build_context.dart'; @@ -27,7 +25,6 @@ part 'observer_component.dart'; part 'render_element.dart'; part 'render_scope.dart'; part 'single_child_element.dart'; -part 'state_mixins.dart'; part 'stateful_component.dart'; part 'stateless_component.dart'; diff --git a/packages/jaspr/lib/src/framework/state_mixins.dart b/packages/jaspr/lib/src/framework/state_mixins.dart deleted file mode 100644 index 4acf73d6..00000000 --- a/packages/jaspr/lib/src/framework/state_mixins.dart +++ /dev/null @@ -1,60 +0,0 @@ -part of framework; - -/// Mixin on [State] that syncs state data from the server with the client -/// -/// Requires a [GlobalKey] on the component. -mixin SyncStateMixin on State implements SyncState { - /// Codec used to serialize the state data on the server and deserialize on the client - /// Should convert the state to any dynamic type: Null, bool, double, int, Uint8List, String, Map, List - @override - Codec? get syncCodec => null; - - /// Globally unique id used to identify the state data between server and client - /// Returns null if state should not be synced - @override - String get syncId; - - /// Called on the client when a new state value is available, either when the state is first initialized, or when the - /// state becomes available through lazy loading a route. - /// - /// On initialization, this will be called as part of the `super.initState()` call. It is recommended to start with the - /// inherited method call in you custom `initState()` implementation, however when you want to do some work before the - /// initial `updateState()` call, you can invoke the `super.initState()` later in your implementation. - /// - /// ```dart - /// @override - /// void initState() { - /// // do some pre-initialization - /// super.initState(); // this will also call your updateState() implementation - /// // do some post-initialization - /// } - /// ``` - /// - /// The framework won't call setState() for you, so you have to call it yourself if you want to rebuild the component. - /// That allows for custom update logic and reduces unnecessary builds. - @override - void updateState(U? value); - - /// Can be overridden to signal that the state should not be synced - @override - bool wantsSync() => true; - - @override - void initState() { - super.initState(); - context.binding.registerSyncState(this, initialUpdate: context.binding.isClient); - } - - @override - void dispose() { - context.binding.unregisterSyncState(this); - super.dispose(); - } -} - -/// Mixin on [State] that preloads state on the server -mixin PreloadStateMixin on State { - /// Called on the server before initState() to preload asynchronous data - @protected - Future preloadState(); -} diff --git a/packages/jaspr/lib/src/framework/stateful_component.dart b/packages/jaspr/lib/src/framework/stateful_component.dart index bd36e8b8..31f17fe7 100644 --- a/packages/jaspr/lib/src/framework/stateful_component.dart +++ b/packages/jaspr/lib/src/framework/stateful_component.dart @@ -575,6 +575,13 @@ abstract class State { void didChangeDependencies() {} } +/// Mixin on [State] that preloads state on the server +mixin PreloadStateMixin on State { + /// Called on the server before initState() to preload asynchronous data + @protected + Future preloadState(); +} + /// An [Element] that uses a [StatefulComponent] as its configuration. class StatefulElement extends MultiChildElement { /// Creates an element that uses the given component as its configuration.