Skip to content

Commit

Permalink
Don't require State to be Encodable (#74)
Browse files Browse the repository at this point in the history
* Don't require State to be Encodable

* Update docs and tests
  • Loading branch information
MortenGregersen authored Jun 4, 2020
1 parent d463f7b commit 35b2a6a
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import Fluxor
import Foundation

// 3
struct AppState: Encodable {
struct AppState {
var counter: Int
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Fluxor/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import struct Foundation.UUID
## Interceptors
It is possible to intercept all `Action`s and `State` changes by registering an `Interceptor`.
*/
open class Store<State: Encodable, Environment>: ObservableObject {
open class Store<State, Environment>: ObservableObject {
/// The state of the `Store`. It can only be modified by the registered `Reducer`s when `Action`s are dispatched.
@Published public private(set) var state: State
internal private(set) var stateHash = UUID()
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluxorSwiftUI/ObservableValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ObservableValue<Value>: ObservableObject {
- Parameter store: The `Store` to select from
- Parameter selector: The `Selector`s to use for selecting
*/
public init<State: Encodable, Environment>(store: Store<State, Environment>, selector: Selector<State, Value>) {
public init<State, Environment>(store: Store<State, Environment>, selector: Selector<State, Value>) {
self.current = store.selectCurrent(selector)
self.cancellable = store.select(selector).assign(to: \.current, on: self)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/FluxorSwiftUI/ValueBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class ValueBinding<Value, UpdateValue> {
- Parameter actionTemplateForValue: A closure used to decide which`ActionTemplate` to use
for dispatching an `Action` when the value changes
*/
public init<State: Encodable, Environment>(store: Store<State, Environment>,
public init<State, Environment>(store: Store<State, Environment>,
selector: Fluxor.Selector<State, Value>,
actionTemplate: @escaping (Value) -> ActionTemplate<UpdateValue>) {
self.storeSelectCurrent = { store.selectCurrent(selector) }
Expand All @@ -101,7 +101,7 @@ public class ValueBinding<Value, UpdateValue> {
- Parameter selector: The `Selector`s to use for selecting
- Parameter actionTemplate: The `ActionTemplate` to use for dispatching an `Action` when the value changes
*/
public convenience init<State: Encodable, Environment>(store: Store<State, Environment>,
public convenience init<State, Environment>(store: Store<State, Environment>,
selector: Fluxor.Selector<State, Value>,
actionTemplate: ActionTemplate<UpdateValue>) {
self.init(store: store, selector: selector, actionTemplate: { _ in actionTemplate })
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluxorTestSupport/MockStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import struct Foundation.UUID
A `MockStore` is intended to be used in unit tests where you want to observe
which `Action`s are dispatched and manipulate the `State` and `Selector`s.
*/
public class MockStore<State: Encodable, Environment>: Store<State, Environment> {
public class MockStore<State, Environment>: Store<State, Environment> {
/// All the `Action`s and state changes that has happened.
public var stateChanges: [(action: Action, oldState: State, newState: State)] {
self.testInterceptor.stateChanges
Expand Down
2 changes: 1 addition & 1 deletion Tests/FluxorSwiftUITests/ObservableValueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class ObservableValueTests: XCTestCase {
}
}

private struct TestState: Encodable {
private struct TestState {
var counter: Int = 42
}
2 changes: 1 addition & 1 deletion Tests/FluxorSwiftUITests/ValueBindingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ValueBindingTests: XCTestCase {
}
}

private struct TestState: Encodable {
private struct TestState {
var counter: Int = 42
var locked: Bool = false
var lightsOn: Bool = false
Expand Down
2 changes: 1 addition & 1 deletion Tests/FluxorTests/MockStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MockStoreTests: XCTestCase {
XCTAssertEqual(mockStore.stateChanges[1].newState, modifiedState)
}

private struct TestState: Encodable, Equatable {
private struct TestState: Equatable {
var counter: Int
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/FluxorTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ class StoreTests: XCTestCase {

private struct TestAction: Action, Equatable {}

private struct TestState: Encodable, Equatable {
private struct TestState: Equatable {
var type: TestType
var lastAction: String?
var todos = TodosState()
}

private struct TodosState: Encodable, Equatable {
private struct TodosState: Equatable {
var counter: Int = 0
}

Expand Down Expand Up @@ -293,7 +293,7 @@ private class TestEnvironment: Equatable {
}
}

private enum TestType: String, Encodable {
private enum TestType: String {
case initial
case modified
case modifiedAgain
Expand Down

0 comments on commit 35b2a6a

Please sign in to comment.