tart-behaving

0.1.0 • Public • Published

tart-behaving

Stability: 1 - Experimental

NPM version

Behaving configuration implementation for Tiny Actor Run-Time in JavaScript that actors can send messages to.

Contributors

@dalnefre, @tristanls

Overview

Behaving configuration implementation for Tiny Actor Run-Time in JavaScript that actors can send messages to.

Usage

To run the below example run:

npm run readme
"use strict";
 
var tart = require('../index.js');
 
var oneTimeLogBeh = function oneTimeLogBeh(message) {
    console.log('[logger]', message);
    this.behavior = function ignore(message) {};
};
 
var sponsor = tart.behaving({behavior: oneTimeLogBeh});
 
var someBeh = function someBeh(message) {
    var timestamp = new Date().getTime();
    this.config(timestamp);
    this.config(timestamp);
    message.customer('hi');
};
 
var customerBeh = function customerBeh(message) {
    console.log('customer:', message);
};
 
var actor = sponsor(someBeh);
var customer = sponsor(customerBeh);
 
actor({customer: customer});

Tests

npm test

Documentation

Public API

tart.behaving([options])

  • options: Object (Default: undefined) Optional overrides.
    • behavior: Function (Default: function (message) {}) function (message) {} Configuration behavior to invoke every time a message is sent to the configuration via this.config(message).
    • constructConfig: Function (Default: function (options) {}) function (options) {} Configuration creation function that is given options. It should return a capability function (behavior) {} to create new actors.
    • deliver: Function (Default: function (context, message, options) {}) function (context, message, options) {} Deliver function that returns a function for dispatch to dispatch.
    • dispatch: Function (Default: setImmediate) function (deliver) {} Dispatch function for dispatching deliver closures.
    • fail: Function (Default: function (exception) {}) function (exception) {} An optional handler to call if a sponsored actor behavior throws an exception.

Creates a sponsor capability to create new actors with and allows replacing parts of the implementation. It is implemented on top of TartJS Pluggable API.

sponsor(behavior)

Same as the core TartJS Minimal implementation. See: sponsor(behavior)

actor(message)

Same as the core TartJS Minimal implementation. See: actor(message)

Sources

Package Sidebar

Install

npm i tart-behaving

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • tristanls