Issue 29 table view data source editing#67
Conversation
Example mixed swift3.0. close #59.
# Conflicts: # Source/BridgedDataSource.swift # Source/BridgedFetchedResultsDelegate.swift
|
Thanks @psartzetakis ! 🎉 Just gave this a glance for now. Looks good! I'll give more feedback soon. |
e31c1fe to
2a31162
Compare
|
Hey @psartzetakis ! Just merged |
|
Hey @jessesquires , Just changed it to develop 👍 |
…leViewDataSource_editing # Conflicts: # .travis.yml # Source/BridgedFetchedResultsDelegate.swift # Source/DataSourceProvider.swift
Current coverage is 93.59% (diff: 96.77%)@@ develop #67 diff @@
==========================================
Files 9 10 +1
Lines 360 390 +30
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 336 365 +29
- Misses 24 25 +1
Partials 0 0
|
…leViewDataSource_editing ViewDataSource_editing # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
…ting' into issue_29_tableViewDataSource_editing
|
Hi @jessesquires , |
jessesquires
left a comment
There was a problem hiding this comment.
Thanks so much @psartzetakis !
Left some review comments, mostly just some style nits. 😄
| return cell | ||
| } | ||
|
|
||
| //3. Optional - create if neccessary a datasourceEditingController to enable the editing functionality on the tableView |
| internal typealias TableTitleForFooterInSectionHandler = (Int) -> String? | ||
|
|
||
| internal typealias TableCanEditRowAtIndexPathHandler = (UITableView, IndexPath) -> Bool | ||
| internal typealias TableCommitEditingStyleForRowAtIndexPathHandler = (UITableView, UITableViewCellEditingStyle, IndexPath) -> Void |
There was a problem hiding this comment.
nit: let's have shorter names here:
TableCanEditHandlerTableCommitEditingStyleHandler
| var tableTitleForFooterInSection: TableTitleForFooterInSectionHandler? | ||
|
|
||
| var tableCanEditRowAtIndexPath: TableCanEditRowAtIndexPathHandler? | ||
| var tableCommitEditingStyleForRowAtIndexPath: TableCommitEditingStyleForRowAtIndexPathHandler? |
There was a problem hiding this comment.
nit, same as above:
var tableCanEditRowvar tableCommitEditingForRow
| } | ||
|
|
||
| @objc func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { | ||
| if let closure = tableCanEditRowAtIndexPath{ |
| Removes an Item at a specific `IndexPath` | ||
|
|
||
| - parameter indexPath: The index path specifying the location of the cell | ||
| - returns: The item specified by indexPath, or `nil` |
There was a problem hiding this comment.
nit: need a . after each sentence 😄
| return canEditConfigurator(indexPath, tableView) | ||
| } | ||
|
|
||
| public func configureCommitEditStyleForRow(in tableView: UITableView, editingStyle: UITableViewCellEditingStyle, at indexPath: IndexPath) { |
| }) | ||
| } | ||
|
|
||
| } |
| let item = dataSource[ip] | ||
|
|
||
| // THEN: we receive the exepected data | ||
| // THEN: we receive the expected data |
| // THEN: the removedItem is the expected item | ||
| let removedItem = dataSource.remove(at: ip) | ||
| XCTAssertEqual(removedItem, itemToRemove) | ||
| } |
There was a problem hiding this comment.
we should test out-of-bounds indexPaths, too 😄
|
|
||
|
|
||
| //The data source that provides the editing functionality on the tableView | ||
| public var dataSourceTableEditing: DataSourceTableEditingProtocol? |
There was a problem hiding this comment.
it would be nice to only have this property for tableView dataSources... but I'm not sure if we can express that?
perhaps:
- this could be
private(orfileprivate) - then, we could expose the setter for only
tableViewdataSources
?
There was a problem hiding this comment.
I believe we can add that requirement here
public extension DataSourceProvider where CellFactory.View: UITableViewCell.
So they will be able to set the property of tableEditingController
what do you think?
Sorry ignore me for now, having second thoughts... :)
|
One more thing: I updated this branch via the GitHub UI, so you might need to pull. Oh, and again, sorry for the delay here! 😊 |
|
I think the biggest thing here is figuring out how to expose the cc @dcaunt - any thoughts? |
|
Hi @jessesquires , |
jessesquires
left a comment
There was a problem hiding this comment.
Thanks so much @psartzetakis ! 🎉
So sorry it took me so long to review here. Overall this looks great! 👍 Just a few more minor comments.
If you don't have time, we carry these changes forward for you. Just let us know.
|
|
||
|
|
||
| //The data source that provides the editing functionality on the tableView | ||
| fileprivate var dataSourceTableEditing: TableDataSourceEditingController? |
There was a problem hiding this comment.
why not make this public and remove setTableDataSourceEditingController(_:) below?
also, we can remove the comment 😄
There was a problem hiding this comment.
Hi @jessesquires ,
Thanks for the review 😄 . The reason that I didn't make it public in the first place is because I wanted to constraint it (through the extension) so that it can be used only for a tableView. Since I cannot have a stored property in an extension I thought of setting the dataSourceTableEditing through a public function in the extension. Another option would be to have a public computed property in the extension that it's setter/getter will use either objc runtime or they will access directly the fileprivate var dataSourceTableEditing. Please let me know your thoughts on that. There might be a way that I have missed or we might don't want any of these approaches 😄
After we sort this I will proceed with applying the changes 👍
There was a problem hiding this comment.
oh, duh! sorry 😄
Ok, this looks good structurally. Only suggestion then is to follow the style of
public var tableViewDataSource: UITableViewDataSource
let's have a fileprivate var _tableEditingController and a public var tableEditingController (computed) in the extension 👍
|
|
||
| dataSource.tableCommitEditingStyleForRow = { [unowned self] (tableView, editingStyle,indexPath) in | ||
| self.dataSourceTableEditing?.commitEditStyleForRow(in: tableView, editingStyle: editingStyle, at: indexPath) | ||
| } |
| // | ||
| // Created by Panagiotis Sartzetakis on 12/09/2016. | ||
| // Copyright © 2016 Hexed Bits. All rights reserved. | ||
| // |
There was a problem hiding this comment.
- let's replace with the project comment headers 😄
- can we rename this file to
TableDataSourceEditingController.swift?
| return commitEditingStyle(tableView, editingStyle, indexPath) | ||
| } | ||
|
|
||
| } |
| let row = indexPath.row | ||
|
|
||
| return row < numberOfItems(inSection: section) | ||
| } |
There was a problem hiding this comment.
I think we can get rid of both of these.
Instead, we can just check if dataSource.item(atIndexPath: ip) == nil
There was a problem hiding this comment.
ok cool, I know that you have opened a PR #76 for making public the function dataSource.item(atIndexPath: ip) but I need to make it public as well in order to use it ..😄
| let section = indexPath.section | ||
| let row = indexPath.row | ||
| return sections[section].items.remove(at: row) | ||
| } |
| Removes an Item at a specific `IndexPath`. | ||
|
|
||
| - parameter indexPath: The index path specifying the location of the cell. | ||
| - returns: The item specified by indexPath, or `nil`. |
There was a problem hiding this comment.
Let's update to:
/**
Removes an item at the specified index path.
- parameter indexPath: The index path specifying the location of the item.
- returns: The item at `indexPath`, or `nil` if it does not exist.|
|
||
| dataSourceProvider?.setTableDataSourceEditingController(tableDataSourceEditingController) | ||
|
|
||
| // 5. set data source |
…leViewDataSource_editing
|
Awesome 🎉 |
| - parameter dataSource: The data source. | ||
| - parameter cellFactory: The cell factory. | ||
| - parameter supplementaryFactory: The supplementary view factory. | ||
| to edit it's cells |
|
Thanks so much @psartzetakis ! 🎉 |
- refine closure param order - rename TableEditingController - refine public interface to TableEditingController - refine naming - update example app
|
We really appreciate the help and effort with this PR! It was great. I've sent you an invite to be a collaborator on this project. This will give you push access + other permissions. 😄 There's no pressure to accept or even contribute anything else if you don't want to! 😊 |
|
Really glad I helped @jessesquires 🎉 . Thanks for the invitation, it will be a pleasure to keep contributing. 😄 |
Pull request checklist
This fixes issue #29 .
What's in this pull request?
The edit functionality of tableView provided by the UITableViewDataSource is now exposed through JSQDataSourcesKit