Home Reference Source Repository

es6/utils/Expressive.js

import debug        from 'debug'
import EventEmitter from 'eventemitter2'

/**
 * @class Expressive
 */
export default class Expressive extends EventEmitter {
  /**
   * creates a new inherited instance
   */
  static create () {
    return new this(...arguments)
  }
  
  /**
   * returns a new `this`
   */
  constructor () {
    super({
      wildcard: true
    })
    this.debug = debug(`wyst:${this.constructor.name}`)
  }

  /**
   * expressive emit
   *
   * @param      {string}  state   The state
   */
  is (state) {
    this.emit(state, this)
    return this
  }

  /**
   * expressive once
   */
  when () {
    this.once(...arguments)
    return this
  }
}