spur-common
Version:
Common node library that is implemented through the use of spur-ioc and bluebird promises.
39 lines (28 loc) • 987 B
text/coffeescript
module.exports = (_, console)->
class BaseDelegate
supportsMethods:()->
for methodName in
do(methodName) =>
@[methodName] = (args...)=>
(methodName, args)
()
callDelegate:(methodName, args)->
_.each , (delegate)=>
if _.isFunction(delegate[methodName])
delegate[methodName].apply(delegate, args)
else if _.isFunction(delegate)
delegate.call(@,methodName, args)
useNoop:()->
= []
useConsole:()->
= []
consoleDelegate:(methodName, args)=>
prefix = .name + "##{methodName}: "
console.log.apply(console, [prefix].concat(args))
useRecorder:()->
= []
recorderDelegate:(methodName, args)=>
?= {}
([methodName] ?= []).push(args)
use:(delegate)=>
= [delegate]