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 🙏

© 2026 – Pkg Stats / Ryan Hefner

rcontext

v0.4.7

Published

A JavaScript library for managing entity relationships, handling CRUD operations, syncing with a server, and emitting real-time state updates to maintain a reactive and consistent frontend state.

Readme

RContext

RContext stands for Remote, Reactive, Real-time, and Reliable context management. It's a JavaScript library designed to manage relationships between entities, handle CRUD operations (create, read, update, delete), and synchronize state seamlessly with a remote server. It bundles changes into efficient requests, interprets server responses to keep the frontend state in sync, and emits real-time state updates for any modifications in the context. It's perfect for building reactive, data-driven applications with minimal boilerplate.

Relationships

Entity relationships are automatically determined based on the provided set definitions. The main rule is that an entity can have multiple children within each entity set but only one parent per set.

When child entities are added to the context, their relationships with their parents are stored in the state. This state keeps track of relationships in both directions, allowing quick access to an entity’s parents or children.

If a child entity is added before its parent, the relationship cannot be created immediately. In this case, the child is temporarily stored as an orphan. Once the parent is added later, the relationship is established, and the child is removed from the orphan list.

Example:

Define your sets

const ctx = new RContext();

// Independent entity set
ctx.addEntitySet({
    name: 'mySet1',
    keys: ['id'],
    parentKeys: []
});

// Entity set whose parent is mySet1
ctx.addEntitySet({
    name: 'mySet2',
    keys: ['id'],
    parentKeys: [
        {
            entitySet: 'mySet1',
            props: ['parentId']
        }
    ]
});

Add entities

// Add an independent entity
const ent1 = ctx.trackObject('mySet1', { id: 1, name: 'My entity 1' });

// Add an entity whose parent will be ent1
const ent2 = ctx.trackObject('mySet2', { id: 5, parentId: 1, name: 'My entity 2' });

Play with state

// Relationships will be automatically generated in the state
const state = ctx.getState();

// Managing state directly might be a bit tedious; better use this helper class
const stateReader = ctx.createStateReader(state); // Creates a new instance of RContextStateReader

// Get children of ent1 whose entitySet is 'mySet2'
const children = stateReader.getChildren(ent1, 'mySet2'); 

// Get the parent of ent2 whose entitySet is 'mySet1'
const parent = stateReader.getParent(ent2, 'mySet1'); 

Please note that the methods in RContextStateReader never return pure entities. Instead, they return immutable state objects, which include a reference to the corresponding pure entity for convenience.

Use it in your reactive app

// Instead of accessing the state directly from the context, in reactive apps,
// it’s better to use the event listener. This approach is more efficient 
// because the event is triggered asynchronously and skips unnecessary updates.
ctx.onContextChange = (newContextState) => {
    // Code to update my reactive app state
};

Edit your data, build requests, and sync with your server

// Edit an existing entity
ent2.edit({ name: 'New name for this entity!' });

// Add an entity in creation mode
const ent3 = ctx.createObject('mySet1', { name: 'My entity 3' });

// Generate the composite request object, which will include all the necessary
// information for the server to update the remote data.
// In this case, it will contain information to create `ent3` and update the
// `name` property of `ent2`.
const requests = ctx.buildRequests();

// Send the generated object to the server and handle the information there 
// (there are official implementations for handling these requests in PHP and C#)
const response = await myFunctionToSendTheObjectToTheServer(requests);

// Synchronize the local context with the server response
ctx.sync(response);