Structs
The following structs are available globally.
-
LoggerMiddleware that logs the action and state when each action is received When an action is dispatched, the LoggerMiddleware will print information related to it in the console.
Example
Adding LoggerMiddleware
let store = Suas.createStore( reducer: ..., middleware: LoggerMiddleware() )When actions are dispatched, you get something similar to this printed to the console.
See more┌───→ Action: IncrementAction @19:15:39.419 ├─ Prev state ► State(innerState: ["Counter": CounterExample.Counter(value: 0)]) ├─ Action ► IncrementAction(incrementValue: 1) ├─ Next state ► State(innerState: ["Counter": CounterExample.Counter(value: 1)]) └──────────────────────────────────────────Declaration
Swift
public struct LoggerMiddleware: Middleware
-
Create an
AsyncActioninline by passing a block to the init CheckAsyncActionfor more infoSeeAlso:
Example
Performing an async network request
See morelet 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())Declaration
Swift
public struct BlockAsyncAction: AsyncAction -
Async Middleware handles actions of type
AsyncActionAsyncActionare not dispatched to the reducer WhenAsyncMiddlewareintercepts anAsyncActionit does the following:- Call
action.executeon that action - the action
executeis executed which receives thegetStateanddispatchfunction as its parameters - the
executecalls dispatch as many times as wanted, dispatching new actions (can also disptach newAsyncAction)
SeeAlso:
See moreDeclaration
Swift
public struct AsyncMiddleware: Middleware - Call
-
Structure that represents the store state. The store state is kept as a
DictionarywithStringKeys andAnyValues ([String: Any])For example, the state with two struct looks like:
See more[ "TodoItems": TodoItems(....), "AppSettings": AppSettings(....) ]Declaration
Swift
public struct State
-
Subscription structure that represents a listener subscription. When adding a listener you get a subscription back. You can use this subscription to remove the listener, notify about the current state or link the listener lifecycle with an object.
See moreDeclaration
Swift
public struct Subscription<StateType> -
Subscription structure that represents a listener subscription. When adding a listener you get a subscription back. You can use this subscription to remove the listener, notify about the current state or link the listener lifecycle with an object.
See moreDeclaration
Swift
public struct ActionSubscription
View on GitHub
Structs Reference