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

@obsidize/rx-map

v2.2.0

Published

ES6 Map with rxjs extensions for change detection

Downloads

10

Readme

@obsidize/rx-map

A simple application state management mechanism reminiscent of @ngrx/entity EntityAdapter API.

This module differs from ngrx / redux in that it does not bother with the concept of actions / effects / reducers.

Rather, this module supplies a few simple base-line classes to build up a state structure that can be observed for changes and mutated directly (thus bypassing the constructs listed above).

Installation

  • npm:
npm install --save @obsidize/rx-map
  • git:
npm install --save git+https://github.com/jospete/obsidize-rx-map.git

Usage

Example

Here is a minimal working example - keep in mind that this example only scratches the surface of the full extent of this module.

import {RxStore} from '@obsidize/rx-map';

// Step 1 - Stand up your model structures

interface Customer {
	id: number;
	firstName: string;
	lastName: string;
}

interface Product {
	id: number;
	name: string;
}

interface Purchase {
	id: number;
	customerId: number;
	productId: number;
	productCount: number;
}

class AppSession extends RxStore {

	public readonly customers = this.defineEntity((customer: Customer) => customer.id);
	public readonly products = this.defineEntity((product: Product) => product.id);
	public readonly purchases = this.defineEntity((purchase: Purchase) => purchase.id);

	public readonly purchasesByCustomerId = this.defineEntityForeignKey(this.purchases, purchase => purchase.customerId);
	public readonly purchasesByProductId = this.defineEntityForeignKey(this.purchases, purchase => purchase.productId);
}

// Step 2 - Use the structure you created to store and fetch data

const session = new AppSession();

const [john, susan, bob] = session.customers.addMany([
	{ id: 0, firstName: 'John', lastName: 'Smith' },
	{ id: 1, firstName: 'Susan', lastName: 'Hopkins' },
	{ id: 2, firstName: 'Bob', lastName: 'Langley' }
]);

const [milk, eggs, bread] = session.products.addMany([
	{ id: 0, name: 'Milk' },
	{ id: 1, name: 'Eggs' },
	{ id: 2, name: 'Bread' }
]);

session.purchases.addMany([
	{ id: 0, customerId: bob.id, productId: eggs.id, productCount: 2 },
	{ id: 1, customerId: bob.id, productId: milk.id, productCount: 1 },
	{ id: 2, customerId: susan.id, productId: milk.id, productCount: 3 },
	{ id: 3, customerId: john.id, productId: bread.id, productCount: 5 },
	{ id: 4, customerId: bob.id, productId: bread.id, productCount: 1 },
	{ id: 5, customerId: susan.id, productId: eggs.id, productCount: 3 }
]);

console.log(session.customers.getOne(john.id)); // { id: 0, firstName: 'John', lastName: 'Smith' }
console.log(session.customers.getOne(susan.id)); // { id: 1, firstName: 'Susan', lastName: 'Hopkins' }
console.log(session.customers.getOne(bob.id)); // { id: 2, firstName: 'Bob', lastName: 'Langley' }

console.log(session.purchasesByCustomerId.getRelatedValues(john.id).length); // 1
console.log(session.purchasesByCustomerId.getRelatedValues(susan.id).length); // 2
console.log(session.purchasesByCustomerId.getRelatedValues(bob.id).length); // 3

console.log(session.purchasesByProductId.getRelatedValues(milk.id).length); // 2
console.log(session.purchasesByProductId.getRelatedValues(eggs.id).length); // 2
console.log(session.purchasesByProductId.getRelatedValues(bread.id).length); // 2

For more extensive examples, see the General Usage and RxStore test suites.

API

Source documentation can be found here