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
| enum Event { | |
| case addTodo(Todo) | |
| case toggleTodo(Todo) | |
| case setVisibilityFilter(VisibilityFilter) | |
| } |
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 reduce(state: State, event: Event) -> State { | |
| switch event { | |
| case .addTodo(let todo): | |
| var newState = state | |
| newState.todos = state.todos + [todo] | |
| return newState | |
| case .toggleTodo(let todo): | |
| var newState = state | |
| newState.todos = state.todos.map { t in | |
| var newTodo = t |
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 loginWithFacebook() -> AsyncResult<Context, String, GenericError> { | |
| return AsyncResult.unfoldTT{ context, continuation in | |
| let loginManager = LoginManager() | |
| loginManager.logIn([ .publicProfile ], viewController: self) { loginResult in | |
| switch loginResult { | |
| case .Failed(let error): | |
| continuation(Result.failure(error)) | |
| case .Cancelled: | |
| continuation(Result.failure(LoginCancelledError())) | |
| case .Success(let grantedPermissions, let declinedPermissions, let accessToken): |
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
| enum Event { | |
| case addTodo(Todo) | |
| case toggleTodo(Todo) | |
| case setVisibilityFilter(VisibilityFilter) | |
| case storeTodos() | |
| case todosStored(Bool) | |
| } | |
| struct State { | |
| var todos: [Todo] |
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
| class CounterViewController: UIViewController { | |
| @IBOutlet weak var label: UILabel? | |
| @IBOutlet weak var minus: UIButton? | |
| @IBOutlet weak var plus: UIButton? | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| typealias State = Int |
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
| protocol BaseContext { | |
| var cloudKitApiKey: String {get} | |
| var todosDataSource: TodosDataSource {get} | |
| } | |
| class AppContext: BaseContext { | |
| var cloudKitApiKey = "sjsfAJ&76sdgjhs3434JHS3" | |
| var todosDataSource: TodosDataSource = TodosCloudKitDataSource() | |
| } | |
| class TodosListContext: AppContext { |
OlderNewer