add valueAction

This commit is contained in:
Max Sokolov 2016-05-06 19:03:36 +03:00
parent 32a257149e
commit 7083462aca
3 changed files with 15 additions and 5 deletions

View File

@ -26,7 +26,7 @@ public typealias ReturnValue = AnyObject?
enum ActionHandler<DataType, CellType> {
case Handler((data: ActionData<DataType, CellType>) -> Void)
case ReturnValueHandler((data: ActionData<DataType, CellType>) -> AnyObject?)
case ValueHandler((data: ActionData<DataType, CellType>) -> AnyObject?)
func invoke(data: ActionData<DataType, CellType>) -> ReturnValue {
@ -34,7 +34,7 @@ enum ActionHandler<DataType, CellType> {
case .Handler(let handler):
handler(data: data)
return true
case .ReturnValueHandler(let handler):
case .ValueHandler(let handler):
return handler(data: data)
}
}
@ -104,9 +104,9 @@ public class TableRowBuilder<DataType, CellType where CellType: UITableViewCell>
return self
}
public func action(type: ActionType, handler: (data: ActionData<DataType, CellType>) -> ReturnValue) -> Self {
public func valueAction(type: ActionType, handler: (data: ActionData<DataType, CellType>) -> ReturnValue) -> Self {
actions[type.key] = .ReturnValueHandler(handler)
actions[type.key] = .ValueHandler(handler)
return self
}

View File

@ -22,9 +22,19 @@ class MainController: UIViewController {
super.viewDidLoad()
let rows = TableConfigurableRowBuilder<String, StoryboardTableViewCell>(items: ["1", "2", "3"])
.action(.click) { [unowned self] data -> Void in
.action(.click) { [unowned self] e in
self.performSegueWithIdentifier("headerfooter", sender: nil)
}
.valueAction(.click) { data in
return 10
}
.action(.click) { data in
self.performSegueWithIdentifier("headerfooter", sender: nil)
}
.action(.click) { data in
}
print("", String(TableDirector.self))