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

angular-pub-sub

v1.0.1

Published

An Angular module that implements a Publish Subscribe service with support for message history.

Downloads

10

Readme

Codeship Status for jmnsf/angular-pub-sub

angular-pub-sub

Straightforward Publish-Subscribe module for AngularJS. Supports messages with multiple parameters and supports keeping a message history and rewinding upon subscription.

Documentation

This README and plenty of JSDOC comments if you feel like messing around with the code. Feel free to reach out here or on twitter (@jmnsferreira) if anything's unclear.

Install

1st: Get the code:

  • From distribution file
    1. Download angular-pub-sub.js (or the -min version);
    2. Include after AngularJS.
  • From npm:
    1. npm install angular-pub-sub

2nd: Add Module Dependency

...
var myApp = angular.module('myApp', ['PubSubModule']);
...

Configuration

setMaxHistory

Set the maximum number of messages to store in the history for playback upon subscription. Default is 10.

app.config(['pubSubProvider', function(pubSubProvider) {
  pubSubProvider.setMaxHistory(5);
}]);

Usage

publish

Publish a message to a channel.

Args:

  • channel - A String that identifies a channel (can be a new channel).
  • message* - Any number of arguments, can be zero for a simple "ping", of any data type to pass onto subscribers.

Return: undefined

Example:

myApp.controller('ItemsCtrl', function($scope, pubSub) {
  var nextPage = function () {
    ...
    pubSub.publish('nav-analytics', 'items', $scope.currentPage);
    ...
  };
});

subscribe

Subscribe to a channel to receive future messages and, optionally, previous ones.

Args:

  • channel - A String that identifies a channel. Same string as used in publish.
  • callback - A Function that will be executed with each message that is published on the selected channel.
  • playback - (Optional) When true, messages previously published on channel will be played back (applied on callback). Doesn't playback by default.
  • maxPlayback - (Optional) An Integer; the maximum number of messages to play back. Default is all available.

Return: A Function that will unsubscribe from channel when called.

Example:

myApp.controller('AnalyticsCtrl', function($scope, pubSub) {
  var killAnalytics = null;

  var trackPageView = function (name, page) {
    _analytics.track(name, page);
  };

  var setUp = function () {
    ...
    killAnalytics = pubSub.subscribe('nav-analytics', trackPageView, true, 1);
    ...
  };

  var setDown = function () { killAnalytics(); };
});

Contributing

  • Fork it.
  • Create an issue before adding a feature.
  • Keep the code style as possible (or change it if it's an improvement).
  • Add tests for what you do.

Developing:

Clone the project:

$ git clone https://github.com/<your-repo>/angular-pub-sub.git
$ cd angular-pub-sub
$ npm install
$ bower install

Run the tests:

$ grunt test

Deploying:

$ grunt dist