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

varo

v0.3.0

Published

pattern matched composition for browser apps

Downloads

9

Readme

logo

pattern matched composition for browser apps

varo

Build Status Gitter

varo is a pattern matched logic library designed for the browser. Varo is designed to compliment Seneca by providing a similar, albeit, smaller set of API's. It's ideal use case is in browser-side apps.

The focus of Varo is to provide the ability to compose logic around patterns; it does not handle transport or any other concerns.

If you're using this module, and need help, you can:

Install

To install, simply use npm,

npm install varo

Test

To run tests, simply use npm:

npm run test

Quick Example

'use strict'

var Varo = require('varo')()

// Only one handler will be called, more specific wins,
// then insertion order is checked on two identical matches.
Varo.handle({role: 'sum'}, function (msg, done) {
  return done(null, {answer: (msg.left + msg.right)})
})

// Won't be called unless the pattern above was removed
Varo.handle({role: 'sum'}, function (msg, done) {
  return done(null, {answer: (msg.left - msg.right)})
})

// Listen for anything emitted via emit
Varo.observe({role: 'user'}, function (msg) {
  console.log(msg.user.name)
})

Varo.emit(role: 'user', event: 'change', user: {name: 'Dean'}})

// Get a response to a message. Handy for asking for data or
// making calculations.
Varo.act({role: 'sum', left: 1, right: 2}, function (err, reply) {
  console.log(reply)
})

// You don't have to use a callback, if you are running an handler that
// doesn't respond then it is ok to leave it out.
Varo.act({role: 'sum', left: 1, right: 2})

API

.handle(msg, handler(err, reply)) : this

Adds a handler for the msg provided. The handler is called when .act() is used. Note that only one handler will be called.

Varo.handle({role: 'sum'}, function (msg, done) {
  return done(null, {answer: (msg.left - msg.right)})
})

.observe(msg, observer(msg)) : this

Adds an observer that listens for any message matching the msg param. The observer is called when .emit() is used. Multiple observers can handle a single message; there is no callback

Varo.observe({role: 'sum'}, function (msg) {
  console.log(msg)
})

.act(msg [, reply]) : this

Sends the provided message to any interested single handler. Calls to act can be fire and forget or request response as necessary.

Varo.act({role: 'sum', left: 1, right: 2}, function (err, reply) {
  console.log(reply)
})

Varo.act({role: 'sum', left: 1, right: 2})

.emit(msg) : this

Sends the provided message to any interested observers. Calls to emit have no callback and are considered fire and forget. This makes .emit() / .observere() a great pattern matched replacement for event emitters.

Varo.handle({role: 'user', event: 'changed'}, function (msg) {
  console.log(msg.user.name)  
})

Varo.emit({role: 'user', event: 'changed', user: {name: 'Dean'})

.plugin(plugin(Varo)) : this

Calls the provided function with the current instance of varo. Useful to group functionality together in modular format.

Varo.plugin(function (varo) {
  varo.handle({role: 'sum'}, function (msg, done) {
    return done(null, {answer: (msg.left + msg.right)})
  })

  varo.observe({role: 'sum'}, function (msg) {
    console.log(msg)
  })
})

Varo.act({role: 'sum', left: 1, right: 2}, function (err, reply) {
  console.log(reply)
})

.removeHandler(handler) : this

Removes a named handler. Does not work for anonymous functions.

var handler = function (msg, done) {
  return done(null, {answer: (msg.left + msg.right)})
}

Varo.handle({role: 'sum'}, handler)
Varo.removeHandler(handler)

.removeObserver(observer) : this

Removes a named observer. Does not work for anonymous functions.

var observer = function (msg) {
  console.log(msg)
}

Varo.observe({role: 'sum'}, observer)
Varo.removeObserver(observer)

Contributing

The Senecajs org encourages open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.

License

Copyright (c) 2015, Dean McDonnell and other contributors. Licensed under MIT.