-
Notifications
You must be signed in to change notification settings - Fork 3
Add updated diagram #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@nikitamounier This good to merge? |
|
Yep! Do you like the documentation style? |
|
I just have one question – does the state publisher in the middleware have any actual use? Because flatmapping and then mapping it to return a refined action or simply returning a Just with a refined action seems to have the same result. Is it for code clarity? |
|
The state publisher is to ensure that a long running network task or something like that has the most up to date copy of the state when it’s finished its call. |
|
I'm not sure I fully understand, since we don't have actual access to the state itself in the middleware. I always pictured the middleware as two parallel streams (like in a marble diagram) – one of raw actions, and one with the state in which all we can do is call refined actions. Do you think you could show me a quick example? |
|
Whoops, ignore what I said! You can access the most recent state in the map! That's super useful, excuse my oversight. Let me try adding an example of that in the documentation. |
|
So would this be correct to add to the documentation – it's a raw action for saving the app state (which if successful returns a refined action static let middleware = Middleware<State, Action.Raw, Action.Refined> { state, action -> AnyPublisher<Action.Refined, Never> in
switch action {
case .saveState:
return state.flatMap { appState in
Just(appState)
}
.encode(encoder: JSONEncoder())
.flatMap { FileManager.default.save(data: $0, to: "appState.json", in: .applicationSupportDirectory) }
.flatMap { _ in
state.map { _ in
return .none
}
}
.catch { error in
Just(.saveStateError(error))
}
.eraseToAnyPublisher()
|
|
Yeah that code is correct. You could have your AppAction.Refined type be optional so you automatically get |
|
Do you think that's better than just adding a |
|
Also I'm fully finished with the Middleware documentation – so feel free to merge with either just the updated diagram or with the Middleware documentation too :) |
No description provided.