Skip to content

Commit d6029b3

Browse files
authored
docs: document recommended state/controller registration pattern for consumer apps (#18)
* docs: document recommended state/controller registration pattern for consumer apps Add architecture reference (doc/architecture/controllers.md) covering the lazy singleton pattern, MagicController + MagicStateMixin usage, controller lifecycle, view binding, and a decision tree for eager vs lazy vs per-view registration. Add practical getting-started guide (doc/guides/state-management.md) with end-to-end examples. Update scaffolded app_service_provider.stub with state registration guidance comments. Add cross-references in service-provider.md. Closes #17 * fix: address PR #18 review comments - controllers.md: clarify MagicStateMixin<bool> is most common, not universal (Newsletter/OTP use untyped); qualify NavigatesRoutes usage; note NotificationsListView as MagicStatefulView exception; fix views-and-layouts Related URL (architecture → basics) - state-management.md: fix "five-state" → "four-state"; fix _isSubmitting → _isLoading consistency; fix flutter/widgets.dart → flutter/material.dart for Icons.* usage; rename Pattern B section to "Manual Access" matching actual content - README.md: use hosted doc URLs instead of repo-relative paths - stub: replace local doc path with generic package docs reference
1 parent 8a7fc79 commit d6029b3

6 files changed

Lines changed: 1361 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
- Documentation for recommended state/controller registration pattern for consumer apps (`doc/architecture/controllers.md`, `doc/guides/state-management.md`)
9+
- State registration guidance in scaffolded `app_service_provider.stub`
10+
711
## [0.0.1-alpha.8] - 2026-03-31
812

913
### 🐛 Bug Fixes

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ App launch → MagicStarterServiceProvider.boot()
379379
| [Manager](https://magic.fluttersdk.com/packages/starter/architecture/manager) | Singleton manager and customization hooks |
380380
| [Service Provider](https://magic.fluttersdk.com/packages/starter/architecture/service-provider) | Bootstrap lifecycle, Gate abilities, IoC bindings |
381381
| [View Registry](https://magic.fluttersdk.com/packages/starter/architecture/view-registry) | String-keyed builders and host app overrides |
382+
| [Controllers & State Registration](https://magic.fluttersdk.com/packages/starter/architecture/controllers) | Recommended state/controller registration pattern for consumer apps |
383+
| [State Management Guide](https://magic.fluttersdk.com/packages/starter/guides/state-management) | State management best practices and patterns |
382384

383385
---
384386

assets/stubs/install/app_service_provider.stub

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,25 @@ class AppServiceProvider extends ServiceProvider {
7373
{{ teams_block }}
7474
{{ social_login_block }}
7575
{{ notifications_block }}
76+
77+
// -------------------------------------------------------------------
78+
// State Registration (optional — for eager initialization)
79+
// -------------------------------------------------------------------
80+
// Most state classes should use the lazy singleton pattern with a
81+
// static accessor instead of registering here:
82+
//
83+
// class ProjectState extends MagicController
84+
// with MagicStateMixin<List<Project>> {
85+
// static ProjectState get instance =>
86+
// Magic.findOrPut(ProjectState.new);
87+
// }
88+
//
89+
// Only register here if the state needs to be ready before any view
90+
// renders (e.g., WebSocket connection, auth-dependent init):
91+
//
92+
// Magic.findOrPut(DashboardState.new);
93+
//
94+
// See the Magic Starter package documentation/repository for the
95+
// controller architecture guide.
7696
}
7797
}

0 commit comments

Comments
 (0)