pattern matched composition for browser apps
varo
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.
- Version: 0.3.0
- Node: 4, 5
- Lead Maintainer: Dean McDonnell
- License: MIT
If you're using this module, and need help, you can:
- Post a github issue,
- Tweet to @senecajs,
- Ask on the Gitter.
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 = // Only one handler will be called, more specific wins,// then insertion order is checked on two identical matches.Varo // Won't be called unless the pattern above was removedVaro // Listen for anything emitted via emitVaro Varo // Get a response to a message. Handy for asking for data or// making calculations.Varo // 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
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
.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
.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 Varo
.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 Varo
.plugin(plugin(Varo)) : this
Calls the provided function with the current instance of varo. Useful to group functionality together in modular format.
Varo Varo
.removeHandler(handler) : this
Removes a named handler. Does not work for anonymous functions.
var { return } VaroVaro
.removeObserver(observer) : this
Removes a named observer. Does not work for anonymous functions.
var { console} VaroVaro
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.