Skip to content

Instantly share code, notes, and snippets.

@Raynos

Raynos/x.js Secret

Created August 22, 2012 07:15
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/2f990fc882437fd358d5 to your computer and use it in GitHub Desktop.
Save Raynos/2f990fc882437fd358d5 to your computer and use it in GitHub Desktop.
var set = Set()
, sorted = sortable()
set.on("add", function (obj) {
var place = sorted.create()
, widget = Widget(obj, place)
widget.on("change", place.updateValue)
place.updateValue(widget.value())
})
function Widget(obj, place) {
var elem = makeElement()
, widget = new EventEmitter()
databind(elem, obj)
place.append(elem)
obj.on("end", function () {
place.destroy()
})
obj.on("changes", function (changes) {
if (changes.value) {
widget.emit("change", changes.value)
}
})
widget.value = function () {
return obj.get("value")
}
return widget
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment