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

organic-plasma-feedback

v2.0.0

Published

Provide syntax sugar on top of organic-plasma implementations with feedback support.

Downloads

7

Readme

organic-plasma-feedback v2.0.0

Provide syntax sugar on top of organic-plasma implementations with feedback support.

usage

var Plasma = require('organic-plasma')
var plasma = require('organic-plasma-feedback")(new Plasma())

plasma.on('chemical1', function (c, callback) {
  // do work
  callback(err, {success: true})
})

plasma.emit('chemical1', function (err, result) {
  // result.success === true
})

API

All results from reactions for callback invoke are delivered as chemicals via plasma having the following signature:

{
  type: chemical.type + '-result',
  err: Error,
  result: Primitive,
  $feedback_timestamp: Date
}

plasma.on(pattern, handler, context, once)

arguments

  • pattern - the pattern on which to listen for chemicals
    • as String - matches against the Chemical.type property
    • as Object - matches against one or more properties of Chemical
  • handler - Function Invoked when a chemical, matching the pattern has been emitted. Invoked with:
    • c - Object emited Chemical
    • callback - Function (optional) - function (err, result), called to return feedback on the emited chemical. Can be omitted to and the plasma.on
  • context - Object (optional) - the context used when invoking the handler function
  • once - Boolean (optional) - indicates whether only one chemical will be processed by the handler function. After the chemical is processed the handler is unregistered

Callback usage - plasma.on(pattern, function (c, callback){} [, context][, once])

Registers a function to be triggered when a chemical emitted in the plasma matches the given pattern.

plasma.on("test-chemical", function (c, callback){
  // do some processing with `c`
  callback(null, { success: true })
}, undefined, true)

plasma.emit(c, callback)

Immediately triggers any reactions matching the given c chemical and provides feedback support via callbacks.

arguments

  • c - Object - to be emmited with the Chemical structure
    • as String - equals to { type: String, ... } Chemical
    • as Object - must follow the Chemical structure
  • callback - Function - function (err, result) {}
plasma.emit({ type: 'test' }, function (err, result) {})
plasma.emit('test', function (err, result) {})

Feedback examples

emit and receive callback from the first who respond

plasma.on({type: 'c1'}, function (c, callback) {
  callback(err, 'result1')
})
plasma.once({type: 'c1'}, function (c, callback) {
  callback(err, 'result2')
})

var c = {type: 'c1'}
plasma.emit(c, function callback (err, result) {
  // callback will be invoked just once with result === 'result1'
})

emit and receive callback invocation from all who respond

plasma.on({type: 'c1'}, function (c, callback) {
  callback(null, 'result1')
})
plasma.on({type: 'c1'}, function (c, callback) {
  callback(null, 'result2')
})

var c = {type: 'c1', $feedback_timestamp: 'unique-timestamp'}
plasma.emit(c, function callback (err, result) {
  // 1st callback invoke result === 'result1'
  // 2nd callback invoke result === 'result2'
})

Performance notice

This implementation is ~6 times slower than organic-plasma v0.0.7, however it provides greater control over plasma's feedback support and is aligned to its pattern in nature.