|
236 | 236 | @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
237 | 237 | static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> { |
238 | 238 |
|
| 239 | + ComposableArchitecture.EmptyReducer<Self.State, Self.Action>() |
| 240 | +
|
239 | 241 | } |
240 | 242 |
|
241 | 243 | enum CaseScope { |
|
303 | 305 |
|
304 | 306 | @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
305 | 307 | static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.Scope<Self.State, Self.Action, Timeline>>, ComposableArchitecture.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() |
314 | | - } |
| 308 | +
|
| 309 | + ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) { |
| 310 | + Activity() |
| 311 | + } |
| 312 | + ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
| 313 | + Timeline() |
| 314 | + } |
| 315 | + ComposableArchitecture.Scope(state: \Self.State.Cases.tweet, action: \Self.Action.Cases.tweet) { |
| 316 | + Tweet() |
| 317 | + } |
| 318 | +
|
315 | 319 | } |
316 | 320 |
|
317 | 321 | enum CaseScope { |
|
341 | 345 | } |
342 | 346 | } |
343 | 347 |
|
| 348 | + func testEnum_Empty() { |
| 349 | + assertMacro { |
| 350 | + """ |
| 351 | + @Reducer |
| 352 | + enum Destination { |
| 353 | + } |
| 354 | + """ |
| 355 | + } expansion: { |
| 356 | + """ |
| 357 | + enum Destination { |
| 358 | +
|
| 359 | + @CasePathable |
| 360 | + @dynamicMemberLookup |
| 361 | + @ObservableState |
| 362 | + enum State: ComposableArchitecture.CaseReducerState { |
| 363 | + typealias StateReducer = Destination |
| 364 | +
|
| 365 | + } |
| 366 | +
|
| 367 | + @CasePathable |
| 368 | + enum Action { |
| 369 | +
|
| 370 | + } |
| 371 | +
|
| 372 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 373 | + static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> { |
| 374 | +
|
| 375 | + ComposableArchitecture.EmptyReducer<Self.State, Self.Action>() |
| 376 | +
|
| 377 | + } |
| 378 | +
|
| 379 | + enum CaseScope { |
| 380 | +
|
| 381 | + } |
| 382 | +
|
| 383 | + static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope { |
| 384 | + switch store.state { |
| 385 | +
|
| 386 | + } |
| 387 | + } |
| 388 | + } |
| 389 | +
|
| 390 | + extension Destination: ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer { |
| 391 | + } |
| 392 | + """ |
| 393 | + } |
| 394 | + } |
| 395 | + |
| 396 | + func testEnum_OneAlertCase() { |
| 397 | + assertMacro { |
| 398 | + """ |
| 399 | + @Reducer |
| 400 | + enum Destination { |
| 401 | + case alert(AlertState<Never>) |
| 402 | + } |
| 403 | + """ |
| 404 | + } expansion: { |
| 405 | + """ |
| 406 | + enum Destination { |
| 407 | + @ReducerCaseEphemeral |
| 408 | + case alert(AlertState<Never>) |
| 409 | +
|
| 410 | + @CasePathable |
| 411 | + @dynamicMemberLookup |
| 412 | + @ObservableState |
| 413 | + enum State: ComposableArchitecture.CaseReducerState { |
| 414 | + typealias StateReducer = Destination |
| 415 | + case alert(AlertState<Never>) |
| 416 | + } |
| 417 | +
|
| 418 | + @CasePathable |
| 419 | + enum Action { |
| 420 | + case alert(AlertState<Never>.Action) |
| 421 | + } |
| 422 | +
|
| 423 | + @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
| 424 | + static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> { |
| 425 | +
|
| 426 | + ComposableArchitecture.EmptyReducer<Self.State, Self.Action>() |
| 427 | +
|
| 428 | + } |
| 429 | +
|
| 430 | + enum CaseScope { |
| 431 | + case alert(AlertState<Never>) |
| 432 | + } |
| 433 | +
|
| 434 | + static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope { |
| 435 | + switch store.state { |
| 436 | + case let .alert(v0): |
| 437 | + return .alert(v0) |
| 438 | + } |
| 439 | + } |
| 440 | + } |
| 441 | +
|
| 442 | + extension Destination: ComposableArchitecture.CaseReducer, ComposableArchitecture.Reducer { |
| 443 | + } |
| 444 | + """ |
| 445 | + } |
| 446 | + } |
| 447 | + |
344 | 448 | func testEnum_TwoCases() { |
345 | 449 | assertMacro { |
346 | 450 | """ |
|
373 | 477 |
|
374 | 478 | @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
375 | 479 | static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Activity>, ComposableArchitecture.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 | | - } |
| 480 | +
|
| 481 | + ComposableArchitecture.Scope(state: \Self.State.Cases.activity, action: \Self.Action.Cases.activity) { |
| 482 | + Activity() |
| 483 | + } |
| 484 | + ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
| 485 | + Timeline() |
| 486 | + } |
| 487 | +
|
382 | 488 | } |
383 | 489 |
|
384 | 490 | enum CaseScope { |
|
435 | 541 |
|
436 | 542 | @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
437 | 543 | static var body: ComposableArchitecture.Scope<Self.State, Self.Action, Timeline> { |
438 | | - ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
439 | | - Timeline() |
440 | | - } |
| 544 | +
|
| 545 | + ComposableArchitecture.Scope(state: \Self.State.Cases.timeline, action: \Self.Action.Cases.timeline) { |
| 546 | + Timeline() |
| 547 | + } |
| 548 | +
|
441 | 549 | } |
442 | 550 |
|
443 | 551 | enum CaseScope { |
|
500 | 608 | @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
501 | 609 | static var body: ComposableArchitecture.EmptyReducer<Self.State, Self.Action> { |
502 | 610 |
|
| 611 | + ComposableArchitecture.EmptyReducer<Self.State, Self.Action>() |
| 612 | +
|
503 | 613 | } |
504 | 614 |
|
505 | 615 | enum CaseScope { |
|
562 | 672 |
|
563 | 673 | @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
564 | 674 | static var body: ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.ReducerBuilder<Self.State, Self.Action>._Sequence<ComposableArchitecture.Scope<Self.State, Self.Action, Counter>, ComposableArchitecture.Scope<Self.State, Self.Action, Counter>>, ComposableArchitecture.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() |
573 | | - } |
| 675 | +
|
| 676 | + ComposableArchitecture.Scope(state: \Self.State.Cases.drillDown, action: \Self.Action.Cases.drillDown) { |
| 677 | + Counter() |
| 678 | + } |
| 679 | + ComposableArchitecture.Scope(state: \Self.State.Cases.popover, action: \Self.Action.Cases.popover) { |
| 680 | + Counter() |
| 681 | + } |
| 682 | + ComposableArchitecture.Scope(state: \Self.State.Cases.sheet, action: \Self.Action.Cases.sheet) { |
| 683 | + Counter() |
| 684 | + } |
| 685 | +
|
574 | 686 | } |
575 | 687 |
|
576 | 688 | enum CaseScope { |
|
625 | 737 |
|
626 | 738 | @ComposableArchitecture.ReducerBuilder<Self.State, Self.Action> |
627 | 739 | static var body: ComposableArchitecture.Scope<Self.State, Self.Action, Nested.Feature> { |
628 | | - ComposableArchitecture.Scope(state: \Self.State.Cases.feature, action: \Self.Action.Cases.feature) { |
629 | | - Nested.Feature() |
630 | | - } |
| 740 | +
|
| 741 | + ComposableArchitecture.Scope(state: \Self.State.Cases.feature, action: \Self.Action.Cases.feature) { |
| 742 | + Nested.Feature() |
| 743 | + } |
| 744 | +
|
631 | 745 | } |
632 | 746 |
|
633 | 747 | enum CaseScope { |
|
0 commit comments