Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature ImageManager for fetching image without using an image view #49

Merged
merged 4 commits into from
Jun 27, 2017

Conversation

zenangst
Copy link
Contributor

ImageManager can fetch images in the same way as the extension on
ImageView. It works pretty much in the exact same way except it does
not use any pre or post configuration closures. If the URL already
exists in the cache, that resource will be used by default, however you
can opt-out of using cache by setting useCache to false at the call
site.

Fetcher is now equitable, it is used to remove fetchers when they are
done doing their job in ImageManager.

This should not affect the current implementation of Imaginary as
ImageManager is completely separate from the image view extensions
that we had (and still have).

ImageManager can fetch images in the same way as the extension on
`ImageView`. It works pretty much in the exact same way except it does
not use any pre or post configuration closures. If the URL already
exists in the cache, that resource will be used by default, however you
can opt-out of using cache by setting `useCache` to `false` at the call
site.

`Fetcher` is now equitable, it is used to remove fetchers when they are
done doing their job in `ImageManager`.

This should not affect the current implementation of Imaginary as
`ImageManager` is completely separate from the image view extensions
that we had (and still have).
@mention-bot
Copy link

@zenangst, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vadymmarkov and @RamonGilabert to be potential reviewers.

}

// Cancel and remove all fetchers from `ImageManager`.
public func purge() {
Copy link
Contributor

Choose a reason for hiding this comment

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

purge sounds like clearing all the cache?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rick-morty-purge-1

@onmyway133
Copy link
Contributor

Look good to me, except the code duplication in Manager and ImageView+Imaginary

@zenangst
Copy link
Contributor Author

@onmyway133 yeah, I was thinking about refactoring the extensions to use the managers internally but that is a bit more work and I didn't want to tinker too much with what already works. If the manager ends up nicely I think it can replace that implementation. Meaning that it will run through like a shared manager for all the extensions. I think that way we might be able to drop the associated objects that we have now.

@zenangst
Copy link
Contributor Author

@vadymmarkov @onmyway133 what do you think about that idea?

@onmyway133
Copy link
Contributor

@zenangst yeah, I vote for that too. Then we have 1 place to change. I also vote for injecting a config object into fetch function, to avoid so many parameters

@vadymmarkov
Copy link
Contributor

I think it's fine to use manager internally because it's the same code.

@@ -96,4 +96,11 @@ class Fetcher {
closure()
}
}

static func == (lhs: Fetcher, rhs: Fetcher) -> Bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To remove the fetcher in the manager when they are done. I thought we need it to be equatable for us to use index(of:). Maybe we don't need that at all :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was right, we need it. If we don't add it then index(of) won't work.

/// - url: The URL of the image that should be fetch from the network.
/// - completion: A completion block that gets called after the network request is done.
/// - Note: The completion will get `nil` back if the request fails to fetch the image.
fileprivate func fetchFromNetwork(url: URL, useCache: Bool = true, completion: Completion? = nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be just private.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

@zenangst zenangst merged commit 377db84 into master Jun 27, 2017
@zenangst zenangst deleted the feature/image-manager branch June 27, 2017 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants