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

service-js

v0.0.1

Published

A library for managing global service interfaces which can have multiple implementations.

Downloads

3

Readme

Service.js

Build Status

Service.js is a library for managing abstractions over how your program interacts with the outside world.

A "service" is an interface to some global funcationality. Examples would be error reporting, data persistence, API abstraction, performance monitoring, audio playback abstraction, even DOM manipulation abstraction.

An "implementation" of a service is an object that implements the service's interface and registers itself with the services library. There may be multiple implementations of a service, the priority is determined by the order of registration.

An "instance" of a service is a particular implementation that's been instantiated, intialized, and (usually) started. Instances are what the application code actually uses and can be accessed by calling Services.ready.

An example should help clear this up.

Example Usage

In this example, we have two implementations of the "Socket" service, which the pubsub service uses to actually accomplish sending and receiving messages. The SocketService service uses websockets and registers itself first, thereby having a higher priority. However, if the client doesn't have WebSockets, the PollingService implementation of 'Socket' will be started instead.

// Web socket implmentation of 'Socket'
var WebSocketService = Object.create(Services.Service);
WebSocketService.isUsable = function() {
  return 'WebSocket' in window;
};
Services.register('Socket', WebSocketService);

// Polling implementation of 'Socket'
var PollingSocketService = Object.create(Services.Service);
Services.register('Socket', PollingSocketService);

// Implementation of pubsub (there's only 1 in the example)
var Pubsub = Object.create(Services.Service);
Pubsub.onStart = function() {
  return Services.ready('Socket');
}
Pubsub.publish = function() { /* publish stuff */ }
Pubsub.subscribe = function() { /* subscribe to stuff */ }
Services.register('Pubsub', Pubsub);

// Later, in application code

// This is usually called once after all services are registered and your app
// is ready to start. In `window.onload` for instance.
Services.start();

// Anywhere in your app where you need to use a service, you can get access
Services.ready('Pubsub').spread(function(pubsub) {
  // `pubsub` is an instance of the Pubsub service implementation
  pubsub.publish('up and running!');
});

There is complete API documentation available.

Using the library

In a browser

Just include build/service.min.js in a script tag. Then Services will be globally available.

If you use AMD

  • Copy build/service.amd.js to the appropriate place in your application, rename it service.js.
  • Then you can just require(['service'] function(Services) {} to your heart's content.

In Node.js

npm install service-js

Then in your app all you need to do is require it:

var Services = require('service-js');

Development

Running tests

make test

Building a release

make release

Files will end up in the build directory.