Skip to content

Commit d95d538

Browse files
committed
updates according to V9.0 changes
1 parent eeb4ece commit d95d538

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

CLAUDE.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ flutter run
6464

6565
**CommandSync<TParam, TResult>** (`sync_command.dart`)
6666
- Wraps synchronous functions
67-
- **Does NOT support `isExecuting`** - will assert if accessed (sync functions don't give UI time to react)
67+
- **Does NOT support `isRunning`** - will assert if accessed (sync functions don't give UI time to react)
6868
- Execution happens immediately on call
6969

7070
**CommandAsync<TParam, TResult>** (`async_command.dart`)
7171
- Wraps asynchronous functions
72-
- Full support for `isExecuting` tracking
72+
- Full support for `isRunning` tracking
7373
- Updates UI progressively: before execution → during → after completion
7474

7575
**UndoableCommand<TParam, TResult, TUndoState>** (`undoable_command.dart`)
@@ -112,10 +112,10 @@ Every Command exposes multiple `ValueListenable` interfaces for different aspect
112112
- `data`: The result value
113113
- `paramData`: Parameter passed to command
114114
- `error`: Any error that occurred
115-
- `isExecuting`: Current execution state
116-
3. **`.isExecuting`** (`ValueListenable<bool>`): Async only, updated asynchronously
117-
4. **`.isExecutingSync`** (`ValueListenable<bool>`): Synchronous version for use as restrictions
118-
5. **`.canExecute`** (`ValueListenable<bool>`): Computed as `!restriction && !isExecuting`
115+
- `isRunning`: Current execution state
116+
3. **`.isRunning`** (`ValueListenable<bool>`): Async only, updated asynchronously
117+
4. **`.isRunningSync`** (`ValueListenable<bool>`): Synchronous version for use as restrictions
118+
5. **`.canRun`** (`ValueListenable<bool>`): Computed as `!restriction && !isRunning`
119119
6. **`.errors`** (`ValueListenable<CommandError<TParam>?>`): Error-specific notifications
120120

121121
### Error Handling System
@@ -154,28 +154,28 @@ Command.detailedStackTraces = true; // Capture enhanced traces
154154
Commands can be conditionally disabled via `restriction` parameter:
155155

156156
```dart
157-
final restriction = ValueNotifier<bool>(false); // false = can execute
157+
final restriction = ValueNotifier<bool>(false); // false = can run
158158
final cmd = Command.createAsync<String, List<Data>>(
159159
fetchData,
160160
[],
161161
restriction: restriction, // Command disabled when true
162-
ifRestrictedExecuteInstead: (param) {
162+
ifRestrictedRunInstead: (param) {
163163
// Optional: handle restricted execution (e.g., show login)
164164
},
165165
);
166166
```
167167

168168
**Important**: `restriction: true` means DISABLED, `false` means enabled.
169169

170-
The `.canExecute` property automatically combines restriction with execution state.
170+
The `.canRun` property automatically combines restriction with execution state.
171171

172172
### Widget Integration
173173

174174
**CommandBuilder** (`command_builder.dart`):
175175
```dart
176176
CommandBuilder<String, List<Data>>(
177177
command: myCommand,
178-
whileExecuting: (context, _) => CircularProgressIndicator(),
178+
whileRunning: (context, _) => CircularProgressIndicator(),
179179
onData: (context, data, _) => DataList(data),
180180
onError: (context, error, param) => ErrorWidget(error),
181181
onSuccess: (context, _) => SuccessWidget(), // For void result commands
@@ -185,7 +185,7 @@ CommandBuilder<String, List<Data>>(
185185
**Extension method** for use with get_it_mixin/provider/flutter_hooks:
186186
```dart
187187
result.toWidget(
188-
whileExecuting: (lastValue, _) => LoadingWidget(),
188+
whileRunning: (lastValue, _) => LoadingWidget(),
189189
onResult: (data, _) => DataWidget(data),
190190
onError: (error, lastValue, paramData) => ErrorWidget(error),
191191
)
@@ -198,19 +198,19 @@ result.toWidget(
198198
Tests use a `Collector<T>` helper class to accumulate ValueListenable emissions:
199199

200200
```dart
201-
final Collector<bool> canExecuteCollector = Collector<bool>();
201+
final Collector<bool> canRunCollector = Collector<bool>();
202202
final Collector<CommandResult> cmdResultCollector = Collector<CommandResult>();
203203
204204
void setupCollectors(Command command) {
205-
command.canExecute.listen((b, _) => canExecuteCollector(b));
205+
command.canRun.listen((b, _) => canRunCollector(b));
206206
command.results.listen((r, _) => cmdResultCollector(r));
207207
// ... etc
208208
}
209209
210210
// In test:
211211
setupCollectors(command);
212212
command.run();
213-
expect(canExecuteCollector.values, [true, false, true]);
213+
expect(canRunCollector.values, [true, false, true]);
214214
```
215215

216216
### Async Test Utilities
@@ -223,7 +223,7 @@ expect(canExecuteCollector.values, [true, false, true]);
223223

224224
```bash
225225
# Run single test by name
226-
flutter test --name "Execute simple sync action No Param No Result"
226+
flutter test --name "Run simple sync action No Param No Result"
227227

228228
# Run test group
229229
flutter test --name "Synchronous Command Testing"
@@ -267,7 +267,7 @@ textChangedCommand.debounce(Duration(milliseconds: 500)).listen((text, _) {
267267
final saveCmd = Command.createAsync<Data, void>(
268268
saveData,
269269
null,
270-
restriction: loadCmd.isExecutingSync, // Can't save while loading
270+
restriction: loadCmd.isRunningSync, // Can't save while loading
271271
);
272272
```
273273

@@ -304,8 +304,8 @@ RefreshIndicator(
304304
- `.errors` emits `null` at start of each execution to clear previous errors
305305
- Use `.where((x) => x != null)` from listen_it to filter these out
306306

307-
4. **Sync commands and isExecuting**:
308-
- Accessing `.isExecuting` on sync commands throws assertion
307+
4. **Sync commands and isRunning**:
308+
- Accessing `.isRunning` on sync commands throws assertion
309309
- Use async commands if you need execution state tracking
310310

311311
5. **Global vs Local error handlers**:

COMMAND_PATTERNS_KNOWLEDGE_BASE.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ errorFilter: ErrorTypeFilter({
621621
context.l10n.networkError,
622622
action: ToastAction(
623623
label: context.l10n.retry,
624-
onPressed: () => command.execute(lastParam),
624+
onPressed: () => command.run(lastParam),
625625
),
626626
);
627627
});
@@ -892,7 +892,7 @@ late final loadDataCommand = Command.createAsyncNoParam<Data>(_loadData, null);
892892
void initState() {
893893
super.initState();
894894
895-
loadDataCommand.isExecuting.listen((isLoading, _) {
895+
loadDataCommand.isRunning.listen((isLoading, _) {
896896
setState(() {
897897
_isLoading = isLoading;
898898
});
@@ -1022,8 +1022,8 @@ late final createOrderCommand = Command.createAsync<OrderParams, Order>(
10221022
final order = await api.createOrder(params);
10231023
10241024
// Refresh related data
1025-
getOrdersCommand.execute();
1026-
getBalanceCommand.execute();
1025+
getOrdersCommand.run();
1026+
getBalanceCommand.run();
10271027
10281028
// Show success feedback
10291029
toastService.showSuccess(context.l10n.orderCreated);
@@ -1050,15 +1050,15 @@ late final deletePaymentMethodCommand = Command.createAsyncNoResult<String>(
10501050
);
10511051
10521052
if (nextMethod != null) {
1053-
await setDefaultPaymentMethodCommand.executeWithFuture(nextMethod.id);
1053+
await setDefaultPaymentMethodCommand.runAsync(nextMethod.id);
10541054
}
10551055
}
10561056
10571057
// Now safe to delete
10581058
await api.deletePaymentMethod(paymentMethodId);
10591059
10601060
// Refresh list
1061-
getPaymentMethodsCommand.execute();
1061+
getPaymentMethodsCommand.run();
10621062
},
10631063
);
10641064
```
@@ -1071,9 +1071,9 @@ late final deletePaymentMethodCommand = Command.createAsyncNoResult<String>(
10711071
late final refreshDashboardCommand = Command.createAsyncNoParamNoResult(
10721072
() async {
10731073
await Future.wait([
1074-
getOrdersCommand.executeWithFuture(),
1075-
getNotificationsCommand.executeWithFuture(),
1076-
getBalanceCommand.executeWithFuture(),
1074+
getOrdersCommand.runAsync(),
1075+
getNotificationsCommand.runAsync(),
1076+
getBalanceCommand.runAsync(),
10771077
]);
10781078
},
10791079
);
@@ -1089,7 +1089,7 @@ late final loadDataCommand = Command.createAsyncNoParam<Data>(_loadData, null);
10891089
late final saveDataCommand = Command.createAsync<Data, void>(
10901090
_saveData,
10911091
null,
1092-
restriction: loadDataCommand.isExecutingSync, // Can't save while loading
1092+
restriction: loadDataCommand.isRunningSync, // Can't save while loading
10931093
);
10941094
```
10951095

@@ -1103,10 +1103,10 @@ late final purchaseListingCommand = Command.createAsync<PurchaseParams, Order>(
11031103
final orderDto = await api.storeOrder(params);
11041104
11051105
// Refresh listing (will show "sold" state)
1106-
params.listing.loadFullTargetCommand.execute();
1106+
params.listing.loadFullTargetCommand.run();
11071107
11081108
// Refresh user's balance
1109-
userManager.getBalanceCommand.execute();
1109+
userManager.getBalanceCommand.run();
11101110
11111111
// Return new order proxy
11121112
return createOrderProxy(orderDto);
@@ -1384,19 +1384,19 @@ errorFilter: const GlobalOnlyErrorFilter(),
13841384
// User sees generic "Something went wrong" toast
13851385
```
13861386

1387-
### 8. Use executeWithFuture for Async Coordination
1387+
### 8. Use runAsync for Async Coordination
13881388

13891389
**Pattern**: When you need to await command completion
13901390

13911391
```dart
13921392
// ✅ GOOD: Await command in async function
13931393
Future<void> onRefresh() async {
1394-
await loadDataCommand.executeWithFuture();
1394+
await loadDataCommand.runAsync();
13951395
}
13961396
13971397
// ✅ GOOD: Use with RefreshIndicator
13981398
RefreshIndicator(
1399-
onRefresh: () => loadDataCommand.executeWithFuture(),
1399+
onRefresh: () => loadDataCommand.runAsync(),
14001400
child: ListView(...),
14011401
)
14021402
```
@@ -1425,7 +1425,7 @@ late final loadDataCommand = Command.createAsync(
14251425
);
14261426
```
14271427

1428-
### 2. ❌ Using Sync Commands When You Need isExecuting
1428+
### 2. ❌ Using Sync Commands When You Need isRunning
14291429

14301430
**Problem**: Sync commands don't support execution state tracking
14311431

@@ -1434,16 +1434,16 @@ late final loadDataCommand = Command.createAsync(
14341434
late final processDataCommand = Command.createSync(_processData, null);
14351435
14361436
// This will throw assertion error:
1437-
processDataCommand.isExecuting.listen(...); // ❌ ASSERTION FAILS
1437+
processDataCommand.isRunning.listen(...); // ❌ ASSERTION FAILS
14381438
```
14391439

14401440
**Solution**: Use async commands for long-running operations
14411441

14421442
```dart
1443-
// ✅ GOOD: Async command supports isExecuting
1443+
// ✅ GOOD: Async command supports isRunning
14441444
late final processDataCommand = Command.createAsync(_processData, null);
14451445
1446-
processDataCommand.isExecuting.listen((isLoading, _) {
1446+
processDataCommand.isRunning.listen((isLoading, _) {
14471447
setState(() => _isLoading = isLoading);
14481448
});
14491449
```

0 commit comments

Comments
 (0)