metarhia/swayer

Add sugar for events

Opened this issue · 0 comments

Support if-style

keyup(event) {
const value = this.props.value;
if (event.key === 'Enter' && value) {
todoCtrl.updateEditingTodo(todo, value);
this.emitCustomEvent('updateTitleEvent', todo);
this.blur();
} else if (event.key === 'Escape') {
this.blur();
}

but implement something like this:

keyup: {
  enter(event) {
    const value = this.props.value;
    if (value) {
      todoCtrl.updateEditingTodo(todo, value);
      this.emitCustomEvent('updateTitleEvent', todo);
      this.blur();
    }
  },
  escape() { 
    this.blur(); 
  }
}