Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Samples/AnimalsData/Sources/AnimalsData/AnimalsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum AnimalsReducer {
@Sendable public static func reduce(
state: AnimalsState,
action: AnimalsAction
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
switch action {
case .ui(action: let action):
return try self.reduce(state: state, action: action)
Expand All @@ -34,7 +34,7 @@ extension AnimalsReducer {
private static func reduce(
state: AnimalsState,
action: AnimalsAction.UI
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
switch action {
case .categoryList(action: let action):
return try self.reduce(state: state, action: action)
Expand All @@ -52,7 +52,7 @@ extension AnimalsReducer {
private static func reduce(
state: AnimalsState,
action: AnimalsAction.UI.CategoryList
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
switch action {
case .onAppear:
if state.categories.status == nil {
Expand All @@ -75,17 +75,17 @@ extension AnimalsReducer {
}

extension AnimalsReducer {
package struct Error: Swift.Error {
package enum Code: Hashable, Sendable {
public struct Error: Swift.Error {
public enum Code: Hashable, Sendable {
case animalNotFound
}

package let code: Self.Code
public let code: Self.Code
}
}

extension AnimalsState {
fileprivate func onTapDeleteSelectedAnimalButton(animalId: Animal.ID) throws -> Self {
fileprivate func onTapDeleteSelectedAnimalButton(animalId: Animal.ID) throws(AnimalsReducer.Error) -> Self {
guard let _ = self.animals.data[animalId] else {
throw AnimalsReducer.Error(code: .animalNotFound)
}
Expand All @@ -99,7 +99,7 @@ extension AnimalsReducer {
private static func reduce(
state: AnimalsState,
action: AnimalsAction.UI.AnimalList
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
switch action {
case .onAppear:
if state.animals.status == nil {
Expand All @@ -118,7 +118,7 @@ extension AnimalsReducer {
private static func reduce(
state: AnimalsState,
action: AnimalsAction.UI.AnimalDetail
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
switch action {
case .onTapDeleteSelectedAnimalButton(animalId: let animalId):
return try state.onTapDeleteSelectedAnimalButton(animalId: animalId)
Expand All @@ -145,7 +145,7 @@ extension AnimalsState {
name: String,
diet: Animal.Diet,
categoryId: Category.ID
) throws -> Self {
) throws(AnimalsReducer.Error) -> Self {
guard let _ = self.animals.data[animalId] else {
throw AnimalsReducer.Error(code: .animalNotFound)
}
Expand All @@ -159,7 +159,7 @@ extension AnimalsReducer {
private static func reduce(
state: AnimalsState,
action: AnimalsAction.UI.AnimalEditor
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
switch action {
case .onTapAddAnimalButton(id: let id, name: let name, diet: let diet, categoryId: let categoryId):
return state.onTapAddAnimalButton(id: id, name: name, diet: diet, categoryId: categoryId)
Expand All @@ -173,7 +173,7 @@ extension AnimalsReducer {
private static func reduce(
state: AnimalsState,
action: AnimalsAction.Data
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
switch action {
case .persistentSession(.didFetchCategories(result: let result)):
return self.persistentSessionDidFetchCategories(state: state, result: result)
Expand Down Expand Up @@ -288,7 +288,7 @@ extension AnimalsReducer {
state: AnimalsState,
animalId: Animal.ID,
result: AnimalsAction.Data.PersistentSession.UpdateAnimalResult
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
guard let _ = state.animals.data[animalId] else {
throw AnimalsReducer.Error(code: .animalNotFound)
}
Expand All @@ -309,7 +309,7 @@ extension AnimalsReducer {
state: AnimalsState,
animalId: Animal.ID,
result: AnimalsAction.Data.PersistentSession.DeleteAnimalResult
) throws -> AnimalsState {
) throws(AnimalsReducer.Error) -> AnimalsState {
guard let _ = state.animals.data[animalId] else {
throw AnimalsReducer.Error(code: .animalNotFound)
}
Expand Down
14 changes: 7 additions & 7 deletions Samples/AnimalsData/Sources/AnimalsData/Listener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension UserDefaults {
}

extension Listener {
public func listen(to store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction> & ImmutableData.Selector<AnimalsState> & ImmutableData.Streamer<AnimalsState, AnimalsAction> & AnyObject) {
public func listen(to store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error> & ImmutableData.Selector<AnimalsState> & ImmutableData.Streamer<AnimalsState, AnimalsAction> & AnyObject) {
if self.store !== store {
self.store = store

Expand All @@ -65,7 +65,7 @@ extension Listener {

extension Listener {
private func onReceive(
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction> & ImmutableData.Selector<AnimalsState>,
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error> & ImmutableData.Selector<AnimalsState>,
oldState: AnimalsState,
action: AnimalsAction
) async {
Expand All @@ -80,7 +80,7 @@ extension Listener {

extension Listener {
private func onReceive(
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction> & ImmutableData.Selector<AnimalsState>,
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error> & ImmutableData.Selector<AnimalsState>,
oldState: AnimalsState,
action: AnimalsAction.UI
) async {
Expand All @@ -99,7 +99,7 @@ extension Listener {

extension Listener {
private func onReceive(
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction> & ImmutableData.Selector<AnimalsState>,
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error> & ImmutableData.Selector<AnimalsState>,
oldState: AnimalsState,
action: AnimalsAction.UI.CategoryList
) async {
Expand Down Expand Up @@ -134,7 +134,7 @@ extension Listener {

extension Listener {
private func onReceive(
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction> & ImmutableData.Selector<AnimalsState>,
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error> & ImmutableData.Selector<AnimalsState>,
oldState: AnimalsState,
action: AnimalsAction.UI.AnimalList
) async {
Expand Down Expand Up @@ -167,7 +167,7 @@ extension Listener {

extension Listener {
private func onReceive(
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction> & ImmutableData.Selector<AnimalsState>,
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error> & ImmutableData.Selector<AnimalsState>,
oldState: AnimalsState,
action: AnimalsAction.UI.AnimalDetail
) async {
Expand All @@ -189,7 +189,7 @@ extension Listener {

extension Listener {
private func onReceive(
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction> & ImmutableData.Selector<AnimalsState>,
from store: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error> & ImmutableData.Selector<AnimalsState>,
oldState: AnimalsState,
action: AnimalsAction.UI.AnimalEditor
) async {
Expand Down
24 changes: 12 additions & 12 deletions Samples/AnimalsData/Sources/AnimalsData/PersistentSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension PersistentSession {
func fetchAnimalsQuery<Dispatcher, Selector>() -> @Sendable (
Dispatcher,
Selector
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction>, Selector : ImmutableData.Selector<AnimalsState> {
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Selector : ImmutableData.Selector<AnimalsState> {
{ dispatcher, selector in
try await self.fetchAnimalsQuery(
dispatcher: dispatcher,
Expand All @@ -61,7 +61,7 @@ extension PersistentSession {

extension PersistentSession {
private func fetchAnimalsQuery(
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction>,
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>,
selector: some ImmutableData.Selector<AnimalsState>
) async throws {
let animals = try await {
Expand Down Expand Up @@ -105,7 +105,7 @@ extension PersistentSession {
) -> @Sendable (
Dispatcher,
Selector
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction>, Selector : ImmutableData.Selector<AnimalsState> {
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Selector : ImmutableData.Selector<AnimalsState> {
{ dispatcher, selector in
try await self.addAnimalMutation(
dispatcher: dispatcher,
Expand All @@ -121,7 +121,7 @@ extension PersistentSession {

extension PersistentSession {
private func addAnimalMutation(
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction>,
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>,
selector: some ImmutableData.Selector<AnimalsState>,
id: String,
name: String,
Expand Down Expand Up @@ -175,7 +175,7 @@ extension PersistentSession {
) -> @Sendable (
Dispatcher,
Selector
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction>, Selector : ImmutableData.Selector<AnimalsState> {
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Selector : ImmutableData.Selector<AnimalsState> {
{ dispatcher, selector in
try await self.updateAnimalMutation(
dispatcher: dispatcher,
Expand All @@ -191,7 +191,7 @@ extension PersistentSession {

extension PersistentSession {
private func updateAnimalMutation(
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction>,
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>,
selector: some ImmutableData.Selector<AnimalsState>,
animalId: String,
name: String,
Expand Down Expand Up @@ -243,7 +243,7 @@ extension PersistentSession {
) -> @Sendable (
Dispatcher,
Selector
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction>, Selector : ImmutableData.Selector<AnimalsState> {
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Selector : ImmutableData.Selector<AnimalsState> {
{ dispatcher, selector in
try await self.deleteAnimalMutation(
dispatcher: dispatcher,
Expand All @@ -256,7 +256,7 @@ extension PersistentSession {

extension PersistentSession {
private func deleteAnimalMutation(
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction>,
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>,
selector: some ImmutableData.Selector<AnimalsState>,
animalId: String
) async throws {
Expand Down Expand Up @@ -300,7 +300,7 @@ extension PersistentSession {
func fetchCategoriesQuery<Dispatcher, Selector>() -> @Sendable (
Dispatcher,
Selector
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction>, Selector : ImmutableData.Selector<AnimalsState> {
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Selector : ImmutableData.Selector<AnimalsState> {
{ dispatcher, selector in
try await self.fetchCategoriesQuery(
dispatcher: dispatcher,
Expand All @@ -312,7 +312,7 @@ extension PersistentSession {

extension PersistentSession {
private func fetchCategoriesQuery(
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction>,
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>,
selector: some ImmutableData.Selector<AnimalsState>
) async throws {
let categories = try await {
Expand Down Expand Up @@ -351,7 +351,7 @@ extension PersistentSession {
func reloadSampleDataMutation<Dispatcher, Selector>() -> @Sendable (
Dispatcher,
Selector
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction>, Selector : ImmutableData.Selector<AnimalsState> {
) async throws -> Void where Dispatcher : ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Selector : ImmutableData.Selector<AnimalsState> {
{ dispatcher, selector in
try await self.reloadSampleDataMutation(
dispatcher: dispatcher,
Expand All @@ -363,7 +363,7 @@ extension PersistentSession {

extension PersistentSession {
private func reloadSampleDataMutation(
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction>,
dispatcher: some ImmutableData.Dispatcher<AnimalsState, AnimalsAction, AnimalsReducer.Error>,
selector: some ImmutableData.Selector<AnimalsState>
) async throws {
let (animals, categories) = try await {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extension PersistentSessionPersistentStoreTestDouble {
}

extension StoreTestDouble : ImmutableData.Dispatcher {
func dispatch(action: Action) throws {
func dispatch(action: Action) throws(AnimalsReducer.Error) {
self.parameterAction.append(action)
}

Expand Down
2 changes: 1 addition & 1 deletion Samples/AnimalsUI/Sources/AnimalsUI/Dispatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import SwiftUI

}

var wrappedValue: (AnimalsAction) throws -> Void {
var wrappedValue: (AnimalsAction) throws(AnimalsReducer.Error) -> Void {
self.dispatcher.dispatch
}
}
2 changes: 1 addition & 1 deletion Samples/AnimalsUI/Sources/AnimalsUI/PreviewStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ImmutableUI
import SwiftUI

@MainActor struct PreviewStore<Content> where Content : View {
@State private var store: ImmutableData.Store<AnimalsState, AnimalsAction> = {
@State private var store: ImmutableData.Store<AnimalsState, AnimalsAction, AnimalsReducer.Error> = {
do {
let store = ImmutableData.Store(
initialState: AnimalsState(),
Expand Down
12 changes: 6 additions & 6 deletions Samples/AnimalsUI/Sources/AnimalsUI/Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension ImmutableUI.Selector {
filter isIncluded: (@Sendable (Store.State, Store.Action) -> Bool)? = nil,
dependencySelector: repeat @escaping @Sendable (Store.State) -> each Dependency,
outputSelector: @escaping @Sendable (Store.State) -> Output
) where Store == ImmutableData.Store<AnimalsState, AnimalsAction>, repeat each Dependency : Equatable, Output : Equatable {
) where Store == ImmutableData.Store<AnimalsState, AnimalsAction, AnimalsReducer.Error>, repeat each Dependency : Equatable, Output : Equatable {
self.init(
id: id,
label: label,
Expand All @@ -56,7 +56,7 @@ extension ImmutableUI.Selector {
filter isIncluded: (@Sendable (Store.State, Store.Action) -> Bool)? = nil,
dependencySelector: repeat @escaping @Sendable (Store.State) -> each Dependency,
outputSelector: @escaping @Sendable (Store.State) -> Output
) where Store == ImmutableData.Store<AnimalsState, AnimalsAction>, repeat each Dependency : Equatable, Output : Equatable {
) where Store == ImmutableData.Store<AnimalsState, AnimalsAction, AnimalsReducer.Error>, repeat each Dependency : Equatable, Output : Equatable {
self.init(
label: label,
filter: isIncluded,
Expand Down Expand Up @@ -91,7 +91,7 @@ extension ImmutableUI.Selector {
}

@MainActor @propertyWrapper struct SelectCategory: DynamicProperty {
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction>, AnimalsData.Category?> var wrappedValue: AnimalsData.Category?
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction, AnimalsReducer.Error>, AnimalsData.Category?> var wrappedValue: AnimalsData.Category?

init(categoryId: AnimalsData.Category.ID?) {
self._wrappedValue = ImmutableUI.Selector(
Expand All @@ -111,7 +111,7 @@ extension ImmutableUI.Selector {
}

@MainActor @propertyWrapper struct SelectAnimalsValues: DynamicProperty {
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction>, TreeDictionary<Animal.ID, Animal>, Array<Animal>> var wrappedValue: Array<Animal>
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction, AnimalsReducer.Error>, TreeDictionary<Animal.ID, Animal>, Array<Animal>> var wrappedValue: Array<Animal>

init(categoryId: AnimalsData.Category.ID?) {
self._wrappedValue = ImmutableUI.Selector(
Expand Down Expand Up @@ -139,7 +139,7 @@ extension ImmutableUI.Selector {
}

@MainActor @propertyWrapper struct SelectAnimal: DynamicProperty {
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction>, Animal?> var wrappedValue: Animal?
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Animal?> var wrappedValue: Animal?

init(animalId: Animal.ID?) {
self._wrappedValue = ImmutableUI.Selector(
Expand All @@ -151,7 +151,7 @@ extension ImmutableUI.Selector {
}

@MainActor @propertyWrapper struct SelectAnimalStatus: DynamicProperty {
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction>, Status?> var wrappedValue: Status?
@ImmutableUI.Selector<ImmutableData.Store<AnimalsState, AnimalsAction, AnimalsReducer.Error>, Status?> var wrappedValue: Status?

init(animalId: Animal.ID?) {
self._wrappedValue = ImmutableUI.Selector(
Expand Down
Loading