wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
266 stars 109 forks source link

Ability to use `FetchOperation` directly. #96

Closed markst closed 7 years ago

markst commented 8 years ago

We'd like to be able to use FetchOperation directly, to enable us to cancel previous operations.

//Cancel previous operation
self.operation.cancel()

//
self.operation = FetchOperation(query: query, spine: self)
self.operation.completionBlock = { [unowned operation] in
....
self.operation.start()
wvteijlingen commented 8 years ago

I think it's better to keep the operation itself an implementation detail. Making it a public API will make it much harder to refactor inner workings if needed. Luckily the FetchOperation class is pretty simple, so it should be easy for you to create your own NSOperation subclass that does the work.

markst commented 7 years ago

Thanks for response @wvteijlingen.

I'm in the process of having to create my own operation. It would be good to be able to subclass from ConcurrentOperation, however this doesn't seem to be possible due to: image

Even if subclassing from NSOperation it would be good if Spine's Failable was public also.

Another one is exposing the Spine router since I can't do something like this on my operation without making a new Router:

/// Convenience variables that proxy to their spine counterpart
var router: Router {
    return spine.router
}