Skip to content

Instantly share code, notes, and snippets.

@Raynos

Raynos/event.js Secret

Created April 17, 2013 00:06
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 Raynos/ff5032d26649fb3e51dd to your computer and use it in GitHub Desktop.
Save Raynos/ff5032d26649fb3e51dd to your computer and use it in GitHub Desktop.
// Minimal events
// type Listener := (value: Value) => void
// type Cancel := () => void
// type Event := (listener: Listener) => Cancel
// someEvent := Event<T>
function someEvent(listener) {
// notify listener when an event has occured
// want to signal completion? Invoke listener(Event.Completed)
// want to signal rejection? Invoke listener(new Error(reason))
return function cancel() {
// remove listener from notification list.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment