Skip to content

Commit

Permalink
Merge pull request #31 from StevenLambion/bugs/fix-reference-based-bi…
Browse files Browse the repository at this point in the history
…ndings

Re-render the view when a referenced-based binding is updated.
  • Loading branch information
StevenLambion authored Feb 7, 2020
2 parents e132b91 + fc72f2d commit 9b03dff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 0 additions & 4 deletions Sources/SwiftDux/UI/MappedState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public struct MappedState<State>: DynamicProperty where State: Equatable {

@EnvironmentObject private var connection: StateConnection<State>

// Needed by SwiftUI in case StateBinder is used. This attaches the required
// subscriptions.
@Environment(\.actionDispatcher) private var actionDispatcher: ActionDispatcher

public var wrappedValue: State {
guard let state = connection.state else {
fatalError("State was not connected before using @MappedState")
Expand Down
6 changes: 3 additions & 3 deletions Sources/SwiftDux/UI/StateBinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public struct StateBinder {
/// Create a binding between a given state and an action.
///
/// - Parameters:
/// - getState: The state to retrieve.
/// - state: The state to retrieve.
/// - getAction: Given a new version of the state, it returns an action to dispatch.
/// - Returns: A new Binding object.
public func bind<T>(_ getState: @autoclosure @escaping () -> T, dispatch getAction: @escaping (T) -> Action?) -> Binding<T> {
public func bind<T>(_ state: T, dispatch getAction: @escaping (T) -> Action?) -> Binding<T> {
Binding<T>(
get: getState,
get: { state },
set: { [actionDispatcher] in
guard let action = getAction($0) else { return }
actionDispatcher.send(action)
Expand Down

0 comments on commit 9b03dff

Please sign in to comment.