Skip to content

Commit 41c9b7d

Browse files
committed
refactor(demo): add detailed comments on CountryInMemoryClient usage
- Explain the purpose of wrapping DataInMemory<Country> with CountryInMemoryClient - Detail the rationale for using this client-side decorator in the demo environment - Clarify why this approach is specific to the demo environment and not needed in API environments - Emphasize the use of the Decorator Pattern to extend functionality without altering the generic base
1 parent a0ebaea commit 41c9b7d

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

lib/bootstrap.dart

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,35 @@ Future<Widget> bootstrap(
107107
initialData: countriesFixturesData,
108108
logger: logger,
109109
);
110-
// Wrap the generic DataInMemory<Country> with CountryInMemoryClient
111-
// to add specialized filtering like 'hasActiveSources' and 'hasActiveHeadlines'.
110+
111+
// Wrap the generic DataInMemory<Country> with CountryInMemoryClient.
112+
// This decorator adds specialized filtering for 'hasActiveSources' and
113+
// 'hasActiveHeadlines' which are specific to the application's needs
114+
// in the demo environment.
115+
//
116+
// Rationale:
117+
// 1. **Demo Environment Specific:** This client-side decorator is only
118+
// applied in the `demo` environment. In this mode, data is served
119+
// from static in-memory fixtures, and this decorator enables complex
120+
// filtering on that local data.
121+
// 2. **API Environments (Development/Production):** For `development`
122+
// and `production` environments, the `countriesClient` is an instance
123+
// of `DataApi<Country>`. In these environments, the backend API
124+
// (which includes services like `CountryQueryService`) is responsible
125+
// for handling all advanced filtering and aggregation logic. Therefore,
126+
// this client-side decorator is not needed.
127+
// 3. **Preserving Genericity:** The core `DataInMemory<T>` client (from
128+
// the `data-inmemory` package) is designed to be generic and reusable
129+
// across various projects. Modifying it directly with application-specific
130+
// logic would violate the Single Responsibility Principle and reduce
131+
// its reusability. The Decorator Pattern allows us to extend its
132+
// functionality for `Country` models without altering the generic base.
112133
countriesClient = CountryInMemoryClient(
113134
decoratedClient: countriesClient,
114135
allSources: sourcesFixturesData,
115136
allHeadlines: headlinesFixturesData,
116137
);
138+
//
117139
sourcesClient = DataInMemory<Source>(
118140
toJson: (i) => i.toJson(),
119141
getId: (i) => i.id,

0 commit comments

Comments
 (0)