Created
January 7, 2017 19:20
-
-
Save bsneed/02128edf08f4e66da9157ad38751c68a to your computer and use it in GitHub Desktop.
Less high level....
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 struct MessagesState: State, HasMessagesUnread, HasMessagesRead { | |
public var unreadCount: UInt = 0 | |
public var messages = [String]() | |
public var outbound = [String]() | |
public var sentCount: UInt = 0 | |
public var readCount: UInt = 0 | |
} | |
// supported state manipulation protocols. | |
public protocol HasMessagesUnread: State { | |
var unreadCount: UInt { get set } | |
} | |
public protocol HasMessagesRead: State { | |
var readCount: UInt { get set } | |
} | |
// ..... | |
class MyController: Subscriber { | |
let store = Store(state: MessagesState(), reducer: MessagesReducer()) | |
func doShit() { | |
store.subscribe(self) { (state: HasMessagesUnread) in | |
print("handling \(HasMessagesUnread.self)") | |
print("unread, value = \(state.unreadCount)\n") | |
} | |
store.subscribe(self) { (state: HasMessagesRead) in | |
print("handling \(HasMessagesRead.self)") | |
print("read, value = \(state.readCount)\n") | |
} | |
store.subscribe(self) { (state: MessagesState) in | |
print("handling \(MessagesState.self)") | |
print("unread, value = \(state.unreadCount)") | |
print("read, value = \(state.readCount)\n") | |
} | |
//let action1 = UpdateUnreadAction(value: 18) | |
//store.dispatch(action1) | |
/* | |
This should hit the HasMessagesRead subscriber, as well as the | |
MessagesState subscriber since the latter subscribes/implements the former. | |
*/ | |
let action2 = UpdateReadAction(value: 42) | |
store.dispatch(action2) | |
//let action3 = UpdateEverythingAction(unread: 1, read: 1) | |
//store.dispatch(action3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment