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

a4-store

v8.0.0

Published

Simple State Management Reactive Store

Downloads

4

Readme

a4-store

7 Store for state management

How-To

Install

npm install a4-store

app.store.ts

import { Injectable } from '@angular/core';
import { InitialState, Store, Reducer } from 'a4-store';

interface State {
  data1: number;
  data2: number;
}

@InitialState<State>({
  data1: 123,
  data2: 9995
})
@Injectable({
  providedIn: 'root'
})
export class AppStore extends Store<State> {

  @Reducer()
  setData1(data: number): Partial<State> {
    return { data1: data };
  }

  @Reducer()
  setData2(data: number): Partial<State> {
    return { data2: data };
  }

}

my-sample.component.ts

import { Component, OnInit, OnDestroy } from '@angular/core';
import { AppStore } from './app.store';
import { Observable, Subscription } from 'rxjs';

@Component({
  selector: 'app-my-sample',
  templateUrl: './my-sample.component.html',
  styleUrls: ['./my-sample.component.css']
})
export class MySampleComponent implements OnInit, OnDestroy {

  data1: Observable<number>;
  data2: Observable<number>;
  subscriptions: Subscription[];

  constructor(private appStore: AppStore) {
    this.data1 = appStore.map(p => p.data1);
    this.data2 = appStore.map(p => p.data2);
  }

  ngOnInit() {
    this.subscriptions = [
      this.data1.subscribe(p => console.log(`Data 1 changes to ${p}`)),
      this.data2.subscribe(p => console.log(`Data 2 changes to ${p}`))
    ];
  }

  ngOnDestroy() {
    this.subscriptions.forEach(p => p.unsubscribe());
  }

  doClick() {
    this.appStore.setData1(this.appStore.state.data1 + 1);
    this.appStore.setData2(this.appStore.state.data2 - 1);
  }

}

Difference between .map and .select

Select will only fire the subscription when the current alue is different than the last while Map will fire the subscription when there is a new value set in the store.

Immutable Methods (protected)

These immutable methods can only be used within the store class.

immutableReplaceElement

Returning a new array with element at index being replaced by newElement.

immutableReplaceElement<T>(array: T[], newElement: T, index: number): T[]

immutableRemoveElement

Returning a new array with element at index being removed.

immutableRemoveElement<T>(array: T[], index: number): T[]

immutableInsertElement

Returning a new array with element being inserted at specified index.

immutableInsertElement<T>(array: T[], element: T, index: number): T[]

immutablePrependElement

Returning a new array with element inserted at the start (first element) of the given array.

immutablePrependElement<T>(array: T[], element: T): T[]

immutableAppendElement

Returning a new array with element inserted at the end (last element) of the given array.

immutableAppendElement<T>(array: T[], element: T): T[]