import { EventSchema, JSFunction, EventModifier } from '../types';
import { Node } from './Node';

export class Event {
  handler: JSFunction;
  modifiers: EventModifier[] = [];
  params: string[] = [];
  constructor(public owner: Node, scheam: EventSchema) {
    const { handler, modifiers = [], params = [] } = scheam;
    this.handler = handler;
    this.modifiers = modifiers;
    this.params = params;
  }
  update(scheam: EventSchema) {
    const { handler, modifiers, params } = scheam;
    if (handler) {
      this.handler = handler;
    }

    if (modifiers) {
      this.modifiers = modifiers;
    }

    if (params) {
      this.params = params;
    }
  }
  getSchema() {
    const { handler, modifiers, params } = this;
    return {
      handler,
      modifiers,
      params
    };
  }
}
