Skip to content

Instantly share code, notes, and snippets.

@auramo
Last active December 28, 2015 20:39
Show Gist options
  • Save auramo/7558691 to your computer and use it in GitHub Desktop.
Save auramo/7558691 to your computer and use it in GitHub Desktop.
textFieldValue based on event delegation
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