Skip to content

Commit

Permalink
Merge pull request #4 from SwiftRex/Add-button-extension
Browse files Browse the repository at this point in the history
Add button extension
  • Loading branch information
GiuliaAriu authored Jun 30, 2021
2 parents 95d852b + a0eb86f commit cf3565f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/CombineRextensions/Button+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ extension Button where Label == Text {
}
}

extension Button where Label == Text {
public init<S: StoreType>(localizedString: KeyPath<S.StateType, String>,
store: S,
action: @escaping @autoclosure () -> S.ActionType,
file: String = #file,
function: String = #function,
line: UInt = #line,
info: String? = nil) {
let actionSource = ActionSource(file: file, function: function, line: line, info: info)
self.init(store.state[keyPath: localizedString], action: {
store.dispatch(action(), from: actionSource)
})
}
}

extension Button {
public init<S: StoreType>(store: S,
action: @escaping @autoclosure () -> S.ActionType,
Expand Down

0 comments on commit cf3565f

Please sign in to comment.