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

allow custom processor through init #197

Merged
merged 1 commit into from
Oct 15, 2018
Merged

Conversation

drkibitz
Copy link
Contributor

  • This allows shared custom processors to be provided rather than depending only on factory methods of image requests

e.g.

let imageRequest = ImageRequest(url: url, processor: MyProccessor.shared)

I also added tests for this and my previous pull request for upscaling.

@kean
Copy link
Owner

kean commented Oct 14, 2018

Hey, @drkibitz! Thanks, I think it makes sense to add a convenience initializer like that.

I would suggest making this init generic to hide AnyImageProcessor (it exists because of the Swift limitations):

public init<Processor: ImageProcessing>(urlRequest: URLRequest, processor: Processor) {
        self = ImageRequest(urlRequest: urlRequest)
        self.processor = AnyImageProcessor(processor)
 }

@kean
Copy link
Owner

kean commented Oct 14, 2018

// Convenience initializers with custom processer. The reason
// why those are implemented as separate init methods is to take advantage
// of memorized `decompressor` when custom parameters are not needed.

I'm not sure I follow, could you please clarify what you meant by this comment? I don't see how these new initializes allow you to do something that the existing ones don't.

@drkibitz
Copy link
Contributor Author

@kean That comment was taken from what was already there, changing "Convenience initializers with targetSize and contentMode." to "Convenience initializers with custom processer.". I didn't mean anything by the comment other than just trying to repeat the pattern of the previous comment but for the custom processor parameter.

- This allows shared custom processors to be provided rather than depending only on factory methods of image requests
@drkibitz
Copy link
Contributor Author

@kean Out of curiosity, what are you gaining by making the image processor objects in this library structs?

@drkibitz
Copy link
Contributor Author

@kean also, FYI, I've updated the PR hopefully to your liking. I've taken a little liberty on the comment(s), and the init calling pattern.

@kean
Copy link
Owner

kean commented Oct 15, 2018

Oh, right, there is an existing comment like that 😄. I will take a look, not sure why I thought it was necessary, seems outdated. It's there just for convenience and to make API for resizing images - which is a common operation - easier to find and use.

Out of curiosity, what are you gaining by making the image processor objects in this library structs?

AFAIR to reduce the number of allocations and deallocations, that's it.

@kean kean merged commit 7ebfcf0 into kean:master Oct 15, 2018
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.

2 participants