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
| func setupNavigationBackAction() { | |
| self.navigationItem.hidesBackButton = true | |
| var customBackButton = UIBarButtonItem(title: "Back", style: .done, | |
| target: nil, action: nil) | |
| customBackButton.rx.action = viewModel.backAction() | |
| self.navigationItem.leftBarButtonItem = customBackButton | |
| } |
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
| import UIKit | |
| import RxSwift | |
| import ReSwift | |
| class CharacterFavoriteView: FavoriteView, StoreSubscriber { | |
| var character: Character? | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) |
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
| import ReSwift | |
| struct FetchedCharactersReducer: Reducer { | |
| let apiManager: MarvelAPICalls | |
| func handleAction(action: Action, state: FetchedCharactersState?) -> FetchedCharactersState { | |
| switch action { | |
| case let action as FetchCharactersAction: | |
| fetchCharacters(query: action.query) |
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
| import ReSwift | |
| struct FavoriteReducer: Reducer { | |
| func handleAction(action: Action, state: FavoritesState?) -> FavoritesState { | |
| let realmManager = RealmManager() | |
| switch action { | |
| case let action as FavoriteAction: | |
| realmManager.favorite(character: action.character) | |
| case let action as UnfavoriteAction: | |
| realmManager.unfavorite(character: action.character) |
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
| import ReSwift | |
| struct AppReducer: Reducer { | |
| let apiManager = MarvelAPIManager() | |
| func handleAction(action: Action, state: AppState?) -> AppState { | |
| return AppState( | |
| favoritesState: FavoriteReducer().handleAction(action: action, state: state?.favoritesState), | |
| fetchedCharactersState: FetchedCharactersReducer(apiManager: apiManager) | |
| .handleAction(action: action, state: state?.fetchedCharactersState) |
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
| import ReSwift | |
| struct FavoriteAction: Action { | |
| let character: Character | |
| } | |
| struct UnfavoriteAction: Action { | |
| let character: Character | |
| } |
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
| import UIKit | |
| import ReSwift | |
| let store = Store<AppState>(reducer: AppReducer(), state: nil) | |
| @UIApplicationMain | |
| class AppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? |
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
| import Foundation | |
| import ReSwift | |
| struct AppState: StateType { | |
| var favoritesState: FavoritesState | |
| var fetchedCharactersState: FetchedCharactersState | |
| } | |
| struct FavoritesState: StateType { | |
| var favorites: [FavoriteCharacter] = [] |
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
| import RealmSwift | |
| import RxSwift | |
| import RxRealm | |
| class FavoriteCharacter: Object { | |
| dynamic var id = 0 | |
| dynamic var isFavorite = true | |
| convenience init(character: Character) { | |
| self.init() |
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
| import RxSwift | |
| class CharacterFavoriteView: FavoriteView { | |
| var disposeBag: DisposeBag? | |
| let realmManager = RealmManager() | |
| var character: Character? | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) |