Skip to content

Instantly share code, notes, and snippets.

@amberstar
Last active May 16, 2016 08:54
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 amberstar/c851430c7d810642e2c860c6eddfda5e to your computer and use it in GitHub Desktop.
Save amberstar/c851430c7d810642e2c860c6eddfda5e to your computer and use it in GitHub Desktop.
// events
public struct ComponentEvents {
public var appEvent = Port<(component: Component, event: EventType)>()
}
subcomponent.events.appEvent.subscribe { component, event in
self.applicationEvent(component, event: event)
}
func applicationEvent(component: Component, event: Event) {
switch event.type {
case .HandledEvent(let isOn):
state.setState = isOn
case .HandledEvent2 :
// handle event 2
default:
// send unhandled event up to parent component
event.send(component: component, event: event.type)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment