Created
February 19, 2017 13:34
-
-
Save srdanrasic/0992da0e0d641538b6b0a8c9f9f08d58 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class RecipeList { | |
| public let sortDescriptor: SafeObserver<SortDescriptor> | |
| public let recipes: SafeSignal<[Recipe]> | |
| public init(client: SafeClient, category: Category) { | |
| let recipes = client | |
| .response(for: API.Recipe.all(category: category)) | |
| .shareReplay(limit: 1) | |
| let sortDescriptor = SafePublishSubject<SortDescriptor>() | |
| self.recipes = sortDescriptor | |
| .flatMapLatest { sortDescriptor in | |
| return recipes.map { $0.sort(by: sortDescriptor) } | |
| } | |
| .shareReplay(limit: 1) | |
| self.sortDescriptor = sortDescriptor.toObserver() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment