Skip to content

Commit

Permalink
Merge branch 'main' into improvement/render_objects
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/jaspr/lib/src/framework/framework.dart
  • Loading branch information
Kilian Schulte committed Jan 11, 2024
2 parents 9e33bf6 + 8454473 commit 273e2af
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 70 deletions.
1 change: 1 addition & 0 deletions packages/jaspr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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

Expand Down
54 changes: 54 additions & 0 deletions packages/jaspr/lib/src/foundation/sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,6 +104,58 @@ abstract class SyncState<U> {
bool wantsSync();
}

/// Mixin on [State] that syncs state data from the server with the client
///
/// Requires a [GlobalKey] on the component.
mixin SyncStateMixin<T extends StatefulComponent, U> on State<T> implements SyncState<U> {
/// 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<U, dynamic>? 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

Check warning on line 152 in packages/jaspr/lib/src/foundation/sync.dart

View check run for this annotation

Codecov / codecov/patch

packages/jaspr/lib/src/foundation/sync.dart#L152

Added line #L152 was not covered by tests
void dispose() {
context.binding.unregisterSyncState(this);
super.dispose();

Check warning on line 155 in packages/jaspr/lib/src/foundation/sync.dart

View check run for this annotation

Codecov / codecov/patch

packages/jaspr/lib/src/foundation/sync.dart#L154-L155

Added lines #L154 - L155 were not covered by tests
}
}

extension _SyncEncoding<U> on SyncState<U> {
_update(dynamic data) {
if (data == null || syncCodec == null) {
Expand Down
3 changes: 0 additions & 3 deletions packages/jaspr/lib/src/framework/framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ 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/object.dart';
import '../foundation/sync.dart';
import '../ui/styles/styles.dart';

part 'build_context.dart';
Expand All @@ -28,7 +26,6 @@ part 'notification.dart';
part 'observer_component.dart';
part 'render_object.dart';
part 'single_child_element.dart';
part 'state_mixins.dart';
part 'stateful_component.dart';
part 'stateless_component.dart';

Expand Down
60 changes: 0 additions & 60 deletions packages/jaspr/lib/src/framework/state_mixins.dart

This file was deleted.

7 changes: 7 additions & 0 deletions packages/jaspr/lib/src/framework/stateful_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,13 @@ abstract class State<T extends StatefulComponent> {
void didChangeDependencies() {}
}

/// Mixin on [State] that preloads state on the server
mixin PreloadStateMixin<T extends StatefulComponent> on State<T> {
/// Called on the server before initState() to preload asynchronous data
@protected
Future<void> 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.
Expand Down
2 changes: 1 addition & 1 deletion packages/jaspr_cli/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 8 additions & 6 deletions packages/jaspr_cli/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 273e2af

Please sign in to comment.