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

webactor

v0.3.3

Published

Everything that you need for actor architecture on client

Downloads

259

Readme

Webactor

Everything that you need for actor architecture on client

Webactor exports a set of functions to implement a message passing mechanism between different parts of a JavaScript application. It creates and manages message channels, defines message types and provides functions to send and receive messages over these channels. The code uses a combination of maps, finalization registry, weak references, and closure to keep track of messages and message channels, and to prevent memory leaks. The module supports message passing between different threads (Web workers) and between different JavaScript contexts within the same thread.

Public methods

w/ chatGPT

createEnvelope

The createEnvelope method is a utility function that helps create an envelope object for communication between different parts of an application.

function createEnvelope<T extends string, P>(type: T, payload: P, transferable?: undefined | Transferable[]): Envelope<T, P>
  • type (required): a string indicating the type of the message being sent. This could be any string that can be used to identify the message type.
  • payload (required): the message payload. This could be any JavaScript object or primitive value.
  • transferable (optional): an array of objects that should be transferred instead of cloned when the message is sent. This could be an array buffer, a shared memory object or a message port.

Return value

The createEnvelope function returns an Envelope object that can be sent between different parts of the application.

isEnvelope

The isEnvelope method is a utility method that checks whether a given object is an instance of the Envelope or not. The method takes one argument, obj, which is the object to be checked.

function isEnvelope<T extends Envelope>(some: any): some is T

createActorFactory

The createActorFactory method is a higher-order function that returns a factory function for creating actors with a given behavior function.

The return function createActorFactory creates an actor that communicates with other actors using a message-passing system. The behavior function defines how the actor should respond to incoming messages.

function createActorFactory(props: { getMailbox: () => Mailbox<Envelope>; }): (name: string, constructor: ActorConstructor) => Actor;

createDispatch / dispatch

The createDispatch function takes a target argument and returns a dispatch function that can be called with an envelope argument. The dispatch function is a shorthand for calling createDispatch and passing both target and envelope arguments in a single call.

The dispatch function send envelope through target.

function createDispatch(target: EnvelopeDispatchTarget): (envelope: Envelope) => void
function dispatch(target: EnvelopeDispatchTarget, envelope: Envelope): void

connectActorToActor

This function takes in two Actors or Actors with mappers and sets up a bi-directional connection between them.

function connectActorToActor(actor1: Actor | EnvelopeTransmitterWithMapper<Actor>, actor2: Actor | EnvelopeTransmitterWithMapper<Actor>): Function;

Request - Response

createRequest

This function takes a transmitter object as an argument. The function returns another function that is used to make requests to the transmitter

function createRequest(transmitter: EnvelopeTransmitter): (envelope: Envelope, onResponse: SubscribeCallback) => Function;
w/o chatGPT

createResponseFactory

function createResponseFactory(dispatch: WithDispatch): (initial: Envelope) => (envelope: Envelope) => void;

Channels

openChannelFactory

function openChannelFactory(transmitter: EnvelopeTransmitter): (envelope: Envelope, onOpenChannel: (context: OpenChanelContext) => void | Function) => () => void;

supportChannelFactory

function supportChannelFactory(transmitter: EnvelopeTransmitter): (initial: Envelope, onOpenChannel: (context: SupportChanelContext) => void | Function) => () => void;

createHeartbeat

type HeartbeatOptions = {
    maxTimeout?: number;
    checkTimeout?: number;
    dispatchTimeout?: number;
};
function createHeartbeat(context: WithDispatch & WithSubscribe, panic: (timeout: number) => void, options?: HeartbeatOptions): () => void;

Worker

connectActorToWorker

function connectActorToWorker(actor: Actor, worker: Worker | SharedWorker): Promise<() => void>;

connectActorToMessagePort

function connectActorToMessagePort(actor: Actor, port: MessagePort | MessagePortName): Function;

onConnectMessagePort

function onConnectMessagePort(context: DedicatedWorkerGlobalScope | SharedWorkerGlobalScope, callback: (name: MessagePortName) => unknown | Function): VoidFunction;