This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var seneca = require('seneca')(); | |
seneca.use('./todo.js'); | |
seneca.act({role:'todo', cmd:'create', name:'Buy Milk'}, function(err, todo) { | |
console.log(todo); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var seneca = require('seneca')(); | |
seneca.use('./todo.js'); | |
seneca.listen({ type: 'tcp', pin: 'role:todo' }); // default port is 10101 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var seneca = require('seneca')(); | |
// seneca.use('./todo.js'); | |
seneca.client({ type: 'tcp', pin: 'role:todo' }); | |
seneca.act({role:'todo', cmd:'add', name:'Buy Milk'}, function(err, todo) { | |
console.log(todo); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SenecaWeb = require('seneca-web') | |
var express = require('express'); | |
var Router = express.Router; | |
var context = new Router(); | |
var senecaWebConfig = { | |
context: context, | |
adapter: require('seneca-web-adapter-express'), | |
options: { parseBody: false } // if you want to use body parser, put this in | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function api(options) { | |
var validActions = { add:'add' } | |
this.add('role:api,path:todo', function (msg, respond) { | |
var action = msg.args.params.action; | |
var todoText = msg.args.body.text; | |
this.act('role:todo', { | |
cmd: validActions[action], // do this to prevent injection attacks | |
text: text, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const io = require('socket.io-client'); | |
/** | |
* Forwards updates from a subclass of {@link UpdateEmitter} to a websocket | |
* @global | |
* @param {string} name - Name string to be send with each {@link UpdateEmitter#status} event | |
* @param {number} port - Websocket port to which to connect and forward events | |
* @param {UpdateEmitter} updateEmitter - Concrete subclass of {@link UpdateEmitter} | |
*/ | |
class WebsocketUpdater { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const EventEmitter = require('events'); | |
/** | |
* Subclass to add `started`, `progress` and `completed` functions. Then, just implement | |
* the `status` getter that returns an object describing the status of your object. Long | |
* running objects like {@link TMSExporter} subclass this class to send updates as they run. | |
* @interface | |
* @global | |
*/ | |
class UpdateEmitter extends EventEmitter { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example of one of our microservices - handles importing to Elasticsearch | |
class ESCollection extends UpdateEmitter { | |
get status() { | |
// should return a JSON object which is passed along with the websocket event | |
} | |
syncESWithCSV(csvName) { | |
this.started(); // emits 'started' event to any front-end listening for it | |
// do stuff to load CSV to Elasticsearch | |
this.progress(); // emits 'progress' event with the status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Partial Express.js API for accessing microservices from front end dashboard | |
// ... | |
app.get('/api/tmstocsv/info', (req, res) => { | |
seneca.act('role:tmstocsv,cmd:info').then((info) => { | |
res.json(info); | |
}); | |
}); | |
app.get('/api/tmstocsv/run', (req, res) => { | |
seneca.act('role:tmstocsv,cmd:run').then(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CodeMirror, copyright (c) by Marijn Haverbeke and others | |
// Distributed under an MIT license: http://codemirror.net/LICENSE | |
// Define search commands. Depends on dialog.js or another | |
// implementation of the openDialog method. | |
// Replace works a little oddly -- it will do the replace on the next | |
// Ctrl-G (or whatever is bound to findNext) press. You prevent a | |
// replace by making sure the match is no longer selected when hitting | |
// Ctrl-G. |