Documentation recreate feature - #11
Merged
Merged
Conversation
This implementation resolves the TODO that was causing infinite loops during ViewModel initialization. ## Key Features - **Factory Function Storage**: Stores the original factory function for recreation without requiring it to be passed again - **Infinite Loop Protection**: Uses `_isRecreating` guard flag to prevent recursive recreation during ViewModel initialization - **Proper Cleanup**: Properly disposes old ViewModel listeners via `stopListeningVM()` and `removeListeners()` - **Lifecycle Management**: Maintains key, related states, and reference counts - **Complete Notification**: Notifies all listeners and parent related states - **Error Handling**: Comprehensive error handling with descriptive messages ## Use Cases - After logout to create fresh user state - Reset application state to initial values - Testing scenarios requiring clean state - Recovery from corrupted or invalid state ## Changes ### lib/src/notifier/reactive_notifier.dart - Added `_createFunction` field to store factory function - Added `_isRecreating` guard flag for infinite loop prevention - Implemented complete `recreate()` method (lines 1311-1505) - Added `_disposeOldNotifier()` helper method for cleanup - Added `isRecreating` getter for debugging - Modified `replaceNotifier()` to bypass circular update checks ### test/reactive_notifier_recreate_test.dart (new) - 24 comprehensive tests covering: - Basic recreation with simple types - Recreation with ViewModels and AsyncViewModels - Infinite loop protection - Listener notification - Auto-dispose integration - Related states behavior - Edge cases and memory management ### CLAUDE.md - Added `recreate()` to key methods list - Added complete documentation section - Included usage examples and comparison with `reinitializeInstance()` All 24 tests pass successfully.
## Changes ### New Modular Documentation Structure Created directory with individual files for each API: - context.md - BuildContext? getter with fallback - has-context.md - Context availability check - require-context.md - Required context with errors - global-context.md - Direct global context access - has-global-context.md - Global context availability - require-global-context.md - Required global context - init-context.md - ReactiveNotifier.initContext() setup - wait-for-context.md - AsyncViewModel waitForContext parameter ### Builder Documentation Created : - Complete ReactiveContextBuilder documentation - InheritedWidget vs markNeedsBuild strategies - Performance considerations and examples ### Updated Files - docs/features/context-access.md - Converted to index/overview - docs/guides/context-pattern.md - Updated with modular references - docs/README.md - Updated structure with context system - docs/features/viewmodel.md - Updated context references - docs/features/async-viewmodel.md - Added context access table ## Benefits - Consistent with viewmodel/ and async-viewmodel/ modular structure - Each API method/property has dedicated documentation - Easy to find and reference specific functionality - Better organization for maintenance and updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.