Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Returned send method to call only effects async
Browse files Browse the repository at this point in the history
  • Loading branch information
sladan-hedvig committed Mar 25, 2024
1 parent 7fd6f84 commit e01d2e0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Presentation/PresentableStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,26 @@ open class StateStore<State: StateProtocol, Action: ActionProtocol>: Store {

/// Sends an action to the store, which is then reduced to produce a new state
public func send(_ action: Action) {
logger("🦄 \(String(describing: Self.self)): sending \(action)")

let previousState = stateSignal.value

stateWriteSignal.value = reduce(stateSignal.value, action)
actionCallbacker.callAll(with: action)

DispatchQueue.global(qos: .background).async {
Self.persist(self.stateSignal.value)
}

let newState = stateSignal.value

if newState != previousState {
logger("🦄 \(String(describing: Self.self)): new state \n \(newState)")
}
Task {
await sendAsync(action)
await effects({
self.stateSignal.value
}, action)
}
}

Expand Down

0 comments on commit e01d2e0

Please sign in to comment.