|
233 | 233 |
|
234 | 234 | }
|
235 | 235 |
|
236 |
| - static var body: some ComposableArchitecture.Reducer<Self.State, Self.Action> { |
237 |
| - ComposableArchitecture.CombineReducers { |
| 236 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 237 | + static var body: EmptyReducer<Self.State, Self.Action> { |
238 | 238 |
|
239 |
| - } |
240 | 239 | }
|
241 | 240 |
|
242 | 241 | enum CaseScope {
|
|
260 | 259 | """
|
261 | 260 | @Reducer
|
262 | 261 | enum Destination {
|
| 262 | + case activity(Activity) |
263 | 263 | case timeline(Timeline)
|
264 | 264 | case tweet(Tweet)
|
265 | 265 | case alert(AlertState<Alert>)
|
|
272 | 272 | } expansion: {
|
273 | 273 | #"""
|
274 | 274 | enum Destination {
|
| 275 | + case activity(Activity) |
275 | 276 | case timeline(Timeline)
|
276 | 277 | case tweet(Tweet)
|
277 | 278 | @ReducerCaseEphemeral
|
|
286 | 287 | @ObservableState
|
287 | 288 | enum State: ComposableArchitecture.CaseReducerState {
|
288 | 289 | typealias StateReducer = Destination
|
| 290 | + case activity(Activity.State) |
289 | 291 | case timeline(Timeline.State)
|
290 | 292 | case tweet(Tweet.State)
|
291 | 293 | case alert(AlertState<Alert>)
|
292 | 294 | }
|
293 | 295 |
|
294 | 296 | @CasePathable
|
295 | 297 | enum Action {
|
| 298 | + case activity(Activity.Action) |
296 | 299 | case timeline(Timeline.Action)
|
297 | 300 | case tweet(Tweet.Action)
|
298 | 301 | case alert(AlertState<Alert>.Action)
|
299 | 302 | }
|
300 | 303 |
|
301 |
| - static var body: some ComposableArchitecture.Reducer<Self.State, Self.Action> { |
302 |
| - ComposableArchitecture.CombineReducers { |
303 |
| - ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
304 |
| - Timeline() |
305 |
| - } |
306 |
| - ComposableArchitecture.Scope(state: \Self.State.Cases.tweet, action: \Self.Action.Cases.tweet) { |
307 |
| - Tweet() |
308 |
| - } |
| 304 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 305 | + static var body: ReducerBuilder<Self.State, Self.Action>._Sequence<ReducerBuilder<Self.State, Self.Action>._Sequence<Scope<Self.State, Self.Action, Activity>, Scope<Self.State, Self.Action, Timeline>>, Scope<Self.State, Self.Action, Tweet>> { |
| 306 | + ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) { |
| 307 | + Activity() |
| 308 | + } |
| 309 | + ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
| 310 | + Timeline() |
| 311 | + } |
| 312 | + ComposableArchitecture.Scope(state: \Self.State.Cases.tweet, action: \Self.Action.Cases.tweet) { |
| 313 | + Tweet() |
309 | 314 | }
|
310 | 315 | }
|
311 | 316 |
|
312 | 317 | enum CaseScope {
|
| 318 | + case activity(ComposableArchitecture.StoreOf<Activity>) |
313 | 319 | case timeline(ComposableArchitecture.StoreOf<Timeline>)
|
314 | 320 | case tweet(ComposableArchitecture.StoreOf<Tweet>)
|
315 | 321 | case alert(AlertState<Alert>)
|
316 | 322 | }
|
317 | 323 |
|
318 | 324 | static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
|
319 | 325 | switch store.state {
|
| 326 | + case .activity: |
| 327 | + return .activity(store.scope(state: \.activity, action: \.activity)!) |
320 | 328 | case .timeline:
|
321 | 329 | return .timeline(store.scope(state: \.timeline, action: \.timeline)!)
|
322 | 330 | case .tweet:
|
|
333 | 341 | }
|
334 | 342 | }
|
335 | 343 |
|
| 344 | + func testEnum_TwoCases() { |
| 345 | + assertMacro { |
| 346 | + """ |
| 347 | + @Reducer |
| 348 | + enum Destination { |
| 349 | + case activity(Activity) |
| 350 | + case timeline(Timeline) |
| 351 | + } |
| 352 | + """ |
| 353 | + } expansion: { |
| 354 | + #""" |
| 355 | + enum Destination { |
| 356 | + case activity(Activity) |
| 357 | + case timeline(Timeline) |
| 358 | +
|
| 359 | + @CasePathable |
| 360 | + @dynamicMemberLookup |
| 361 | + @ObservableState |
| 362 | + enum State: ComposableArchitecture.CaseReducerState { |
| 363 | + typealias StateReducer = Destination |
| 364 | + case activity(Activity.State) |
| 365 | + case timeline(Timeline.State) |
| 366 | + } |
| 367 | +
|
| 368 | + @CasePathable |
| 369 | + enum Action { |
| 370 | + case activity(Activity.Action) |
| 371 | + case timeline(Timeline.Action) |
| 372 | + } |
| 373 | +
|
| 374 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 375 | + static var body: ReducerBuilder<Self.State, Self.Action>._Sequence<Scope<Self.State, Self.Action, Activity>, Scope<Self.State, Self.Action, Timeline>> { |
| 376 | + ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) { |
| 377 | + Activity() |
| 378 | + } |
| 379 | + ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
| 380 | + Timeline() |
| 381 | + } |
| 382 | + } |
| 383 | +
|
| 384 | + enum CaseScope { |
| 385 | + case activity(ComposableArchitecture.StoreOf<Activity>) |
| 386 | + case timeline(ComposableArchitecture.StoreOf<Timeline>) |
| 387 | + } |
| 388 | +
|
| 389 | + static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope { |
| 390 | + switch store.state { |
| 391 | + case .activity: |
| 392 | + return .activity(store.scope(state: \.activity, action: \.activity)!) |
| 393 | + case .timeline: |
| 394 | + return .timeline(store.scope(state: \.timeline, action: \.timeline)!) |
| 395 | + } |
| 396 | + } |
| 397 | + } |
| 398 | +
|
| 399 | + extension Destination: ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer { |
| 400 | + } |
| 401 | + """# |
| 402 | + } |
| 403 | + } |
| 404 | + |
336 | 405 | func testEnum_CaseIgnored() {
|
337 | 406 | assertMacro {
|
338 | 407 | """
|
|
364 | 433 | case timeline(Timeline.Action)
|
365 | 434 | }
|
366 | 435 |
|
367 |
| - static var body: some ComposableArchitecture.Reducer<Self.State, Self.Action> { |
368 |
| - ComposableArchitecture.CombineReducers { |
369 |
| - ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
370 |
| - Timeline() |
371 |
| - } |
| 436 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 437 | + static var body: Scope<Self.State, Self.Action, Timeline> { |
| 438 | + ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
| 439 | + Timeline() |
372 | 440 | }
|
373 | 441 | }
|
374 | 442 |
|
|
429 | 497 | case dialog(ConfirmationDialogState<Dialog>.Action)
|
430 | 498 | }
|
431 | 499 |
|
432 |
| - static var body: some ComposableArchitecture.Reducer<Self.State, Self.Action> { |
433 |
| - ComposableArchitecture.CombineReducers { |
| 500 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 501 | + static var body: EmptyReducer<Self.State, Self.Action> { |
434 | 502 |
|
435 |
| - } |
436 | 503 | }
|
437 | 504 |
|
438 | 505 | enum CaseScope {
|
|
493 | 560 | case sheet(Counter.Action)
|
494 | 561 | }
|
495 | 562 |
|
496 |
| - static var body: some ComposableArchitecture.Reducer<Self.State, Self.Action> { |
497 |
| - ComposableArchitecture.CombineReducers { |
498 |
| - ComposableArchitecture.Scope(state: \Self.State.Cases.drillDown, action: \Self.Action.Cases.drillDown) { |
499 |
| - Counter() |
500 |
| - } |
501 |
| - ComposableArchitecture.Scope(state: \Self.State.Cases.popover, action: \Self.Action.Cases.popover) { |
502 |
| - Counter() |
503 |
| - } |
504 |
| - ComposableArchitecture.Scope(state: \Self.State.Cases.sheet, action: \Self.Action.Cases.sheet) { |
505 |
| - Counter() |
506 |
| - } |
| 563 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 564 | + static var body: ReducerBuilder<Self.State, Self.Action>._Sequence<ReducerBuilder<Self.State, Self.Action>._Sequence<Scope<Self.State, Self.Action, Counter>, Scope<Self.State, Self.Action, Counter>>, Scope<Self.State, Self.Action, Counter>> { |
| 565 | + ComposableArchitecture.Scope(state: \Self.State.Cases.drillDown, action: \Self.Action.Cases.drillDown) { |
| 566 | + Counter() |
| 567 | + } |
| 568 | + ComposableArchitecture.Scope(state: \Self.State.Cases.popover, action: \Self.Action.Cases.popover) { |
| 569 | + Counter() |
| 570 | + } |
| 571 | + ComposableArchitecture.Scope(state: \Self.State.Cases.sheet, action: \Self.Action.Cases.sheet) { |
| 572 | + Counter() |
507 | 573 | }
|
508 | 574 | }
|
509 | 575 |
|
|
557 | 623 | case feature(Nested.Feature.Action)
|
558 | 624 | }
|
559 | 625 |
|
560 |
| - static var body: some ComposableArchitecture.Reducer<Self.State, Self.Action> { |
561 |
| - ComposableArchitecture.CombineReducers { |
562 |
| - ComposableArchitecture.Scope(state: \Self.State.Cases.feature, action: \Self.Action.Cases.feature) { |
563 |
| - Nested.Feature() |
564 |
| - } |
| 626 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 627 | + static var body: Scope<Self.State, Self.Action, Nested.Feature> { |
| 628 | + ComposableArchitecture.Scope(state: \Self.State.Cases.feature, action: \Self.Action.Cases.feature) { |
| 629 | + Nested.Feature() |
565 | 630 | }
|
566 | 631 | }
|
567 | 632 |
|
|
0 commit comments