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

@iamadamjowett/angular-coms

v1.1.2

Published

A communication service to allow easy passing and listening of events (with optionaldata) around an angular application. Events are broadcast from the $rootScope, making it easy to listen to events from anywhere in your application.

Downloads

3

Readme

#angular-coms

A communication service to allow easy passing and listening of events (with optionaldata) around an angular application. Events are broadcast from the $rootScope, making it easy to listen to events from anywhere in your application.

Installation

There are two easy ways to install the Coms service:

####npm

npm install @iamadamjowett/angular-coms

Bower

To install via Bower, run:

bower install angular-coms

Manual download

Download the coms.service.js file, and include it in your index.html file with something like:

<script type="text/javascript" src="/path/to/coms.service.js"></script>

Also be sure to include the module in your app.js file with:

angular.module('yourAppName', ['angular-coms'])

Usage

Sending signals (events)

Sending events are as easy as calling the sendSignal method. You pass the event string to be sent as the first parameter, and any data you wish to pass with the event as the second.

Coms.sendSignal('signal:foo', { id: getId(), arr: [1, 2, 3] });
Coms.onSignal('signal:foo', function (event, dataObj) {
    console.log(dataObj);
}, $scope);

Sometimes with the async nature of AngularJS, you need to delay the sending of a call until something else is ready. This can be done as follows, in this case, delaying the sending of the event by 400ms:

Coms.sendSignal('signal:foo', 'random string', 400);
Coms.onSignal('signal:foo', function (event, data) {
    console.log('I received the ' + data + ' after a 400ms delay');
}, $scope);

Listening for signals (events)

To listen for an event, you can use the onSignal method, which takes a signal string as the first parameter, a function to listen to the event and a scope to automatically remove the listener if the scope is destroyed (handy for controlling memory leaks).

Coms.onSignal('signal:foo', function (event, data) {
    console.log('id received: ' + data.id);
}, $scope);

Deregistering event listeners

Like native angular events, the onSignal method returns the de-registering function as part of the call. You can assign this to a variable and call it later to manually remove a listener. Listeners are de-registed automatically when the scope is destroyed as long as you pass the scope as the last parameter of the listener.

var fooListener = Coms.onSignal(Events.FOO_EVENT, function (event, data) {
    console.log('FOO_EVENT received with fooVar value of: ' + data);
}, $scope);

elem.$on('$destroy', function () {
    fooListener();
});