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

cjs-noticeboard

v0.0.7

Published

Self-Logging Pubsub with Built-In Cache

Downloads

325

Readme


CJS-NOTICEBOARD


npm version Build Status Coverage Status

WHAT IS A NOTICEBOARD?

A Noticeboard is just the Pub-Sub pattern with a twist: most-recently published values are cached and accessible by future subscribers.

HOW TO USE IT

Install

	npm install cjs-noticeboard

Basic Use

Create New Noticeboard


	var Noticeboard = require('cjs-noticeboard'),
		board = new Noticeboard();

Subscribe to Notice

	
	var notice = 'new-user',
		watcher = 'greet-new-users';

	board.watch( notice, watcher, function( message ){

		console.log( "Hello " + message.notice.username + "!" );
	});

Publish to Notice Watchers


	board.notify( 'new-user', { username: 'akamaozu' });

Stop Subscribing to a Notice

	
	board.ignore( 'new-user', 'greet-new-users' )

Advanced Use

Unsubscribe Immediately After Responding to a Notice

	
	board.once( 'new-user', 'identify-first-user-only', function( message ){

		console.log( "First User: " + message.notice.username );
	});

Use Previous Notice and Subscribe to Future Notices

	
	board.watch( 'window-size', 'log-window-size', function( message ){

		console.log( "w: " + message.notice.width  " | h: " + message.notice.height );

	}, { useCache: true });

Enable Noticeboard Log Feature


	var Noticeboard = require('cjs-noticeboard'),
		board = new Noticeboard({ logging: true });

	// or

	board.settings.logging = true;

Enable Noticeboard Internal Operation Logging

Note: Noticeboard must have settings logging set to true


	var Noticeboard = require('cjs-noticeboard'),
		board = new Noticeboard({ logOps: true });

	// or

	board.settings.logOps = true;

Handle Noticeboard Logs

	
	board.watch( 'log-entry', 'process-board-logs', function( message ){

		var entry = message.notice;

		console.log.apply( console, entry );
	});

API


new Noticeboard(settings)

Create a new Noticeboard Instance. Behavior can be configured with settings.

  • Is a Function
  • Arguments
    • settings
      • type: Object {}
      • required: false
      • props:
        • logging
          • type: Boolean (true or false)
          • required: false
          • desc: Determines if the Noticeboard will notify subscribers of log-entry.
        • logOps
          • type: Boolean (true or false)
          • required: false
          • desc: Determines if the Noticeboard will publish notices about its internal operations to log-entry watchers.

Noticeboard.notify(notice, message, source)

Triggers the callback in every watcher of the specified notice. If there is a non-null message, the notification will be cached. The source is for attribution / debugging purposes.

  • Is a Function
  • Arguments
    • notice
      • type: String
      • required: true
    • message
      • type: Any
      • required: false
      • gotchas:
        1. notifications with a message will automatically be cached.
        2. notifications without a message will not be cached.
        3. notifications with the message object null will not be cached.
    • source
      • type: String
      • required: false

Noticeboard.watch(notice, watcher, callback, options)

Adds a watcher to the list of callbacks to execute when a notice is sent out. The execution context and parameters of the callback can be modified via options.

  • Is a Function
  • Arguments
    • notice
      • type: String
      • required: true
    • watcher
      • type: String
      • required: true
    • callback
      • type: Function
      • required: true
      • arguments passed: Object {}
      • arguments props:
        • notice
          • description: message passed from Noticeboard.notify
        • watcher
          • description: message passed from Noticeboard.watch
    • options
      • type: Object {}

      • required: false

      • props:

      • message

        • type: Any
        • required: false
        • description: Passed to callback on execution. accessible inside callback as arguments[0].watcher
      • useCache

        • type: Boolean (true or false)
        • required: false
        • description: Set to true if its okay to autofire the callback if the notification has been previously cached
      • once

        • type: Boolean (true or false)
        • required: false
        • description: Set to true if you want this watcher to autoignore the notice immediately after its callback.

Noticeboard.ignore(notice, watcher)

Remove a watcher from the list of callbacks to execute when this notice is sent out.

  • Is a Function
  • Arguments
    • notice
      • type: String
      • required: true
    • watcher
    • type: String
    • required: true

Noticeboard.once(notice, watcher, callback, options)

A simple wrapper around Noticeboard.watch that calls Noticeboard.ignore as soon as its callback is executed. See Noticeboard.watch for details this function's parameters.

Noticeboard.log()

Designed to simulate the browser's console.log, this function will notify all watchers of log-entry and pass its arguments object as the message.

For instance, this is equivalent to calling console.log, with the added benefit of not crashing if the browser doesn't have console. That and your log can be piped to other parts of your app.

Noticeboard.watch('log-entry', 'browser-console', function(msg){
	if(!console || typeof console.log !== "function"){ return; }

	console.log.apply(console, msg.notice);
}

With the above watcher, the snippet below is now a superior version of console.log.

Noticeboard.log("testing", {isTest: true}, [1,2,3], function(){})

CONTACT ME

Hop on the Noticeboard Train!

You're waiting for a train
A train that will take you far away
You know where you hope this train will take you
But you don't know for sure
Yet it doesn't matter
Because we'll be together

-- Mal (Inception, 2010)