Skip to content

Commit 2153b23

Browse files
author
levitckii-daniil
committed
fix(EWM-511): rename dataFabric -> createData
1 parent 2a71bee commit 2153b23

File tree

18 files changed

+40
-28
lines changed

18 files changed

+40
-28
lines changed

docs/type_safe_navigation.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ abstract class CompassRoute<T extends CompassRouteDataQuery>
8787
```
8888

8989
Key features:
90+
9091
- Handles query parameter serialization and deserialization
9192
- Provides type-safe access to route parameters
9293
- Preserves parameters during navigation
@@ -103,6 +104,7 @@ abstract class CompassRouteParameterless<T extends CompassRouteData>
103104
```
104105

105106
Key features:
107+
106108
- Simplified implementation for routes without parameters
107109
- Uses a factory method pattern with `dataFabric()` to create route data
108110
- Type-safe routing without the overhead of parameter handling
@@ -119,6 +121,7 @@ abstract class CompassShellRoute
119121
```
120122

121123
Key features:
124+
122125
- Creates a StatefulShellRoute for complex UI patterns like tab navigation
123126
- Each child route becomes a separate branch in the shell
124127
- Maintains independent navigation state for each branch
@@ -148,6 +151,7 @@ The Compass router automatically discovers routes and guards through dependency
148151
4. The router then builds its routing table and middleware chain using these discovered components
149152

150153
Specifically, in `CompassRouter`:
154+
151155
- Routes are discovered via `GetIt.I.getAll<CompassBaseRoute>()`
152156
- Guards are discovered via `GetIt.I.getAll<CompassGuard>()`
153157
- Guards are sorted by priority for execution order (higher priority guards execute first)
@@ -161,6 +165,7 @@ This automatic discovery eliminates the need for manual route registration and e
161165
Routes and guards must be registered using a specific pattern for the DI container to discover them:
162166

163167
**For Routes:**
168+
164169
```dart
165170
@named
166171
@Singleton(as: CompassBaseRoute)
@@ -170,6 +175,7 @@ class MyRoute extends CompassRouteParameterless<MyRouteData> {
170175
```
171176

172177
**For Guards:**
178+
173179
```dart
174180
@named
175181
@Singleton(as: CompassGuard)
@@ -179,6 +185,7 @@ class MyGuard extends CompassGuard {
179185
```
180186

181187
This pattern ensures that:
188+
182189
1. The concrete implementation is registered with a unique name (`@named`)
183190
2. The implementation is registered as its base interface type (`CompassBaseRoute` or `CompassGuard`)
184191
3. The DI container can find all implementations of the base types
@@ -227,6 +234,7 @@ For parameterized routes:
227234
class ProfileRoute extends CompassRoute<ProfileRouteData> {
228235
ProfileRoute() : super(
229236
name: 'profile',
237+
path: '/profile',
230238
isTopLevel: true,
231239
builder: (context, data, state) => ProfilePage(userId: data.userId),
232240
);
@@ -249,13 +257,14 @@ For parameterless routes:
249257
class HomeRoute extends CompassRouteParameterless<HomeRouteData> {
250258
HomeRoute() : super(
251259
name: 'home',
260+
path: '/home',
252261
isTopLevel: true,
253262
isInitial: true,
254263
builder: (context, data, state) => HomePage(),
255264
);
256265
257266
@override
258-
HomeRouteData dataFabric() {
267+
HomeRouteData createData() {
259268
return HomeRouteData();
260269
}
261270
}
@@ -338,6 +347,7 @@ context.compassContinue(ProfileRouteData(userId: '123'));
338347
```
339348

340349
Technical implementation:
350+
341351
1. The current path is preserved using the '.' path segment
342352
2. The new path segments are appended to the relative path
343353
3. Query parameters from both the original and new location are merged
@@ -401,6 +411,7 @@ class AuthGuard extends CompassGuard {
401411
```
402412

403413
Guards are executed in priority order (highest to lowest) when navigation occurs. The predefined priority constants are:
414+
404415
- `priorityHigh = 3` - For critical guards like authentication
405416
- `priorityMedium = 2` - For feature flag guards and similar
406417
- `priorityLow = 1` - For analytics and other non-blocking guards
@@ -535,6 +546,7 @@ While Freezed is a powerful tool for creating immutable data classes in Flutter,
535546
- This mismatch causes the router to fail to find the correct route handler
536547

537548
3. **Example of the Problem**:
549+
538550
```dart
539551
// This is what the router expects
540552
final type = ProfileRouteData;
@@ -599,11 +611,11 @@ While Freezed is a powerful tool for creating immutable data classes in Flutter,
599611
- Use route verification when redirecting in guards
600612

601613
10. **Router organization and discovery**
602-
- The router automatically discovers all routes and guards registered as their base types
603-
- Routes must be registered with `@named` and `@Singleton(as: CompassBaseRoute)`
604-
- Guards must be registered with `@named` and `@Singleton(as: CompassGuard)`
605-
- Only routes with `isTopLevel = true` are registered directly with GoRouter
606-
- Only one route should have `isInitial = true` to define the app's entry point
607-
- Guards are executed in priority order (highest to lowest)
608-
- Routes are identified by both type and path for efficient lookup
609614

615+
- The router automatically discovers all routes and guards registered as their base types
616+
- Routes must be registered with `@named` and `@Singleton(as: CompassBaseRoute)`
617+
- Guards must be registered with `@named` and `@Singleton(as: CompassGuard)`
618+
- Only routes with `isTopLevel = true` are registered directly with GoRouter
619+
- Only one route should have `isInitial = true` to define the app's entry point
620+
- Guards are executed in priority order (highest to lowest)
621+
- Routes are identified by both type and path for efficient lookup

lib/app/router/compass/data_from_query.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ mixin CompassRouteDataQueryMixin<T extends CompassRouteDataQuery>
7777
mixin EmptyRouteDataMixin<T extends CompassRouteData> on CompassBaseGoRoute<T> {
7878
@override
7979
T dataFromState(GoRouterState state) {
80-
return dataFabric();
80+
return createData();
8181
}
8282

8383
/// Factory method that creates a new instance of the route data.
8484
///
8585
/// Since this mixin is for parameterless routes, this method should
8686
/// return a default instance of the route data class.
87-
T dataFabric();
87+
T createData();
8888

8989
@override
9090
Uri toLocation(T data) {

lib/app/router/compass/go_route.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ abstract class CompassBaseGoRoute<T extends CompassRouteData>
8989
///
9090
/// This is used when building the route's widget to provide it with
9191
/// the correct data from the current navigation state.
92-
T dataFromState(GoRouterState state);
92+
T routeDataConstructor(GoRouterState state);
9393

9494
@override
9595
late final GoRoute route = GoRoute(
9696
path: path,
9797
name: name,
9898
builder: builder != null
99-
? (context, state) => builder!(context, dataFromState(state), state)
99+
? (context, state) => builder!(context, routeDataConstructor(state), state)
100100
: null,
101101
pageBuilder: pageBuilder != null
102-
? (context, state) => pageBuilder!(context, dataFromState(state), state)
102+
? (context, state) => pageBuilder!(context, routeDataConstructor(state), state)
103103
: null,
104104
redirect: redirect,
105105
routes: routes,

lib/feature/add_seed/add_existing_wallet/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AddExistingWalletRoute
1717
);
1818

1919
@override
20-
AddExistingWalletRouteData dataFabric() {
20+
AddExistingWalletRouteData createData() {
2121
return const AddExistingWalletRouteData();
2222
}
2323
}

lib/feature/add_seed/import_wallet/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ImportWalletRoute
2323
);
2424

2525
@override
26-
ImportWalletRouteData dataFabric() {
26+
ImportWalletRouteData createData() {
2727
return const ImportWalletRouteData();
2828
}
2929
}

lib/feature/biometry/view/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EnableBiometryRoute
1313
);
1414

1515
@override
16-
EnableBiometryRouteData dataFabric() {
16+
EnableBiometryRouteData createData() {
1717
return const EnableBiometryRouteData();
1818
}
1919
}

lib/feature/browser_v2/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BrowserRoute extends CompassRouteParameterless<BrowserRouteData> {
1414
);
1515

1616
@override
17-
BrowserRouteData dataFabric() {
17+
BrowserRouteData createData() {
1818
return const BrowserRouteData();
1919
}
2020
}

lib/feature/network/configure_networks/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ConfigureNetworksRoute
1717
);
1818

1919
@override
20-
ConfigureNetworksRouteData dataFabric() {
20+
ConfigureNetworksRouteData createData() {
2121
return const ConfigureNetworksRouteData();
2222
}
2323
}

lib/feature/no_internet/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class NoInternetRoute extends CompassRouteParameterless<NoInternetRouteData> {
1414
);
1515

1616
@override
17-
NoInternetRouteData dataFabric() {
17+
NoInternetRouteData createData() {
1818
return const NoInternetRouteData();
1919
}
2020
}

lib/feature/onboarding/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class OnBoardingRoute extends CompassRouteParameterless<OnBoardingRouteData> {
2323
);
2424

2525
@override
26-
OnBoardingRouteData dataFabric() {
26+
OnBoardingRouteData createData() {
2727
return const OnBoardingRouteData();
2828
}
2929
}

lib/feature/profile/manage_seeds_accounts/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ManageSeedsAccountsRoute
2424
);
2525

2626
@override
27-
ManageSeedsAccountsRouteData dataFabric() {
27+
ManageSeedsAccountsRouteData createData() {
2828
return const ManageSeedsAccountsRouteData();
2929
}
3030
}

lib/feature/profile/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ProfileRoute extends CompassRouteParameterless<ProfileRouteData> {
2121
);
2222

2323
@override
24-
ProfileRouteData dataFabric() {
24+
ProfileRouteData createData() {
2525
return const ProfileRouteData();
2626
}
2727
}

lib/feature/splash/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SplashScreenRoute
1616
);
1717

