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

vientos

v0.0.1

Published

Vientos is a library that implements the Publisher/Subscriber model for communcation.

Downloads

5

Readme

Vientos

Vientos is a package for making React tables with ease. This library is browser native so does not require any build step.

Table of Contents

  • Installation
  • Usage

Installation

npm install vientos

Usage

Include the source in your html

<script type="text/javascript" src="{% static 'path/to/vientos.js' %}"></script>

Broker

The broker is a singleton hat exists in the Vientos object. It is responsible for handling the registration, subscriptions and publications. It can be accessed using

Vientos.Broker

however it is recommeneded to avoid directly accessing this object and always using the Client API.

Client

Vientos.Client is a class used for accessing the Vientos API. A new Vientos.Client object can be instantiated by

const vientosClient = new Vientos.Client();

Constructor

The constructor has a signature

constructor(registerCallback = function(clientId, clientStore){}, sync = false){}

The registerCallback argument is a function that will be run after the registration has been accepted by the Broker but before the clientId has been returned to the Client constructor. Default is a no-op function.

The clientId argument of the registerCallback function is the unique ID returned when registering with the broker which the client object will have set as an attribute.

The clientStore argument of the registerCallback function is initially an empty object that the client can do whatever it wants to with. It is useful for storing extra data that can be used in subscription callbacks that would otherwise not appear in the publication data, specific to the client.

The sync argument is whether the registerCallback will be run synchronously or asynchronously. Default is false.

Subscribe

The Client has a method sub with signature

sub(topic, callback, sync = false){}

The topic argument is a string that references which topic to subscribe to.

The callback argument is a function that will be run on behalf of the client by the Broker when a publication is made to the given topic. The callback function must have the signature

function(data, clientStore){}

Where data is the data that was published to the given topic and clientStore is the object stored by the Broker on behalf of the client that can provide extra data for the callback function.

The sync argument is whether the callback will be run synchronously or asynchronously. Default is false.

Publish

The Client has a method pub with signature

pub(topic, data){}

The topic argument is a string that references which topic to publish to.

The data argument is of arbitrary type that will be passed to the callback functions of the subscribers for the given topic.

Examples

Hello World

const vientosClient1 = new Vientos.Client();
vientosClient1.sub('topic1', (data, clientStore) => console.log(data));

const vientosClient1 = new Vientos.Client();
vientosClient1.sub('topic2', (data, clientStore) => console.log(data * 2));

vientosClient1.pub('topic2', 42);
vientosClient2.pub('topic1', 'minerals');

In this example the output may be out of order as the sync argument was not passed as true, but the output for each would be 84 and "minerals" respectively.

React

A good use of Vientos is for functional react components that need to communicate with one another.