npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

truflux-state-msg

v2.1.0

Published

A stateful based messaging protocol for truflux

Downloads

10

Readme

Truflux State Message

To install

npm install --save truflux-state-msg

The truflux message definition is designed to be separate from the actual messaging system to allow you to separate protocol from implementation.This messaging module contains internal mechanisms for managing message state when using truflux.

New in v2.0.0

To provide better decoupling, truflux-state-msg now no longer supports the enforce Schema methods any more, which have been moved to a separate module, truflux-msg-schema. The prebuilt browser versions have removed to allow one to include their own specialized build if need be

Example

The following example is adapted from the stateless truflux-msg protocol definition module.It is suggested that you try out truflux-msg before moving on to using truflux-state-msg

//In your protocol definition file lets call it protocol.js
var TrufluxStateMessage = require('truflux-state-msg'),
    protocol            = new TrufluxStateMessage();

protocol.add('provideUsername')
        .add('providePassword')
        .add('login')
        .add('somethingOnlyOnce');

//login may only be called once the provideUsername and providePassword messages have been called before hand 
protocol.depend('login',['provideUsername','providePassword']);

//Will make sure this message will only be called once, otherwise an error will be emitted
protocol.singleton('somethingOnlyOnce');

module.exports = protocol;

To show you how to deal with protocol errors see the following example

    protocol.onUnimplemented     = function(identifier,socket)
    {
        console.log('Whoops, forgot to specify '+identifier);
    };
    protocol.onMultipleSingleton = function(messageID,socket)
    {
        console.log('Message : '+protocol.getMessageName(messageID)+'has been called more than once');
    }; 
    protocol.onMultipleSingleton = function(messageID,dependancyID,socket)
    {
        console.log('Message : '+protocol.getMessageName(messageID)+'has not had dependancy fulfilled : '+protocol.getMessageName(dependancyID));
    };

API

The preferred method of accessing the integer value of a message is to use msgObjectInstance.id.identifierName , this can be used to obtain values for has and call if needed

Constructor(options)

/**
 * Creates a new TrufluxMessage
 * @param {Object}  [options] 
 * @param {Boolean} [options.noThrow] If true, we will not throw an error for unimplemented functions for "add" 
 */

add(identifier,[func])

/**
 * Adds a function handler for the provided string
 * @param  {String} identifier 
 * @param  {Function} [func]  function(data,socket)   
 * @return {TrufluxMessage}    
 */

specify(identifier,func)

/**
 * Specifies the function to be used for the provided identifier. Used to override add
 * @param  {String|Number} identifier 
 * @param  {Function} func function(data,socket)       
 * @return {TrufluxMessage}            
 */

call(id,payload,socket)

/**
 * Calls the handler associated with the message ID. NOTE This will throw an error if there is no 
 * handler associated. It is assumed you have called "has" before hand
 * @param  {Number} id      
 * @param  {Any} payload 
 * @param  {TrufluxSocket} socket
 * @return {TrufluxMessage}   
 */

has(messageID)

/**
 * Checks to see if it has the specified message handler
 * @param  {Number}  messageID 
 * @return {Boolean}       
 */

singleton(identifier)

/**
 * Makes a specified message a singleton
 * @param  {String|Number} identifier 
 * @return {TrufluxMessage}            
 */

depend(dependant,prerequisites)

/**
 * Makes a function depend on previous functions having been called
 * @param  {String|Number} dependant  
 * @param  {String|Array}  prerequisites The string identifiers of the messages that must be called before this
 * @return {TrufluxMessage}            
 */

changeMessageID(oldId,newID)

/**
 * Changes the ID of a message handler. Ideal if you need to make sure that the ID has a certain value 
 * @param  {Number|String} oldId The old identifer of the handler
 * @param  {Number} newID  The new ID value 
 * @throws {Error } If the newID is already taken
 * @return {TrufluxMessage}       
 */

Instance properties

/**
 * Called when a message handler has recieved a message but was unimplemented
 * @property {Function} onUnimplemented 
 */

/**
 * Called when a message handler has recieved a message but has unsatisfied dependancies 
 * @property {Function} onUnsatisfiedDependancy 
 */

/**
 * Called when a message handler has recieved a message and was a singleton, but has been called more than once
 * @property {Function} onMultipleSingleton 
 */