diff --git a/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift b/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift index 04c3f27..5ae0da3 100644 --- a/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift +++ b/Sources/KarrotListKit/Adapter/CollectionViewAdapter.swift @@ -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) } } } diff --git a/Sources/KarrotListKit/Prefetching/CollectionViewPrefetchingPlugin.swift b/Sources/KarrotListKit/Prefetching/CollectionViewPrefetchingPlugin.swift deleted file mode 100644 index 524b264..0000000 --- a/Sources/KarrotListKit/Prefetching/CollectionViewPrefetchingPlugin.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright (c) 2024 Danggeun Market Inc. -// - -import Combine -import Foundation - -public protocol ComponentPrefetchable {} - -public protocol RemoteImagePrefetchable: ComponentPrefetchable { - var remoteImageURLs: [URL] { get } -} - -public protocol CollectionViewPrefetchingPlugin { - func prefetch(dataSource: ComponentPrefetchable) -> AnyCancellable? -} diff --git a/Sources/KarrotListKit/Prefetching/Plugins/CollectionViewPrefetchingPlugin.swift b/Sources/KarrotListKit/Prefetching/Plugins/CollectionViewPrefetchingPlugin.swift new file mode 100644 index 0000000..7ccf438 --- /dev/null +++ b/Sources/KarrotListKit/Prefetching/Plugins/CollectionViewPrefetchingPlugin.swift @@ -0,0 +1,10 @@ +// +// Copyright (c) 2024 Danggeun Market Inc. +// + +import Combine +import Foundation + +public protocol CollectionViewPrefetchingPlugin { + func prefetch(with component: ComponentResourcePrefetchable) -> AnyCancellable? +} diff --git a/Sources/KarrotListKit/Prefetching/RemoteImagePrefetchingPlugin.swift b/Sources/KarrotListKit/Prefetching/Plugins/RemoteImagePrefetchingPlugin.swift similarity index 72% rename from Sources/KarrotListKit/Prefetching/RemoteImagePrefetchingPlugin.swift rename to Sources/KarrotListKit/Prefetching/Plugins/RemoteImagePrefetchingPlugin.swift index acdcd08..b190275 100644 --- a/Sources/KarrotListKit/Prefetching/RemoteImagePrefetchingPlugin.swift +++ b/Sources/KarrotListKit/Prefetching/Plugins/RemoteImagePrefetchingPlugin.swift @@ -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) } @@ -29,4 +29,3 @@ public final class RemoteImagePrefetchingPlugin: CollectionViewPrefetchingPlugin } } } - diff --git a/Sources/KarrotListKit/Prefetching/PrefetchableComponent.swift b/Sources/KarrotListKit/Prefetching/PrefetchableComponent.swift new file mode 100644 index 0000000..8e44e48 --- /dev/null +++ b/Sources/KarrotListKit/Prefetching/PrefetchableComponent.swift @@ -0,0 +1,11 @@ +// +// Copyright (c) 2024 Danggeun Market Inc. +// + +import Foundation + +public protocol ComponentResourcePrefetchable {} + +public protocol ComponentRemoteImagePrefetchable: ComponentResourcePrefetchable { + var remoteImageURLs: [URL] { get } +}