mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-08-14 20:41:01 +01:00
Finish HackMyCore reshaping.
Reintroduce HackMyCore, dropping the interim submodule, and reorganize and improve tests.
This commit is contained in:
71
src/verbs/verb.coffee
Normal file
71
src/verbs/verb.coffee
Normal file
@@ -0,0 +1,71 @@
|
||||
###*
|
||||
Definition of the Verb class.
|
||||
@module verbs/verb
|
||||
@license MIT. See LICENSE.md for details.
|
||||
###
|
||||
|
||||
|
||||
|
||||
|
||||
# Use J. Resig's nifty class implementation
|
||||
Class = require '../utils/class'
|
||||
EVENTS = require 'events'
|
||||
|
||||
|
||||
|
||||
###*
|
||||
An instantiation of a HackMyResume command.
|
||||
@class Verb
|
||||
###
|
||||
Verb = module.exports = Class.extend
|
||||
|
||||
|
||||
|
||||
###* Constructor. Automatically called at creation. ###
|
||||
init: ( moniker ) ->
|
||||
@.moniker = moniker
|
||||
@.emitter = new EVENTS.EventEmitter()
|
||||
return
|
||||
|
||||
|
||||
|
||||
###* Forward subscriptions to the event emitter. ###
|
||||
on: ->
|
||||
this.emitter.on.apply @.emitter, arguments
|
||||
|
||||
|
||||
|
||||
###* Fire an arbitrary event, scoped to "hmr:". ###
|
||||
fire: (evtName, payload) ->
|
||||
payload = payload || { }
|
||||
payload.cmd = this.moniker
|
||||
this.emitter.emit 'hmr:' + evtName, payload
|
||||
true
|
||||
|
||||
|
||||
|
||||
###* Handle an error condition. ###
|
||||
err: ( errorCode, payload, hot ) ->
|
||||
payload = payload || { }
|
||||
payload.sub = payload.fluenterror = errorCode
|
||||
payload.throw = hot
|
||||
this.fire 'error', payload
|
||||
if hot
|
||||
throw payload
|
||||
true
|
||||
|
||||
|
||||
|
||||
###* Fire the 'hmr:status' error event. ###
|
||||
stat: ( subEvent, payload ) ->
|
||||
payload = payload || { }
|
||||
payload.sub = subEvent
|
||||
this.fire 'status', payload
|
||||
true
|
||||
|
||||
|
||||
###* Associate error info with the invocation. ###
|
||||
setError: ( code, obj ) ->
|
||||
@errorCode = code
|
||||
@errorObj = obj
|
||||
return
|
Reference in New Issue
Block a user