Skip to content

Commit 35b2a6a

Browse files
Don't require State to be Encodable (#74)
* Don't require State to be Encodable * Update docs and tests
1 parent d463f7b commit 35b2a6a

File tree

9 files changed

+12
-12
lines changed

9 files changed

+12
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import Fluxor
6666
import Foundation
6767

6868
// 3
69-
struct AppState: Encodable {
69+
struct AppState {
7070
var counter: Int
7171
}
7272

Sources/Fluxor/Store.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import struct Foundation.UUID
2525
## Interceptors
2626
It is possible to intercept all `Action`s and `State` changes by registering an `Interceptor`.
2727
*/
28-
open class Store<State: Encodable, Environment>: ObservableObject {
28+
open class Store<State, Environment>: ObservableObject {
2929
/// The state of the `Store`. It can only be modified by the registered `Reducer`s when `Action`s are dispatched.
3030
@Published public private(set) var state: State
3131
internal private(set) var stateHash = UUID()

Sources/FluxorSwiftUI/ObservableValue.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ObservableValue<Value>: ObservableObject {
3434
- Parameter store: The `Store` to select from
3535
- Parameter selector: The `Selector`s to use for selecting
3636
*/
37-
public init<State: Encodable, Environment>(store: Store<State, Environment>, selector: Selector<State, Value>) {
37+
public init<State, Environment>(store: Store<State, Environment>, selector: Selector<State, Value>) {
3838
self.current = store.selectCurrent(selector)
3939
self.cancellable = store.select(selector).assign(to: \.current, on: self)
4040
}

Sources/FluxorSwiftUI/ValueBinding.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class ValueBinding<Value, UpdateValue> {
8585
- Parameter actionTemplateForValue: A closure used to decide which`ActionTemplate` to use
8686
for dispatching an `Action` when the value changes
8787
*/
88-
public init<State: Encodable, Environment>(store: Store<State, Environment>,
88+
public init<State, Environment>(store: Store<State, Environment>,
8989
selector: Fluxor.Selector<State, Value>,
9090
actionTemplate: @escaping (Value) -> ActionTemplate<UpdateValue>) {
9191
self.storeSelectCurrent = { store.selectCurrent(selector) }
@@ -101,7 +101,7 @@ public class ValueBinding<Value, UpdateValue> {
101101
- Parameter selector: The `Selector`s to use for selecting
102102
- Parameter actionTemplate: The `ActionTemplate` to use for dispatching an `Action` when the value changes
103103
*/
104-
public convenience init<State: Encodable, Environment>(store: Store<State, Environment>,
104+
public convenience init<State, Environment>(store: Store<State, Environment>,
105105
selector: Fluxor.Selector<State, Value>,
106106
actionTemplate: ActionTemplate<UpdateValue>) {
107107
self.init(store: store, selector: selector, actionTemplate: { _ in actionTemplate })

Sources/FluxorTestSupport/MockStore.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import struct Foundation.UUID
1414
A `MockStore` is intended to be used in unit tests where you want to observe
1515
which `Action`s are dispatched and manipulate the `State` and `Selector`s.
1616
*/
17-
public class MockStore<State: Encodable, Environment>: Store<State, Environment> {
17+
public class MockStore<State, Environment>: Store<State, Environment> {
1818
/// All the `Action`s and state changes that has happened.
1919
public var stateChanges: [(action: Action, oldState: State, newState: State)] {
2020
self.testInterceptor.stateChanges

Tests/FluxorSwiftUITests/ObservableValueTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class ObservableValueTests: XCTestCase {
2727
}
2828
}
2929

30-
private struct TestState: Encodable {
30+
private struct TestState {
3131
var counter: Int = 42
3232
}

Tests/FluxorSwiftUITests/ValueBindingTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class ValueBindingTests: XCTestCase {
103103
}
104104
}
105105

106-
private struct TestState: Encodable {
106+
private struct TestState {
107107
var counter: Int = 42
108108
var locked: Bool = false
109109
var lightsOn: Bool = false

Tests/FluxorTests/MockStoreTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class MockStoreTests: XCTestCase {
9191
XCTAssertEqual(mockStore.stateChanges[1].newState, modifiedState)
9292
}
9393

94-
private struct TestState: Encodable, Equatable {
94+
private struct TestState: Equatable {
9595
var counter: Int
9696
}
9797

Tests/FluxorTests/StoreTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ class StoreTests: XCTestCase {
256256

257257
private struct TestAction: Action, Equatable {}
258258

259-
private struct TestState: Encodable, Equatable {
259+
private struct TestState: Equatable {
260260
var type: TestType
261261
var lastAction: String?
262262
var todos = TodosState()
263263
}
264264

265-
private struct TodosState: Encodable, Equatable {
265+
private struct TodosState: Equatable {
266266
var counter: Int = 0
267267
}
268268

@@ -293,7 +293,7 @@ private class TestEnvironment: Equatable {
293293
}
294294
}
295295

296-
private enum TestType: String, Encodable {
296+
private enum TestType: String {
297297
case initial
298298
case modified
299299
case modifiedAgain

0 commit comments

Comments
 (0)