Skip to content

Commit

Permalink
Merge pull request #9 from daangn/feature/ray/prefetchable-component
Browse files Browse the repository at this point in the history
NO-JIRA `ComponentPrefetchable` 네이밍을 변경해요
  • Loading branch information
OhKanghoon authored Feb 5, 2024
2 parents 4ccb20f + a575d91 commit 86f336e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ extension CollectionViewAdapter: UICollectionViewDataSourcePrefetching {
}

guard let item = item(at: indexPath),
let dataSource = item.component.as(ComponentPrefetchable.self)
let prefetchableComponent = item.component.as(ComponentResourcePrefetchable.self)
else {
continue
}

prefetchingIndexPathOperations[indexPath] = prefetchingPlugins.compactMap {
$0.prefetch(dataSource: dataSource)
$0.prefetch(with: prefetchableComponent)
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Copyright (c) 2024 Danggeun Market Inc.
//

import Combine
import Foundation

public protocol CollectionViewPrefetchingPlugin {
func prefetch(with component: ComponentResourcePrefetchable) -> AnyCancellable?
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public final class RemoteImagePrefetchingPlugin: CollectionViewPrefetchingPlugin
self.remoteImagePrefetcher = remoteImagePrefetcher
}

public func prefetch(dataSource: ComponentPrefetchable) -> AnyCancellable? {
guard let dataSource = dataSource as? RemoteImagePrefetchable else {
public func prefetch(with component: ComponentResourcePrefetchable) -> AnyCancellable? {
guard let component = component as? ComponentRemoteImagePrefetchable else {
return nil
}

let uuids = dataSource.remoteImageURLs.compactMap {
let uuids = component.remoteImageURLs.compactMap {
remoteImagePrefetcher.prefetchImage(url: $0)
}

Expand All @@ -29,4 +29,3 @@ public final class RemoteImagePrefetchingPlugin: CollectionViewPrefetchingPlugin
}
}
}

11 changes: 11 additions & 0 deletions Sources/KarrotListKit/Prefetching/PrefetchableComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Copyright (c) 2024 Danggeun Market Inc.
//

import Foundation

public protocol ComponentResourcePrefetchable {}

public protocol ComponentRemoteImagePrefetchable: ComponentResourcePrefetchable {
var remoteImageURLs: [URL] { get }
}

0 comments on commit 86f336e

Please sign in to comment.