Created
March 11, 2013 03:21
-
-
Save Raynos/5131676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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