Skip to content

Instantly share code, notes, and snippets.

@mamiu
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save mamiu/00945368e8e37ecad63e to your computer and use it in GitHub Desktop.

Select an option

Save mamiu/00945368e8e37ecad63e to your computer and use it in GitHub Desktop.
EventEmitter sample for Lornez ;)
var contactForm = function(){
EventEmitter.call(this);
var submit = function(email, name, message){
this.emit("submitContactForm", email, name, message);
}
var validateForm = function(email, name, message){
//check if all required fields are filled and the text is valid (no attacks)
this.emit("validated", email, name, message);
}
var sendContent = function(email, name, message){
//try to send the form content
this.emit("contentSent", email, name, message);
}
var showInfo(){
//open dialog box with success message or replace form with thanks text^^
this.emit("submitSuccessfull", "The Content was sent successfully");
}
this.on("submitContactForm", validateForm);
this.on("validated", sendContent);
this.on("contentSend", showInfo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment