From 4458e41b23ff1a5f8c0f9bd05330f8023396d924 Mon Sep 17 00:00:00 2001 From: pavanpodila Date: Tue, 14 Jan 2025 16:51:55 +0530 Subject: [PATCH] updated docs for vyuh-core --- .../docs/framework/packages/vyuh-core.mdx | 119 +++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/src/content/docs/framework/packages/vyuh-core.mdx b/src/content/docs/framework/packages/vyuh-core.mdx index 8022e70..28ea78e 100644 --- a/src/content/docs/framework/packages/vyuh-core.mdx +++ b/src/content/docs/framework/packages/vyuh-core.mdx @@ -90,10 +90,41 @@ Provides comprehensive logging and monitoring capabilities. Supports multiple te Manages dependency injection throughout the application. Provides a clean way to register and resolve dependencies. Includes a default implementation using the GetIt service locator. #### Event Plugin -Handles application-wide event management. Provides a pub/sub system for communication between different parts of the application. Includes both synchronous and asynchronous event handling. +Provides a type-safe event bus for application-wide communication. Supports both synchronous and asynchronous event handling with a pub/sub pattern. + +```dart +abstract class EventPlugin extends Plugin { + // Subscribe to events + DisposeFunction on(VyuhEventListener listener); + + // One-time event subscription + void once(VyuhEventListener listener); + + // Emit events + void emit(T event); +} +``` #### Storage Plugin -Manages persistent storage operations. Provides a unified interface for storing and retrieving data across different storage backends. +Manages data persistence with both regular and secure storage options. Provides a consistent interface for key-value storage operations. + +```dart +// Regular storage for non-sensitive data +abstract class StoragePlugin extends Plugin { + Future read(String key); + Future write(String key, dynamic value); + Future has(String key); + Future delete(String key); +} + +// Secure storage for sensitive data +abstract class SecureStoragePlugin extends Plugin { + Future read(String key); + Future write(String key, dynamic value); + Future has(String key); + Future delete(String key); +} +``` ### Plugin Providers @@ -115,6 +146,90 @@ Vyuh provides default implementations for most plugins: - `GetItDIPlugin`: Default dependency injection using GetIt - `NoOpTelemetryProvider`: No-op implementation for telemetry +## Platform Widgets + +Vyuh provides a set of customizable platform widgets for common UI patterns: + +### Error Views +Handles various error states in the application: +- Network errors +- Content loading failures +- Route not found +- General error boundaries + +### Loading States +Customizable loading indicators for: +- Initial app loading +- Content fetching +- Route transitions +- Plugin initialization + +### Framework Views +Special views for framework states: +- Platform initialization +- Plugin loading +- Feature registration +- Debug information + +### Custom Platform Widgets +You can customize the platform widgets by implementing the `PlatformWidgetBuilder`: + +```dart +final class PlatformWidgetBuilder { + PlatformWidgetBuilder({ + required this.appBuilder, + required this.appLoader, + required this.contentLoader, + required this.routeLoader, + required this.errorView, + required this.routeErrorView, + required this.imagePlaceholder, + }); + + // Root app widget builder (MaterialApp/CupertinoApp) + final AppBuilder appBuilder; + + // Loading states + final Loader appLoader; // App initialization + final Loader contentLoader; // Content loading + final RouteLoader routeLoader; // Route transitions + + // Error handling + final ErrorViewBuilder errorView; // General errors + final RouteErrorViewBuilder routeErrorView; // Route-specific errors + + // Asset handling + final ImagePlaceholderBuilder imagePlaceholder; +} + +// Builder function types +typedef AppBuilder = Widget Function(VyuhPlatform platform); +typedef Loader = Widget Function(BuildContext context); +typedef RouteLoader = Widget Function(BuildContext context, [Uri? url, String? routeId]); +typedef ImagePlaceholderBuilder = Widget Function(BuildContext context, {double? width, double? height}); + +typedef ErrorViewBuilder = Widget Function( + BuildContext context, { + required String title, + dynamic error, + StackTrace? stackTrace, + String? retryLabel, + VoidCallback? onRetry, + String? subtitle, + bool showRestart, +}); + +typedef RouteErrorViewBuilder = Widget Function( + BuildContext context, { + required String title, + String? retryLabel, + VoidCallback? onRetry, + dynamic error, + StackTrace? stackTrace, + String? subtitle, +}); +``` + ## Usage Example ```dart