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

jarvice

v0.7.0

Published

Jarvice is a JavaScript library for developing multithreaded web applications

Downloads

4

Readme

About

jarvice is a tiny library that helps you develop maintainable multithreaded browser applications and simplifies the code written atop the Channel Messaging API.

Features

  • supports TypeScript as a first-class citizen
  • supports module bundlers like webpack and parcel
  • zero dependencies

Usage

jarvice is based on a creation of nodes. Each node represents a separate JavaScript thread (currently Window or a Web Worker) and exposes it's own external API for other nodes and threads. The nodes' connections can be passed down the spawn tree so for example the nested workers can still access the main thread.

Using methods:

worker.ts

import { node } from 'jarvice';

node()
  .method('greetPromise', async ([who]) => `Hello ${who}!`)
  .method('greetCallback', ([who], callback) => callback(`Hey ${who}!`));

window.ts

import { connect } from 'jarvice';

const worker = connect(new Worker('./worker.ts'));

const main = async () => {
  // 'Hello Dave!'
  console.log(await worker.methods.greetPromise('Dave'));
  // 'Hey David!'
  console.log(await worker.methods.greetCallback('David'));
};

main();

Using topics:

worker.ts

import { node } from 'jarvice';

const { publish } = node().topic('SECOND');

let i = -1;
setInterval(() => publish('SECOND', (i += 1)), 1000);

window.ts

import { connect } from 'jarvice';

const worker = connect(new Worker('./worker.ts'));

const unsubscribe = worker.topics.SECOND.subscribe((i) => {
  // 0, 1, 2, 3...
  console.log(i);
});

Passing down the nodes connections:

In this example we create a topic, pass down the app node interface to the worker and begin to listen on user's input on another thread.

window.ts

import { node, connect } from 'jarvice';

const app = node().topic('USER_INPUT');
const worker = connect(new Worker('./worker.ts'));

document.body.querySelector('#input').addEventListener((event) => {
  app.publish('USER_INPUT', event.currentTarget.value);
});

worker.connect('app', app);

worker.ts

import { node } from 'jarvice';

const worker = node();

const main = async () => {
  const app = await worker.getConnectedNode('app');

  const unsubscribe = app.topics.USER_INPUT.subscribe(console.log);
};

main();

Terminating nodes:

Nodes can be terminated by using terminate method available in the connected threads.

window.ts

import { node, connect } from 'jarvice';

const worker = connect(new Worker('./worker.ts'));

setTimeout(() => worker.terminate(), 1000);

Using typings schemas:

This library provides helper typings so you can benefit from TypeScript IDEs and type checking.

schemas.ts

import { NodeMethodDefinition, NodeSchema, NodeTopicDefinition } from 'jarvice';

// First we define methods, then topics, then connectable nodes schemas.
export type WorkerNodeSchema = NodeSchema<
  { formatTime: NodeMethodDefinition<[number, string], string> },
  { FORMATTED_TIME: NodeTopicDefinition<string> }
>;

worker.ts

Depending on the IDE you use, as you type the following code you should see names suggestions and typing errors highlighting.

import { node } from 'jarvice';
import { WorkerNodeSchema } from './schemas';
import { format } from 'date-fns';

const worker = node<WorkerNodeSchema>()
  .method('formatTime', async ([millis, pattern]) => format(millis, pattern))
  .topic('FORMATTED_TIME');

setInterval(
  () => worker.publish('FORMATTED_TIME', format(Date.now(), '')),
  1000,
);

app.ts

Same as in the above snippet, the schemas can be passed to the nodes interfaces.

import { connect } from 'jarvice';

import { WorkerNodeSchema } from './schemas';

const worker = connect<WorkerNodeSchema>(new Worker('./worker.ts'));

const main = async () => {
  const result = await worker.methods.formatTime(Date.now(), 'YYYY-MM-DD');
};

main();