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

subote

v0.4.2

Published

unidirectional data flow RPC framework

Downloads

8

Readme

subote

Build Status NPM Version License

unidirectional data flow RPC framework

subote-architecture

Installation

npm install subote --save

API

Router : Duplex

Router manage messages and switching context. This class should not used directly in ordinary. You can use Server/Client classes instead of this class.

  • constructor(socket: Socket, [namespace: string])

Instance attributes

  • socket: Socket
  • namespace: string
  • shared: object
  • currentContext: Context
  • currentContextName: string

Instance methods

dispatch a message

  • register(address: string, subscription: function): void
  • register(subscription: function): void
  • register(subscription: { delegate: function }): void
    • register a given callback function or delegator
  • unregister(address: string, subscription: function): void
  • unregister(subscription: function): void
  • unregister(subscription: { delegate: function }): void
    • unregister a given callback function or delegator
  • dispatch(address: string, data: any): void
    • send a message to subscriptions

receive a message

  • delegate(address: string, data: any): void
    • called automatically by message publisher

for sending a message (via network)

  • send(address: string, data: any, [options: object])
    • server side: send a message to all clients via network (aka broadcast)
    • client side: send a message to the server router (is not a client binded in the server) via network
    • options are used for socket flags
      • volatile: boolean
      • json: boolean

for managing contexts

  • registerContext(name: string, context: Context): void
  • switchContext(name: string): Promise<void>
Address

address: string must start with / . Address is used for dispatching a message, or name of action that is received it.

Actions

Action is instance method that starts with / . It is called automatically by messages from other dispatcher.

Server : Router

Router for server side.

  • constructor(socket: Socket, [namespace: string])

Instance attributes

  • clients: Socket[]
    • socket.send(address: string, data: any): void
      • send a message to a client binded via network

Client : Router

Router for client side.

  • constructor(socket: Socket, [namespace: string])

Context : Delegator

Context represents separate actions.

  • constructor()

Instance attributes

  • router: Router
  • shared: object

Instance methods

for sending a message

  • send(address: string, data: any)
    • shortcut of router.send
  • dispatch(address: string, data: any): void
    • shortcut of router.dispatch

for receiving a message

  • delegate(address: string, data: any)
    • called automatically by router

for managing contexts

  • resume(): Promise<void>
  • suspend(): Promise<void>

Actions

Action can be defined in each context. A context action is called after a router action.

Messaging Protocol

+--------+                  +-------------+
| source | <-- register --- | destination |
|        | --- dispatch --> |             |
+--------+                  +-------------+

interface source {
  register(address: string, subscription: function): void;
  register(subscription: function): void;
  register({ delegate: function }): void;
};

interface destination {
  delegate(address: string, data: any): void;
};

Source needs to have a register method for a destination subscribes messages. When source dispatch a message, they needs to call destination's delegate method.

In subote architecture, address: string must start with / . When subote.Router instance is received a message, it automatically calls an action method with data.

let source = new subote.Dispatcher();
let router = new subote.Router(socket);

router["/message/view"] = (data) => {
  console.log(`received: ${data}`);
};

source.register(router);

source.dispatch("/message/view", "hello!");
// -> call router.delegate("/message/view", "hello!")
// => "received: hello!"

License

MIT