UNPKG

concern

Version:

A library for seperating your application logic into concerns.

111 lines (70 loc) 4.44 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: node/ProcessRouter.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: node/ProcessRouter.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>import beof from 'beof'; import Context from '../Context'; import Signal from '../Signal'; import RemoteMessage from '../RemoteMessage'; import ParentReference from './ParentReference'; /** * ProcessRouter is a class for treating the current process as a * system. * @param {Context} context */ class ProcessRouter { constructor(context) { beof({ context }).interface(Context); process.on('message', message => { var m; try { m = JSON.parse(message); assert.ok(typeof m === 'object'); } catch (e) { return context.publish(new InvalidMessageError(message, '')); } if (m.type === 'signal') { context.select(m.path).accept(new Signal[m.type](m.path), new ParentReference(process)); } else if (RemoteMessage.is(m)) { this._context.select(m.to).accept(m.body, new ParentReference(process)); } else { context.publish(new InvalidMessageError(m, '')); } }); ctx.on('generate', function(concern) { concern.watch(function(old, neu) { process.send(neu.toString()); }); }); } } export default ProcessRouter </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Active.html">Active</a></li><li><a href="Address.html">Address</a></li><li><a href="ChildActiveState.html">ChildActiveState</a></li><li><a href="ChildReference.html">ChildReference</a></li><li><a href="ChildReferenceProvider.html">ChildReferenceProvider</a></li><li><a href="ChildStateProvider.html">ChildStateProvider</a></li><li><a href="Envelope.html">Envelope</a></li><li><a href="IgnoredMessage.html">IgnoredMessage</a></li><li><a href="InvalidMessageError.html">InvalidMessageError</a></li><li><a href="MailDispatcher.html">MailDispatcher</a></li><li><a href="MemoryStateProvider.html">MemoryStateProvider</a></li><li><a href="ParentReference.html">ParentReference</a></li><li><a href="Pause.html">Pause</a></li><li><a href="Paused.html">Paused</a></li><li><a href="ProcessRouter.html">ProcessRouter</a></li><li><a href="Ready.html">Ready</a></li><li><a href="ReceiveError.html">ReceiveError</a></li><li><a href="Reference.html">Reference</a></li><li><a href="RefState.html">RefState</a></li><li><a href="RemoteMessage.html">RemoteMessage</a></li><li><a href="RemoteteTerminatedError.html">RemoteteTerminatedError</a></li><li><a href="Resume.html">Resume</a></li><li><a href="Signal.html">Signal</a></li><li><a href="SimpleMailBox.html">SimpleMailBox</a></li><li><a href="SpawnChildProcessError.html">SpawnChildProcessError</a></li><li><a href="Start.html">Start</a></li><li><a href="Stop.html">Stop</a></li><li><a href="Stopped.html">Stopped</a></li><li><a href="StoppedConcernError.html">StoppedConcernError</a></li><li><a href="System.html">System</a></li><li><a href="UnhandledMessage.html">UnhandledMessage</a></li><li><a href="Unknown.html">Unknown</a></li></ul><h3>Interfaces</h3><ul><li><a href="Concern.html">Concern</a></li><li><a href="Context.html">Context</a></li><li><a href="EnqueueListener.html">EnqueueListener</a></li><li><a href="MailBox.html">MailBox</a></li><li><a href="ReferenceProvider.html">ReferenceProvider</a></li><li><a href="StateProvider.html">StateProvider</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.0-dev</a> on Mon Sep 26 2016 02:55:49 GMT-0400 (AST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>