Last active
May 10, 2017 11:00
-
-
Save AndreyPanov/05346ada24a875e1d4ee12c013e60cc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Repository: Chainable { | |
var before: (()->())? | |
private let dataProdider: DataProvider | |
init(dataProdider: DataProvider = .init()) { | |
self.dataProdider = dataProdider | |
} | |
func getItem(onSuccess: @escaping (Item)->(), onError: @escaping (Error)->()) { | |
//background async request | |
dataProvider.request.items { [weak self] data, error in | |
self?.invoke() | |
if let item = ItemBuilder(with: data) { | |
onSuccess(item) | |
} else { | |
onError(error) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment