Last active
December 28, 2015 20:39
-
-
Save auramo/7558691 to your computer and use it in GitHub Desktop.
textFieldValue based on event delegation
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
function textFieldValue(parentElement, inputFieldSelector) { | |
return parentElement.asEventStream("keyup input").filter(isNotEnter). | |
merge(parentElement.asEventStream("cut paste").delay(1)). | |
merge(autofillPoller()). | |
map(getValue).toProperty(getValue()).skipDuplicates(); | |
function getValue() { | |
var inputField = parentElement.find(inputFieldSelector) | |
return _.isEmpty(inputField) ? "" : inputField.val(); | |
} | |
function autofillPoller() { | |
return Bacon.interval(100).take(20).map(getValue).filter(nonEmpty).take(1); | |
} | |
function nonEmpty(x) { return x && x.length > 0; } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment