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

@rx-angular/state

v18.1.0

Published

@rx-angular/state is a light-weight, flexible, strongly typed and tested tool dedicated to reduce the complexity of managing component state and side effects in angular

Downloads

48,770

Readme

@rx-angular/state

npm npm rx-angular CI codecov

state logo

Description

@rx-angular/state is a library designed to help developers effectively manage component-level state in Angular. It offers a lightweight and intuitive API and automatic subscription handling, making it a perfect solution for handling state in any Angular component, service or directive. This library offers unique features such as merging global state into local state, shared state selections, subscription-free interaction, and integration with imperative functions like component lifecycle and HostBindings. It is an ideal alternative or complimentary library to global state management solutions like Akita, NgRx, and NgXs.

Key features

  • ⚡️ Fully reactive
  • 🛡️ Strongly typed
  • 🚀 Highly performant

Introduction Video

intro-video_rx-angular--state-rx-state

Installation

npm install @rx-angular/state

Usage

Functional Creation (NEW)

The new functional creation API lets you create and configure RxState in only one place.

import { rxState } from '@rx-angular/state';
import { RxFor } from '@rx-angular/template/for';

@Component({
  template: `<movie *rxFor="let movie of movies$" [movie]="movie" />`,
  imports: [RxFor],
})
export class MovieListComponent {
  private movieResource = inject(MovieResource);

  private state = rxState<{ movies: Movie[] }>(({ set, connect }) => {
    // set initial state
    set({ movies: [] });
    // connect data source to state
    connect('movies', this.movieResource.fetchMovies());
  });

  // select a property for the template to consume as an observable
  movies$ = this.state.select('movies');
  // select a property for the template to consume as a signal
  movies = this.state.signal('movies');
}

The functional approach will be the new default approach for newer versions.

Read the Migration Guide for a migration guide explaining how to upgrade your codebase to the new API.

Class Based

Local Provider: Use RxState as a local provider in your component to make use of Angular's Dependency Injection.

With the new inject method:

@Component({
  /*...*/
  providers: [RxState],
})
export class RxStateInjectionComponent {
  private state: RxState<{ foo: string }> = inject(RxState);

  state$ = this.state.select();
}

With constructor based injection:

@Component({
  /*...*/
  providers: [RxState],
})
export class RxStateInjectionComponent {
  state$ = this.state.select();

  constructor(private state: RxState<{ foo: string }>) {}
}

Inheritance: Use RxState by extending it in your component.

@Component({
  /*...*/
})
export class RxStateInheritanceClass extends RxState<{ foo: string }> {
  value$ = this.select();
}

API overview

With @rx-angular/state, you can easily manage your component state with a range of powerful methods. You can find a detailed API documentation here.

Addons

The following complimentary tools are recommended for use with RxState to improve the development experience and optimize application performance.

🚀 @rx-angular/template

Reduce the amount of boilerplate code required in templates and bring rendering performance to next level.

⚒️ @rx-angular/state/effects

Reactively handle side effects, forget about the subscribe API and potential memory leaks.

📡 @rx-angular/state/actions

Create composable action streams for user interaction and backend communication with a minimal memory footprint.

✨ @rx-angular/cdk/transformations

Simplify data structures management. Create, modify, convert arrays and objects with ease.

🔬 @rx-angular/eslint-plugin

Enforce best practices for building reactive, performant, and Zone-less Angular applications.

🧩 Selections

Optimize state selections and data transfer, ensure only the necessary data is transferred.

Version Compatibility

| RxAngular | Angular | |-----------|------------| | ^18.0.0 | ^18.0.0 | | ^17.0.0 | ^17.0.0 | | ^16.0.0 | ^16.0.0 | | ^15.0.0 | ^15.0.0 | | ^14.0.0 | ^14.0.0 | | ^2.0.0 | >=13.0.0 | | ^1.0.0 | >=12.0.0 |

Regarding the compatibility with RxJS, we generally stick to the compatibilities of the Angular framework itself, for more information about the compatibilities of Angular itself see the official guide.

Contribution

If you want to contribute to this project, please follow our guideline.

Additional materials

OSS Example Applications