Skip to content

Commit

Permalink
Remove main actor isolated from Updating (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored Nov 25, 2024
1 parent 70d9e82 commit ad662ac
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import RxSwift
import SwiftUIHosting
import UIKit

enum NonIsolated {

func run(collectionView: UICollectionView) {

let dataSource: SectionDataController<ModelA, CollectionViewAdapter> = .init(
adapter: .init(collectionView: collectionView),
displayingSection: 0
)

}

}

final class SingleSectionCollectionViewController: UIViewController, UICollectionViewDataSource,
UICollectionViewDelegateFlowLayout
{
Expand Down
14 changes: 7 additions & 7 deletions Sources/DataSources/CollectionViewAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

open class CollectionViewAdapter<Element>: Updating {
public struct CollectionViewAdapter<Element>: Updating {

public unowned let collectionView: UICollectionView

Expand All @@ -20,27 +20,27 @@ open class CollectionViewAdapter<Element>: Updating {
self.collectionView = collectionView
}

open func insertItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
public func insertItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {

collectionView.insertItems(at: indexPaths)
}

open func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
public func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {

collectionView.deleteItems(at: indexPaths)
}

open func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
public func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {

collectionView.reloadItems(at: indexPaths)
}

open func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext<Element>) {
public func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext<Element>) {

collectionView.moveItem(at: indexPath, to: newIndexPath)
}

open func performBatch(in context: UpdateContext<Element>, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void) {
public func performBatch(in context: UpdateContext<Element>, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void) {

if animated {
collectionView.performBatchUpdates({
Expand All @@ -63,7 +63,7 @@ open class CollectionViewAdapter<Element>: Updating {

}

open func reload(completion: @escaping () -> Void) {
public func reload(completion: @escaping () -> Void) {

collectionView.reloadData()
completion()
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataSources/SectionDataController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public final class SectionDataController<T: Differentiable & Sendable, A: Updati
/// - adapter:
/// - displayingSection:
/// - isEqual: To use for decision that item should update.
public init(itemType: ItemType.Type? = nil, adapter: AdapterType, displayingSection: Int = 0) {
public init(itemType: ItemType.Type? = nil, adapter: consuming AdapterType, displayingSection: Int = 0) {
self.adapter = adapter
self.displayingSection = displayingSection
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/DataSources/TableViewAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

open class TableViewAdapter<Element>: Updating {
public struct TableViewAdapter<Element>: Updating {

public unowned let tableView: UITableView

Expand Down
9 changes: 7 additions & 2 deletions Sources/DataSources/Updating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,28 @@ extension UpdateContext: Sendable where Element: Sendable {
}


@MainActor
public protocol Updating: AnyObject {
public protocol Updating: ~Copyable, Sendable {

associatedtype Target
associatedtype Element

var target: Target { get }

@MainActor
func insertItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>)

@MainActor
func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>)

@MainActor
func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>)

@MainActor
func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext<Element>)

@MainActor
func performBatch(in context: UpdateContext<Element>, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void)

@MainActor
func reload(completion: @escaping () -> Void)
}

0 comments on commit ad662ac

Please sign in to comment.