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

@ee-tools/rxs

v0.1.6

Published

A Super simple, type-safe, and blaizngly fast RxJS store.

Downloads

6

Readme

RxS

npm (scoped) npm bundle size (scoped) Libraries.io dependency status for latest release, scoped npm package npms.io (final) npms.io (final) NPM Libraries.io SourceRank npm Dependents (via libraries.io), scoped npm package Snyk Vulnerabilities for npm scoped package

Introduction

RxS (Reactive Store) is a super light-weight implementation of a store that implements reactivity through RxJS.

Using RxS, you can create a store with some initial state, react to changes to that state, select specific elements from that state, and then mutate the state or describe re-usable actions.

Installation

To install RxS, just run:

yarn add @ee-tools/rxs

or

npm install @ee-tools/rxs

Example

Let's say you have an angular application and a component with some state that you want to react to.

import { Component } from '@angular/core';
import { store } from '@ee-tools/rxs';

// Setup some initial state
const initialState = { name: 'Initial Name' };

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
})
export class AppComponent {
  // Create a store using the initial state and an action to change the name
  store = createStore(initialState, {
    changeName: (state, newName: string) => {
      state.name = newName;

      return state;
    },
  });

  // select the name value from the store as an observable to be used in the application
  name$ = this.store.select('name');

  constructor() {}

  // define a method on the component to trigger an action from the store
  action(): void {
    this.store.dispatch('changeName', 'Ethan');
  }
}

API

createStore()

This method is called with the initial state and any associated actions to mutate the state. Similar to how redux introduces a single object for the entire state application and allows reacting on it, this returned store implements the RxJS Observable, as well as a few helper methods.

Example

const initialState = { count: 0 };

const store$ = createStore(initialState);

// The store object returned by createStore is also an RxJS Observable, 
// so you can subscribe to changes on the entire store!

store$.subscribe((state) => console.log(state))

mutate()

This method on the store allows you to directly mutate the entire state. It accepts a method that gives you the current state and expects you to return a new state.

Example


const store = createStore({count: 0});

store.mutate((state) => {
  state.count++;

  return state;
});

select()

Select will allow you to pick a value from the root store object, and get an observable for all changes to that specific value.

Example

const store = createStore({count: 0});

const count$ = store.select('count');
//      ^?  Observable<number>

dispatch()

Dispatch allows you to initiate one of the predefined actions against the store. It accepts two arguments; the first is the name of the action, and the second is the optional parameter to provide to your action.

Example

In this example we are going to also demonstrate defining the actions to increment and decrement the count.

const initialState = {count: 0};

const store = createStore(initialState, {
  increment: (state) => {
    state.count++;

    return state;
  },
  decrement: (state) => {
    state.count--;

    return state;
  },
  setCount: (state, count) => {
    state.count = count;

    return state;
  }
});

// Now that we have all of these actions, we can call them anywhere!

store.dispatch('increment');

store.dispatch('decrement');

store.dispatch('setCount', 100);