Skip to content

Instantly share code, notes, and snippets.

@isaldin
Last active June 21, 2016 13:23
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 isaldin/598e31785ba6999db71264782ee5f62e to your computer and use it in GitHub Desktop.
Save isaldin/598e31785ba6999db71264782ee5f62e to your computer and use it in GitHub Desktop.
AtomState template
extension State {
struct <STATE_NAME>: AtomState {
typealias EventType = Event
static var parentClass: AtomNode.Type = <#PARENT_CLASS_TYPE#>
static func react(optionalCurrent: <STATE_NAME>?, event: EventType) -> <STATE_NAME> {
guard var current = optionalCurrent else { return initial() }
switch event {
/// cases here
default:
break
}
return current
}
static func initial() -> <STATE_NAME> {
return <STATE_NAME>()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment