Skip to content

Instantly share code, notes, and snippets.

@alexobenauer
Last active December 7, 2017 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexobenauer/987950387e58486ce08646d4730dde39 to your computer and use it in GitHub Desktop.
Save alexobenauer/987950387e58486ce08646d4730dde39 to your computer and use it in GitHub Desktop.
import Cocoa
class ViewController: NSViewController, StoreSubscriber {
@IBOutlet weak var counterLabel: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
store.subscribe(self)
}
@IBAction func userClickedPlus(_ sender: Any) {
store.dispatch(action: IncreaseAction(increaseBy: 1))
}
@IBAction func userClickedMinus(_ sender: Any) {
store.dispatch(action: DecreaseAction(decreaseBy: 1))
}
func newState(state: State) {
counterLabel.stringValue = "\((state as? AppState)?.counter ?? 0)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment