Skip to content

Instantly share code, notes, and snippets.

@Raynos

Raynos/x.js Secret

Created August 22, 2012 06:40
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/c664833ae7b56ab48534 to your computer and use it in GitHub Desktop.
Save Raynos/c664833ae7b56ab48534 to your computer and use it in GitHub Desktop.
function selectron() {
var sel = new EventEmitter()
, selected
sel.select = select
sel.unselect = unselect
return sel
function select(thing) {
unselect()
selected = thing
selected.select()
sel.emit("select", selected)
}
function unselect() {
if (selected) {
selected.unselect()
}
sel.emit("unselect", selected)
selected = null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment