pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.35k stars 1.44k forks source link

1.5.4 action from run not called #2647

Closed zhenyataranr10 closed 10 months ago

zhenyataranr10 commented 10 months ago

Description

Actually don't know why, but sometimes in Reducer actions that sends from run not receives in reducer

` @Reducer struct ChatReducer: Reducer {

struct State: Equatable {
    var chatMessages: IdentifiedArrayOf<MessageReducer.State> = []
    @BindingState var chatText: String
}

enum Action: BindableAction{
    case binding(BindingAction<State>)
    case messageResult(Result<[MessagesModel], Error>)
    case viewAppear
    case message(id: MessageReducer.State.ID, action: MessageReducer.Action)
}

@Dependency(\.dismiss) var dismiss
@Dependency(\.uuid) var uuid
@Dependency(\.fireStoreChatService) var fireStoreService

var body: some Reducer<State, Action> {
    Reduce { state, action in
        switch action {
        case .viewAppear:
            return .run { send in
                await send(
                    .messageResult(
                        Result {
                            try await fireStoreService.getMessage()
                        }
                    )
                )
            }
        case .messageResult(.success(let model)):
            print("FETCHESUCCESS")
            return .none
        case .messageResult(.failure(let error)):
            debugPrint("Something went wrong error: ", error)
            return .none
        }
    }
}

}`

in this case not receiving any action of messageResult

Checklist

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

The Composable Architecture version information

1.5.4

Destination operating system

17.0

Xcode version information

15.0.1

Swift Compiler version information

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
KirillZholnerovich commented 10 months ago

Same issue. On 1.5.1 everything is fine

stephencelis commented 10 months ago

Fixed by #2648.

mbrandonw commented 10 months ago

Hi @zhenyataranr10, this was fixed in 1.5.5. Can you update and confirm?

zhenyataranr10 commented 10 months ago

Hi @zhenyataranr10, this was fixed in 1.5.5. Can you update and confirm?

@mbrandonw Yeah fix works. Thanks!

Cu-Toof commented 7 months ago
@Reducer
struct Splash {
    // MARK: - Define States/Actions
    @ObservableState
    struct State: Equatable {
        var isLoading = false
    }

    enum Action: Equatable {
        case load
        case loaded

        case delegate(Delegate)
        enum Delegate: Equatable {
            case mainNavigation
        }
    }

    // MARK: - Define Dependencies

    var body: some Reducer<State, Action> {
        Reduce { state, action in
            switch action {
            case .load:
                state.isLoading = true
                return .run { send in
                    try? await configure()
                    try? await prepareData()
                    await send(.loaded)
                }
            case .loaded:
                state.isLoading = false
                return .send(.delegate(.mainNavigation))
            case .delegate:
                return .none
            }
        }
    }
}

I'm using ver 1.9.2. But this issue still happens. After send(.loaded) inside run, loaded-action not work

mbrandonw commented 7 months ago

Hi @Cu-Toof, can you please provide a minimal, compiling project that demonstrates the behavior you are seeing? Also please start a new discussion instead of responding to this old issue.

Cu-Toof commented 6 months ago

@mbrandonw Sorry, I made a mistake in preparing the data prepareData().