1818
@override
19-
SplashScreenRouteData dataFabric() {
19+
SplashScreenRouteData createData() {
2020
return const SplashScreenRouteData();
2121
}
2222
}

lib/feature/update_version/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UpdateVersionRoute
2222
);
2323

2424
@override
25-
UpdateVersionRouteData dataFabric() {
25+
UpdateVersionRouteData createData() {
2626
return const UpdateVersionRouteData();
2727
}
2828
}

lib/feature/wallet/new_account/add_external_account/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class NewExternalAccountRoute
1313
);
1414

1515
@override
16-
NewExternalAccountRouteData dataFabric() {
16+
NewExternalAccountRouteData createData() {
1717
return const NewExternalAccountRouteData();
1818
}
1919
}

lib/feature/wallet/new_account/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AddAccountRoute extends CompassRouteParameterless<AddAccountRouteData> {
2424
);
2525

2626
@override
27-
AddAccountRouteData dataFabric() {
27+
AddAccountRouteData createData() {
2828
return const AddAccountRouteData();
2929
}
3030
}

lib/feature/wallet/new_account/select_seed/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SelectSeedRoute extends CompassRouteParameterless<SelectSeedRouteData> {
1717
);
1818

1919
@override
20-
SelectSeedRouteData dataFabric() {
20+
SelectSeedRouteData createData() {
2121
return const SelectSeedRouteData();
2222
}
2323
}

lib/feature/wallet/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class WalletRoute extends CompassRouteParameterless<WalletRouteData> {
6060
);
6161

6262
@override
63-
WalletRouteData dataFabric() {
63+
WalletRouteData createData() {
6464
return const WalletRouteData();
6565
}
6666
}

0 commit comments

Comments
 (0)