Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created March 11, 2013 03:21
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/5131676 to your computer and use it in GitHub Desktop.
Save Raynos/5131676 to your computer and use it in GitHub Desktop.
var observable = require("observable")
function input(elem) {
var o = observable()
o(elem.value)
elem.addEventListener("change", function () { o(elem.value) })
return o
}
var i = input(document.getElementById('some-input')
i('actually setting value. naughty naughty')
var signal = require("observable/signal")
function input(elem) {
// signal takes callback in which you have lexical access
// to the value setting function
// It also takes initial value for convenience
return signal(function (setValue) {
elem.addEventListener("change", function () { setValue(elem.value) })
}, elem.value)
}
var i = input(document.getElementById('some-input')
// THIS NOW THROWS EXCEPTION
i('actually setting value. naughty naughty')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment