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

casern

v1.1.0

Published

unidirectional data-flow manager for persistent, multi-tenant state machines

Downloads

19

Readme

casern

Build Status TAP 💯 club

unidirectional data-flow manager for persistent, multi-tenant state machines

Casern is for server side redux, when you need a lot of little state machines. For example handling chatbot states across thousands of conversations.

This project has been used succesfully for 1000's of parallel chatbot states.

The structure of data flow is based on barracks. In casern, the state is persistent, and you can have many state machines.

"A casern is a military barracks in a garrison town"

Module Usage

npm install casern
const casern = require('casern')
const PouchDB = require('pouchdb')
const yourEmailSender = require('yourEmailSender')

let preferences = {
  supportPerson: '[email protected]'
  timeoutAfter: 10000
}
let services = {
  sendEmail: (emailAddress, msg, done) => yourEmailSender(emailAddress, msg, done)
}
let reducers = {
  initialInquiry: (preferences, state, data) => {
    let nextState = {}
    nextState.status = 'inquired'
    nextState.name = data.name
    nextState.when = Date.now()
    return nextState
  }
  checkTimeout: (preferences, state, data) => {
    if (!data.now) return state // we need the current time to be passed to us so we are a pure, side-effect free function
    if (state.status === 'timeout') return state // ignore some existing states
    if (state.when + preferences.timeoutAfter > data.now) state.status = 'timeout'
    return state
  }
}
let stateChangeListeners = {
  emailSupport: (preferences, services, send, prevState, currentState, appliedDate, stateID, done) => {
    if (currentState.status === 'timeout') {
      services.sendEmail(preferences.supportPerson, `The person ${currentState.name} has not responded`, done)
    }
  }
}
let statedb = new PouchDB('statedb')
const {send} = casern(statedb, preferences, services, reducers, stateChangeListeners)

// for now, lets just show one thing to track state of
let someId = '12344'
let inquiry = { name: 'ryan' }
send('initialInquiry', someId, inquiry) // create an initialInquiry by sending to the reducer
setInterval(
  () => send('checkTimeout', someId, {now: Date.now()}), // call the checkTimeout reducer
1000) // pulse this enquiry every second

License

MIT