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

reduce-store

v3.0.0

Published

[![npm install][install-img]]([npm-url]) [![Downloads][downloads-img]]([stats-url]) ![License][license-img]

Downloads

164

Readme

reduce-store

npm install Downloads License

This library contains functionality to store and reduce (change) multiple application states.

The Concept.

At every moment an application can be described as a set of States. User actions, server responses, and other events lead to reduce (change) of an application States. Change of an application state is done by Reducers. A reducer is an object which implements the IReducer interface. A Reducer contains a reference to a State constructor function and reduceAsync method. This method receives a current state and up to 6 arguments and return a Promise of a next State. Reducers may have dependencies which are resolved by an object which implements the IDependecyResolver interface.

Another way to change a State is to call anonymous reduce function (delegate), i.e. implements the IReducerDelegate interface. That function receives a current State and returns a Promise of a next State.

An application usually has multiple States which are located in a different folder. The folder structure may follow the Domain Driven Design concept. A State along with its Reducers may be located in the same file. It is recommended to create small states and simple reduce functions. Because small functions are easy to test.

It is recommended that States be immutable. In that case, different application component receives different copies of a State. These copies cannot influence each other and the State stored in the reduce-store Store. Basic clone functionality can be found in the Clone class. One can extend this class and Store will support cloning of every state. In order to turn cloning on a developer should call Store.config.set({ cloneMethodName: 'clone' });

Demo application

Below is the link to a sample application that shows main usages of reduce-store library. Tour of Heroes with reduce-store

Author

Polezky Oleg Follow on GitHub Follow on Stack Overflow

License

MIT License (Expat).

Code samples.

file: test.state.ts

import { Clone, IReducer } from 'reduce-store';
import { Injectable } from '@angular/core';

export class State extends Clone<State> {
  value: number;
}

@Injectable({ providedIn: 'root' }) // here the Reducer is an angular service
export class TestStateReducer implements IReducer<State> {
  stateCtor = State;

  reduceAsync(state: State, newValue: number = new State()): Promise<State> {
    s.value = newValue;
    return Promise.resolve(s);
  };
}

export function TestStateDelegate(s: State = new State()): Promise<State> {
  return Promise.resolve(new State({ value: 1.75 }));
} 

file: test.component.ts

import * as testState from './test.state.ts';
import { Component, OnDestroy } from '@angular/core';

@Component({ selector: 'test' })
export class TestComponent implements OnDestroy {
  private state: State;

  constructor(private store: StoreService) {
    this.store.state.subscribe(testState.State, this, this.onStateChanged);
  }

  ngOnDestroy(): void {}

  private onStateChanged(s: testState.State): void {
    this.state = s;
  }
}

file: app.component.ts

import * as testState from './test.state.ts';
import { Component } from '@angular/core';

@Component({ template: '<test></test><input (click)="onButtonClick()" />' })
export class AppComponent {
  constructor(private store: StoreService) {
    this.store.reduce.byConstructor(testState.TestStateReducer, 1);
  }

  onButtonClick(): void {
    this.store.reduce.byDelegate(testState.State, testState.TestStateDelegate);
  }
}