BlockAsyncAction
public struct BlockAsyncAction: AsyncAction
Create an AsyncAction
inline by passing a block to the init
Check AsyncAction
for more info
SeeAlso:
Example
Performing an async network request
let action = BlockAsyncAction { getState, dispatch in
// Read the current state from the Store
getState()
// First dispatch some action syncrhonously
dispatch(SomeAction(...))
let session = URLSession(configuration: .default)
// perform a dataTask
session.dataTask(with: urlRequest) { data, response, error in
if let data = data {
// Do something with the data
dispatch(RequestSucceeded(data: data))
} else if let error = error {
// Error happenend
dispatch(RequestFaile(data: data))
}
}
}
store.dispatch(action: MyURLAsyncAction())
-
Undocumented
Declaration
Swift
public struct BlockAsyncAction: AsyncAction
-
Declaration
Swift
public func execute(getState: @escaping GetStateFunction, dispatch: @escaping DispatchFunction)