Skip to content

Instantly share code, notes, and snippets.

@jxson
Created June 16, 2014 23:22
Show Gist options
  • Save jxson/a39802d00ed04d1c36c1 to your computer and use it in GitHub Desktop.
Save jxson/a39802d00ed04d1c36c1 to your computer and use it in GitHub Desktop.
function submit(sink, data) {
if (!(this instanceof submit)) {
return new submit(sink, data)
}
this.sink = sink
this.data = data
this.id = sink.id
this.type = 'submit'
}
submit.prototype.handleEvent = function(event) {
var isValid = event.target.tagName === 'FORM' && event.type === 'submit'
if (! isValid) return;
event.preventDefault()
var values = serialize(event.currentTarget, { hash: true });
var data = extend(values, this.data);
if (typeof this.sink === 'function') {
this.sink(data)
} else {
this.sink.write(data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment