Last active
October 5, 2016 10:21
Revisions
-
Nicholas T revised this gist
Oct 5, 2016 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,32 @@ // Swift 3 protocol ActionType { } struct InitialAction: ActionType { } class Store<State> { var state: State! typealias Reducer = (State?, ActionType) -> State final let reducer: Reducer init(with reducer: @escaping Reducer) { self.reducer = reducer dispatch(InitialAction()) } typealias Subscriber = (Store) -> () final var subscribers = [Subscriber]() final func dispatch(_ action: ActionType) { self.state = reducer(state, action) subscribers.forEach { $0(self) } } final func subscribe(with subscriber: @escaping Subscriber) { subscribers.append(subscriber) subscriber(self) } } -
Nicholas T created this gist
Oct 5, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ // Swift 2 protocol ActionType { } struct InitialAction: ActionType { } class Store<State> { var state: State! typealias Reducer = (state: State?, action: ActionType) -> State final let reducer: Reducer init(with reducer: Reducer) { self.reducer = reducer dispatch(InitialAction()) } typealias Subscriber = (store: Store) -> () final var subscribers = [Subscriber]() final func dispatch(action: ActionType) { self.state = reducer(state: state, action: action) subscribers.forEach { $0(store: self) } } final func subscribe(with subscriber: Subscriber) { subscribers.append(subscriber) subscriber(store: self) } }