Skip to content

Commit

Permalink
translate
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed May 26, 2018
1 parent 4841a9c commit b6d477b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ var errlog = Common.make_standard_err_log_entry

var intern = {}


exports.translate = function(from_in, to_in) {
var from = 'string' === typeof(from_in) ? Jsonic(from_in) : from_in
var to = 'string' === typeof(to_in) ? Jsonic(to_in) : to_in
this.add(from, function(msg, reply) {
var transmsg = Object.assign(this.util.clean(msg),to)
this.act(transmsg,reply)
})
return this
}

exports.test = function test(errhandler, logspec) {
var opts = this.options()

Expand Down Expand Up @@ -250,8 +261,6 @@ exports.client = function(callpoint) {
'role:transport,cmd:client',
{ config: config, gate$: true },
function(err, liveclient) {
//console.log(this.id,'CL RES',err,liveclient)

if (err) {
return sd.die(private$.error(err, 'transport_client', config))
}
Expand Down
6 changes: 6 additions & 0 deletions seneca.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ function make_seneca(initial_options) {
root$.gate = API.gate // Create a delegate that executes actions in sequence.
root$.ungate = API.ungate // Execute actions in parallel.
root$.test = API.test // Set test mode.
root$.translate = API.translate // Set test mode.

root$.add = api_add // Add a pattern an associated action.
root$.act = api_act // Submit a message and trigger the associated action.
Expand Down Expand Up @@ -1384,6 +1385,7 @@ intern.handle_inward_break = function(
intern.make_actmsg = function(origmsg) {
var actmsg = Object.assign({}, origmsg)


if (actmsg.id$) {
delete actmsg.id$
}
Expand All @@ -1396,6 +1398,10 @@ intern.make_actmsg = function(origmsg) {
delete actmsg.meta$
}

if (actmsg.prior$) {
delete actmsg.prior$
}

// backwards compatibility for Seneca 3.x transports
if (origmsg.transport$) {
actmsg.transport$ = origmsg.transport$
Expand Down

0 comments on commit b6d477b

Please sign in to comment.