Skip to content

Commit

Permalink
making most fields optional in PluginDescriptor for better ergonomics
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanpodila committed Sep 18, 2024
1 parent 92bec0f commit 0b8d6d4
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions packages/system/vyuh_core/lib/plugin/plugin_descriptor.dart
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
import 'package:vyuh_core/plugin/content/noop_content_plugin.dart';
import 'package:vyuh_core/plugin/di/di_plugin.dart';
import 'package:vyuh_core/plugin/di/plugin_di_get_it.dart';
import 'package:vyuh_core/plugin/plugin.dart';

import 'analytics/analytics_plugin.dart';
import 'analytics/noop_analytics_provider.dart';
import 'auth/anonymous_auth_plugin.dart';
import 'auth/auth_plugin.dart';
import 'content/content_plugin.dart';
import 'navigation/default_navigation_plugin.dart';
import 'navigation/navigation.dart';
import 'network/http_network_plugin.dart';
import 'network/network_plugin.dart';
import 'package:vyuh_core/plugin/auth/anonymous_auth_plugin.dart';
import 'package:vyuh_core/vyuh_core.dart';

final class PluginDescriptor {
final Set<Plugin> _plugins = {};

List<Plugin> get plugins => List.unmodifiable(_plugins);

PluginDescriptor({
required final DIPlugin di,
required final ContentPlugin content,
required final AnalyticsPlugin analytics,
required final NetworkPlugin network,
required final AuthPlugin auth,
required final NavigationPlugin navigation,
final DIPlugin? di,
final ContentPlugin? content,
final AnalyticsPlugin? analytics,
final NetworkPlugin? network,
final AuthPlugin? auth,
final NavigationPlugin? navigation,
final List<Plugin>? others,
}) {
_plugins.addAll([
di,
content,
analytics,
network,
auth,
navigation,
navigation,
di ?? defaultPlugins.get<DIPlugin>(),
content ?? defaultPlugins.get<ContentPlugin>(),
analytics ?? defaultPlugins.get<AnalyticsPlugin>(),
network ?? defaultPlugins.get<NetworkPlugin>(),
auth ?? defaultPlugins.get<AuthPlugin>(),
navigation ?? defaultPlugins.get<NavigationPlugin>(),
]);

_plugins.addAll(others ?? []);
}

Expand All @@ -47,4 +35,8 @@ final class PluginDescriptor {
auth: UnknownAuthPlugin(),
navigation: DefaultNavigationPlugin(),
);

Plugin get<T>() {
return _plugins.firstWhere((element) => element is T);
}
}

0 comments on commit 0b8d6d4

Please sign in to comment.