perform -> invoke
This commit is contained in:
parent
a268a726bb
commit
8613687eea
22
README.md
22
README.md
|
|
@ -49,7 +49,7 @@ You may want to setup a very basic table view, without any custom cells. In that
|
|||
import Tablet
|
||||
|
||||
let rowBuilder = TableRowBuilder<User, UITableViewCell>(items: [user1, user2, user3], id: "reusable_id")
|
||||
.action(.configure) { data in
|
||||
.action(.configure) { data -> Void in
|
||||
|
||||
data.cell?.textLabel?.text = data.item.username
|
||||
data.cell?.detailTextLabel?.text = data.item.isActive ? "Active" : "Inactive"
|
||||
|
|
@ -104,13 +104,13 @@ Tablet provides a chaining approach to handle actions from your cells:
|
|||
import Tablet
|
||||
|
||||
let rowBuilder = TableRowBuilder<User, MyTableViewCell>(items: [user1, user2, user3], id: "reusable_id")
|
||||
.action(.configure) { data in
|
||||
.action(.configure) { data -> Void in
|
||||
|
||||
}
|
||||
.action(.click) { data in
|
||||
.action(.click) { data -> Void in
|
||||
|
||||
}
|
||||
.action(.shouldHighlight) { data in
|
||||
.action(.shouldHighlight) { data -> ReturnValue in
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ class MyTableViewCell : UITableViewCell {
|
|||
|
||||
@IBAction func buttonClicked(sender: UIButton) {
|
||||
|
||||
Action(key: kMyAction, sender: self, userInfo: nil).perform()
|
||||
Action(key: kMyAction, sender: self, userInfo: nil).invoke()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
@ -135,13 +135,13 @@ And receive this actions with your row builder:
|
|||
import Tablet
|
||||
|
||||
let rowBuilder = TableConfigurableRowBuilder<User, MyTableViewCell>(items: users, id: "reusable_id", estimatedRowHeight: 42)
|
||||
.action(.click) { data in
|
||||
.action(.click) { data -> Void in
|
||||
|
||||
}
|
||||
.action(.willDisplay) { data in
|
||||
.action(.willDisplay) { data -> Void in
|
||||
|
||||
}
|
||||
.action(kMyAction) { data in
|
||||
.action(kMyAction) { data -> Void in
|
||||
|
||||
}
|
||||
```
|
||||
|
|
@ -159,18 +159,18 @@ extension TableDirector {
|
|||
|
||||
public func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
|
||||
|
||||
performAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
|
||||
invokeAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
|
||||
}
|
||||
}
|
||||
```
|
||||
Catch your action with row builder:
|
||||
```swift
|
||||
let rowBuilder = TableConfigurableRowBuilder<User, MyTableViewCell>(items: users, estimatedRowHeight: 42)
|
||||
.action(kTableDirectorDidEndDisplayingCell) { data in
|
||||
.action(kTableDirectorDidEndDisplayingCell) { data -> Void in
|
||||
|
||||
}
|
||||
```
|
||||
You could also perform an action that returns a value.
|
||||
You could also invoke an action that returns a value.
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
|||
|
|
@ -69,10 +69,10 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
|
|||
return sections[indexPath.section].builderAtIndex(indexPath.row)!
|
||||
}
|
||||
|
||||
public func performAction(action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? {
|
||||
public func invokeAction(action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? {
|
||||
|
||||
let builder = builderAtIndexPath(indexPath)
|
||||
return builder.0.performAction(action, cell: cell, indexPath: indexPath, itemIndex: builder.1)
|
||||
return builder.0.invokeAction(action, cell: cell, indexPath: indexPath, itemIndex: builder.1)
|
||||
}
|
||||
|
||||
internal func didReceiveAction(notification: NSNotification) {
|
||||
|
|
@ -80,7 +80,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
|
|||
if let action = notification.object as? Action, indexPath = tableView.indexPathForCell(action.cell) {
|
||||
|
||||
let builder = builderAtIndexPath(indexPath)
|
||||
builder.0.performAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1)
|
||||
builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate
|
|||
|
||||
let cell = tableView.dequeueReusableCellWithIdentifier(builder.0.reusableIdentifier, forIndexPath: indexPath)
|
||||
|
||||
builder.0.performAction(.configure, cell: cell, indexPath: indexPath, itemIndex: builder.1)
|
||||
builder.0.invokeAction(.configure, cell: cell, indexPath: indexPath, itemIndex: builder.1)
|
||||
|
||||
return cell
|
||||
}
|
||||
|
|
@ -156,32 +156,32 @@ extension TableDirector {
|
|||
|
||||
public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
|
||||
|
||||
return performAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension
|
||||
return invokeAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension
|
||||
}
|
||||
|
||||
public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
|
||||
|
||||
let cell = tableView.cellForRowAtIndexPath(indexPath)
|
||||
|
||||
if performAction(.click, cell: cell, indexPath: indexPath) != nil {
|
||||
if invokeAction(.click, cell: cell, indexPath: indexPath) != nil {
|
||||
tableView.deselectRowAtIndexPath(indexPath, animated: true)
|
||||
} else {
|
||||
performAction(.select, cell: cell, indexPath: indexPath)
|
||||
invokeAction(.select, cell: cell, indexPath: indexPath)
|
||||
}
|
||||
}
|
||||
|
||||
public func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
|
||||
|
||||
performAction(.deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath)
|
||||
invokeAction(.deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath)
|
||||
}
|
||||
|
||||
public func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
|
||||
|
||||
performAction(.willDisplay, cell: cell, indexPath: indexPath)
|
||||
invokeAction(.willDisplay, cell: cell, indexPath: indexPath)
|
||||
}
|
||||
|
||||
public func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
||||
|
||||
return performAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true
|
||||
return invokeAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true
|
||||
}
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ public class TableRowBuilder<I, C where C: UITableViewCell> : RowBuilder {
|
|||
|
||||
// MARK: Triggers
|
||||
|
||||
public func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? {
|
||||
public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? {
|
||||
|
||||
if let action = actions[actionType.key] {
|
||||
return action.call(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex))
|
||||
|
|
@ -129,13 +129,13 @@ public class TableConfigurableRowBuilder<I, C: ConfigurableCell where C.Item ==
|
|||
super.init(items: items, id: C.reusableIdentifier(), estimatedRowHeight: estimatedRowHeight)
|
||||
}
|
||||
|
||||
public override func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? {
|
||||
public override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? {
|
||||
|
||||
switch actionType {
|
||||
case .configure:
|
||||
(cell as? C)?.configureWithItem(items[itemIndex])
|
||||
default: break
|
||||
}
|
||||
return super.performAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex)
|
||||
return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class Action {
|
|||
self.userInfo = userInfo
|
||||
}
|
||||
|
||||
public func perform() {
|
||||
public func invoke() {
|
||||
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(kActionPerformedNotificationKey, object: self)
|
||||
}
|
||||
|
|
@ -114,5 +114,5 @@ public protocol RowBuilder {
|
|||
var reusableIdentifier: String { get }
|
||||
var estimatedRowHeight: CGFloat { get }
|
||||
|
||||
func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject?
|
||||
func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject?
|
||||
}
|
||||
Binary file not shown.
|
|
@ -29,6 +29,6 @@ class ConfigurableTableViewCell: UITableViewCell, ConfigurableCell {
|
|||
|
||||
@IBAction func buttonClicked(sender: UIButton) {
|
||||
|
||||
Action(key: kConfigurableTableViewCellButtonClickedAction, sender: self).perform()
|
||||
Action(key: kConfigurableTableViewCellButtonClickedAction, sender: self).invoke()
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,6 @@ extension TableDirector {
|
|||
|
||||
public func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
|
||||
|
||||
performAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
|
||||
invokeAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue