UNPKG

forwarder

Version:

Forwarding of messages to different objects (mostly properties of the receiver)

19 lines (17 loc) 555 B
_forward = exports.forward = (obj, message, {to, as, with: wth}) -> throw new TypeError("missing keyword arg to:") unless to as ?= message wth ?= [] target = obj[to] target = target.call obj if typeof target == typeof Function if as == '[]' obj[message] = (args...) -> args = wth.concat args target[args] else obj[message] = (args...) -> args = wth.concat args target[as].apply( target, args ) class exports.Forwarder forward: (message, {to, as, with: wth}) -> _forward @, message, {to, as, with: wth}