1 Star 6 Fork 0

潘韬 / getting-started-seneca

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sum.js 777 Bytes
一键复制 编辑 原始数据 按行查看 历史
潘韬 提交于 2017-01-05 09:07 . 添加 sum.js
const seneca = require('seneca')();
/**
* `seneca.add` 方法,添加了一个新的动作模式(*Action Pattern*)至 `Seneca` 实例中,
* 它有两个参数:
*
* 1. `pattern` :用于匹配 Seneca 实例中 `JSON` 消息体的模式;
* 2. `action` :当模式被匹配时执行的操作
*/
seneca.add('role:math, cmd:sum', (msg, reply) => {
reply(null, { answer: ( msg.left + msg.right )})
});
/**
* `seneca.act` 方法同样有两个参数:
*
* 1. `msg` :作为纯对象提供的待匹配的入站消息;
* 2. `respond` :用于接收并处理响应信息的回调函数。
*/
seneca.act({
role: 'math',
cmd: 'sum',
left: 1,
right: 2
}, (err, result) => {
if (err) {
return console.error(err);
}
console.log(result);
});
JavaScript
1
https://gitee.com/pantao/getting-started-seneca.git
git@gitee.com:pantao/getting-started-seneca.git
pantao
getting-started-seneca
getting-started-seneca
master

搜索帮助