Skip to content
This repository was archived by the owner on Apr 15, 2020. It is now read-only.

Issue 29 table view data source editing#67

Merged
jessesquires merged 41 commits into
jessesquires:developfrom
psartzetakis:issue_29_tableViewDataSource_editing
Dec 13, 2016
Merged

Issue 29 table view data source editing#67
jessesquires merged 41 commits into
jessesquires:developfrom
psartzetakis:issue_29_tableViewDataSource_editing

Conversation

@psartzetakis
Copy link
Copy Markdown
Collaborator

@psartzetakis psartzetakis commented Sep 14, 2016

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

@jessesquires
Copy link
Copy Markdown
Owner

Thanks @psartzetakis ! 🎉

Just gave this a glance for now. Looks good! I'll give more feedback soon.

@jessesquires jessesquires force-pushed the swift3.0 branch 2 times, most recently from e31c1fe to 2a31162 Compare September 17, 2016 09:38
@jessesquires
Copy link
Copy Markdown
Owner

Hey @psartzetakis !

Just merged swift3.0 into develop. Do you mind updating this to merge into develop instead?

@psartzetakis psartzetakis changed the base branch from swift3.0 to develop September 17, 2016 11:25
@psartzetakis
Copy link
Copy Markdown
Collaborator Author

Hey @jessesquires ,

Just changed it to develop 👍

…leViewDataSource_editing

# Conflicts:
#	.travis.yml
#	Source/BridgedFetchedResultsDelegate.swift
#	Source/DataSourceProvider.swift
@codecov-io
Copy link
Copy Markdown

codecov-io commented Sep 17, 2016

Current coverage is 93.59% (diff: 96.77%)

Merging #67 into develop will increase coverage by 0.26%

@@            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          

Sunburst

Diff Coverage File Path
•••••••• 83% Source/BridgedDataSource.swift
•••••••••• 100% new Source/TableDataSourceEditingController.swift
•••••••••• 100% Source/DataSourceProvider.swift
•••••••••• 100% Source/DataSource.swift

Powered by Codecov. Last update d86929f...97f94dc

Panagiotis Sartzetakis added 3 commits September 18, 2016 10:42
…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
@jessesquires jessesquires self-assigned this Oct 1, 2016
@psartzetakis
Copy link
Copy Markdown
Collaborator Author

Hi @jessesquires ,
I was wondering if there is anything that I have a missed or anything else I should do?

Copy link
Copy Markdown
Owner

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space after //

Comment thread Source/BridgedDataSource.swift Outdated
internal typealias TableTitleForFooterInSectionHandler = (Int) -> String?

internal typealias TableCanEditRowAtIndexPathHandler = (UITableView, IndexPath) -> Bool
internal typealias TableCommitEditingStyleForRowAtIndexPathHandler = (UITableView, UITableViewCellEditingStyle, IndexPath) -> Void
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's have shorter names here:

  • TableCanEditHandler
  • TableCommitEditingStyleHandler

Comment thread Source/BridgedDataSource.swift Outdated
var tableTitleForFooterInSection: TableTitleForFooterInSectionHandler?

var tableCanEditRowAtIndexPath: TableCanEditRowAtIndexPathHandler?
var tableCommitEditingStyleForRowAtIndexPath: TableCommitEditingStyleForRowAtIndexPathHandler?
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, same as above:

  • var tableCanEditRow
  • var tableCommitEditingForRow

Comment thread Source/BridgedDataSource.swift Outdated
}

@objc func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
if let closure = tableCanEditRowAtIndexPath{
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space before {

Comment thread Source/DataSource.swift Outdated
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`
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: need a . after each sentence 😄

Comment thread Source/OptionalDataSource.swift Outdated
return canEditConfigurator(indexPath, tableView)
}

public func configureCommitEditStyleForRow(in tableView: UITableView, editingStyle: UITableViewCellEditingStyle, at indexPath: IndexPath) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove "configure"

})
}

}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🙌

let item = dataSource[ip]

// THEN: we receive the exepected data
// THEN: we receive the expected data
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😊

// THEN: the removedItem is the expected item
let removedItem = dataSource.remove(at: ip)
XCTAssertEqual(removedItem, itemToRemove)
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should test out-of-bounds indexPaths, too 😄

Comment thread Source/DataSourceProvider.swift Outdated


//The data source that provides the editing functionality on the tableView
public var dataSourceTableEditing: DataSourceTableEditingProtocol?
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice to only have this property for tableView dataSources... but I'm not sure if we can express that?

perhaps:

  1. this could be private (or fileprivate)
  2. then, we could expose the setter for only tableView dataSources

?

Copy link
Copy Markdown
Collaborator Author

@psartzetakis psartzetakis Nov 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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... :)

@jessesquires
Copy link
Copy Markdown
Owner

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! 😊

@jessesquires
Copy link
Copy Markdown
Owner

I think the biggest thing here is figuring out how to expose the TableEditingController to only tableView.

cc @dcaunt - any thoughts?

@psartzetakis
Copy link
Copy Markdown
Collaborator Author

Hi @jessesquires ,
Just pushed some changes :)

Copy link
Copy Markdown
Owner

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Source/DataSourceProvider.swift Outdated


//The data source that provides the editing functionality on the tableView
fileprivate var dataSourceTableEditing: TableDataSourceEditingController?
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make this public and remove setTableDataSourceEditingController(_:) below?

also, we can remove the comment 😄

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 👍

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


dataSource.tableCommitEditingStyleForRow = { [unowned self] (tableView, editingStyle,indexPath) in
self.dataSourceTableEditing?.commitEditStyleForRow(in: tableView, editingStyle: editingStyle, at: indexPath)
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

//
// Created by Panagiotis Sartzetakis on 12/09/2016.
// Copyright © 2016 Hexed Bits. All rights reserved.
//
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • let's replace with the project comment headers 😄
  • can we rename this file to TableDataSourceEditingController.swift ?

return commitEditingStyle(tableView, editingStyle, indexPath)
}

}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Comment thread Source/DataSource.swift Outdated
let row = indexPath.row

return row < numberOfItems(inSection: section)
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of both of these.

Instead, we can just check if dataSource.item(atIndexPath: ip) == nil

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ..😄

Comment thread Source/DataSource.swift
let section = indexPath.section
let row = indexPath.row
return sections[section].items.remove(at: row)
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread Source/DataSource.swift Outdated
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`.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@jessesquires
Copy link
Copy Markdown
Owner

Awesome 🎉

Comment thread Source/DataSourceProvider.swift Outdated
- parameter dataSource: The data source.
- parameter cellFactory: The cell factory.
- parameter supplementaryFactory: The supplementary view factory.
to edit it's cells
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

@jessesquires
Copy link
Copy Markdown
Owner

Thanks so much @psartzetakis ! 🎉

@jessesquires jessesquires merged commit a9a90b0 into jessesquires:develop Dec 13, 2016
jessesquires added a commit that referenced this pull request Dec 13, 2016
- refine closure param order
- rename TableEditingController
- refine public interface to TableEditingController
- refine naming
- update example app
@jessesquires
Copy link
Copy Markdown
Owner

@psartzetakis

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! 😊

@psartzetakis
Copy link
Copy Markdown
Collaborator Author

Really glad I helped @jessesquires 🎉 . Thanks for the invitation, it will be a pleasure to keep contributing. 😄

@psartzetakis psartzetakis deleted the issue_29_tableViewDataSource_editing branch December 14, 2016 11:53
@jessesquires jessesquires modified the milestones: 6.1.0, 7.0.0 Nov 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants