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

@vcomm/asmgraph

v1.0.8

Published

State Diagram Notation (Graph)

Downloads

7

Readme

ASMgraph

State Diagram Notation (Graph)

State diagrams (also called State Chart diagrams) are used to help the developer better understand any complex/unusual functionalities or business flows of specialized areas of the system. In short, State diagrams depict the dynamic behavior of the entire system, or a sub-system, or even a single object in a system. This is done with the help of Behavioral elements.

Finite State Machine (FSM)

A Finite State Machine (FSM) is the representation of a system in terms of its states and events. A state is simply a decision point at the system level , and an event is a stimulus that causes a state transition within the system. Therefore , a state machine stays in the current state until n event is received causing a state transition. If the state to transition to is the current state, a new state is not entered event though a state transition occurs.

Mealy and Moore

Two well known types of state machine are the Mealy and Moore machines. The difference between these state machines is their output. The output of the Mealy state machine depends on the received event, while the output of the Moore state machine does not.

The functions defining the Moore state machine at transition t are:

S(t+1) = Function (S(t),I(t)); O(t+1) = Function (S(t))

The functions defining the Mealy state machine at transition t are:

S(t+1) = Function (S(t),I(t)); O(t+1) = Function (S(t),I(t))

While the state transition function S is same for both states machine, the output function O is different. The output of the Moore machine depends solely on the current state, while the output of the Mealy machine depends on both the current state and input.

Deterministic and Non- Deterministic

In a state transition diagram, if no two outgoing edges of a state have the same label, then the corresponding machine is called a deterministic finite state machine …if two or more outgoing edges of a state have the same label, then it is called a non-deterministic finite state machine.

Start docker instance

docker run --name asmgraph -p 5050:5050 -d --rm vcomm/asmgraph:latest

Install

npm install

Build

cd widgets/graph npm install npm run build

Run

cd ../..

Start application

npm start

Example: Generated Executable JSON

{
    "id": "tst",
    "prj": "prj",
    "type": "manual",
    "states": {
        "init": {
            "key": "init",
            "transitions": {
                "init=>[evCheck/efConfig]=>wait": {
                    "nextstatename": "wait",
                    "input": "evCheck",
                    "output": "efConfig"
                }
            }
        },
        "final": {
            "key": "final",
            "transitions": {}
        },
        "wait": {
            "key": "wait",
            "transitions": {
                "wait=>[evComplete/efReport]=>final": {
                    "nextstatename": "final",
                    "input": "evComplete",
                    "output": "efReport"
                },
                "wait=>[evReplay/efRequest]=>wait": {
                    "nextstatename": "wait",
                    "input": "evReplay",
                    "output": "efRequest"
                }
            }
        }
    }
}

Example: Generated Node.js code template

const fsmLogic = require('./manual.json');
const { serviceContent, serviceDeploy } = require('@vcomm/asmcore');

class serviceManager extends serviceDeploy {
    constructor() {
        super();
    }
    initLogic() {  // You have to implement the method 
        this.emitOn('efConfig', [
          (cntx)=>console.log('efConfig'),
          async (cntx)=>{
              return new Promise(resolve => {
                  setTimeout(() => resolve(cntx), 3000)
              })
              .then(data => {
                  console.log(`: Run async func: Anominus 1`);
              }) 
          },
          (cntx)=>cntx.setState(cntx.getNextSate()),
          (cntx)=>cntx.unlock()
        ], {});
        this.emitOn('efReport', [
          (cntx)=>console.log('efReport'),
          (cntx)=>cntx.setState(cntx.getNextSate()),
          (cntx)=>cntx.unlock()
        ], {});
        this.emitOn('efRequest', [
          (cntx)=>console.log('efRequest'),
          async (cntx)=>{
            const promise = new Promise((resolve,reject) => {
                setTimeout(() => resolve(cntx), 1000)
            })
            const data = await promise
            console.log(`: Run async func: Anominus 2`); 
          },
          (cntx)=>cntx.setState(cntx.getNextSate()),
          (cntx)=>cntx.unlock()
        ], {});
    }
}

Example: Using

const content  = new serviceContent(fsmLogic);
const manager  = new serviceManager();
manager.initLogic();

async function runLoop(trig, cntx, srvmng) {
    const state = await cntx.eventLoop(trig, srvmng);
    console.debug(` EvProc[${trig}] => nextState[${state}]:`)
}

(async (cntx, srvmng) => {
    await runLoop('evCheck', cntx, srvmng)
    await runLoop('evReplay', cntx, srvmng)
    await runLoop('evComplete', cntx, srvmng)
})(content, manager);

Debug in REPL.it

https://repl.it/@YakovLiskoff/ASMtest?lite=true