SwiftFlux icon indicating copy to clipboard operation
SwiftFlux copied to clipboard

[Proposal]Error handling by ErrorAction instead of antitypical/Result

Open yonekawa opened this issue 9 years ago • 1 comments

Many Action is always success. I think antitypical/Result is overkill for represent Action's error.

before

struct SampleAction: Action {
    func invoke(dispatcher: DIspatcher) {
        someFunc() { (result, error) in
            if error {
                dispatcher.dispatch(self, Result(error: error))
            } else {
                dispatcher.dispatch(self, Result(value: result))                
            }
        }
    }
}

My plan is

struct SampleAction: Action {
    func invoke(dispatcher: DIspatcher) {
        someFunc() { (result, error) in
            if error {
                ActionCreator.invoke(SomeErrorAction(error: error))
            } else {
                dispatcher.dispatch(self, result)                
            }
        }
    }
}

yonekawa avatar Dec 20 '15 16:12 yonekawa

I think this will make the SampleAction ambiguous about what Action it will dispatch in the end. And thats why we suggesting separate the role of definition of a Action and the creation of a Action into separate classes in #15.

mortyccp avatar Dec 24 '15 04:12 mortyccp