Skip to content

Commit

Permalink
renamed initConfigurations to lifecycleHandlers
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanpodila committed Mar 25, 2024
1 parent c8fea66 commit 2893cfb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ gen-vyuh_core: (_generate-json "packages/system/vyuh_core" "watch")
gen-vyuh_extension_script: (_generate-json "packages/system/vyuh_extension_script" "watch")
gen-vyuh_extension_content: (_generate-json "packages/system/vyuh_extension_content" "watch")
gen-vyuh_feature_system: (_generate-json "packages/system/vyuh_feature_system" "watch")
gen-feature_sample: (_generate-json "features/sample/feature_sample" "watch")
gen-feature_sample: (_generate-json "features/feature_sample" "watch")

_generate-json package command="build":
#!/usr/bin/env bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class ContentExtensionDescriptor extends ExtensionDescriptor {
this.contentBuilders,
this.actions,
this.conditions,
this.routeInitializers,
this.lifecycleHandlers,
this.routeTypes,
}) : super(title: 'Content Extension');

final List<ContentDescriptor>? contents;
final List<ContentBuilder>? contentBuilders;
final List<TypeDescriptor<ActionConfiguration>>? actions;
final List<TypeDescriptor<ConditionConfiguration>>? conditions;
final List<TypeDescriptor<RouteInitConfiguration>>? routeInitializers;
final List<TypeDescriptor<RouteLifecycleHandler>>? lifecycleHandlers;
final List<TypeDescriptor<RouteTypeConfiguration>>? routeTypes;
}

Expand All @@ -29,10 +29,10 @@ abstract class RouteTypeConfiguration {
Page<T> create<T>(Widget child, RouteBase route);
}

abstract class RouteInitConfiguration {
abstract class RouteLifecycleHandler {
final String? title;

RouteInitConfiguration({this.title});
RouteLifecycleHandler({this.title});

Future<void> init(RouteBase route);

Expand Down
28 changes: 13 additions & 15 deletions packages/system/vyuh_feature_system/lib/content/route/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ final class Route extends RouteBase {
required super.id,
super.category,
super.layout,
this.initConfigurations,
this.lifecycleHandlers,
}) : super(schemaType: Route.schemaName) {
setParent(regions.expand((element) => element.items));
}

@JsonKey(defaultValue: [], fromJson: initConfigurationsFromJson)
final List<RouteInitConfiguration>? initConfigurations;
@JsonKey(defaultValue: [], fromJson: lifecycleHandlersFromJson)
final List<RouteLifecycleHandler>? lifecycleHandlers;

factory Route.fromJson(Map<String, dynamic> json) => _$RouteFromJson(json);

static List<RouteInitConfiguration>? initConfigurationsFromJson(
dynamic json) =>
listFromJson<RouteInitConfiguration>(json);
static List<RouteLifecycleHandler>? lifecycleHandlersFromJson(dynamic json) =>
listFromJson<RouteLifecycleHandler>(json);

flutter.Page<T> createPage<T>(flutter.BuildContext context) {
final child = kDebugMode
Expand All @@ -57,8 +56,8 @@ final class Route extends RouteBase {
return _initializedInstance;
}

if (initConfigurations != null && initConfigurations!.isNotEmpty) {
for (final config in initConfigurations!) {
if (lifecycleHandlers != null && lifecycleHandlers!.isNotEmpty) {
for (final config in lifecycleHandlers!) {
await config.init(this);
}
}
Expand All @@ -69,8 +68,8 @@ final class Route extends RouteBase {

@override
Future<void> dispose() async {
if (initConfigurations != null && initConfigurations!.isNotEmpty) {
for (final config in initConfigurations!) {
if (lifecycleHandlers != null && lifecycleHandlers!.isNotEmpty) {
for (final config in lifecycleHandlers!) {
await config.dispose();
}
}
Expand All @@ -95,11 +94,11 @@ final class Region {
}

final class RouteDescriptor extends ContentDescriptor {
List<TypeDescriptor<RouteInitConfiguration>>? initConfigurations;
List<TypeDescriptor<RouteLifecycleHandler>>? lifecycleHandlers;
List<TypeDescriptor<RouteTypeConfiguration>>? routeTypes;

RouteDescriptor({
this.initConfigurations,
this.lifecycleHandlers,
this.routeTypes,
super.layouts,
}) : super(schemaType: Route.schemaName, title: 'Route');
Expand All @@ -122,11 +121,10 @@ final class RouteContentBuilder extends ContentBuilder<Route> {

final rtDescriptors = descriptors.cast<RouteDescriptor>();
final initConfigs = rtDescriptors.expand((element) =>
element.initConfigurations ??
<TypeDescriptor<RouteInitConfiguration>>[]);
element.lifecycleHandlers ?? <TypeDescriptor<RouteLifecycleHandler>>[]);

for (final config in initConfigs) {
vyuh.content.register<RouteInitConfiguration>(config);
vyuh.content.register<RouteLifecycleHandler>(config);
}

final routeTypes = rtDescriptors.expand((element) =>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2893cfb

Please sign in to comment.