Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
@rx-angular/state
Advanced tools
Readme
@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.
npm install @rx-angular/state
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.
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();
}
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.
The following complimentary tools are recommended for use with RxState to improve the development experience and optimize application performance.
Reduce the amount of boilerplate code required in templates and bring rendering performance to next level.
Reactively handle side effects, forget about the subscribe
API and potential memory leaks.
Create composable action streams for user interaction and backend communication with a minimal memory footprint.
Simplify data structures management. Create, modify, convert arrays and objects with ease.
Enforce best practices for building reactive, performant, and Zone-less Angular applications.
Optimize state selections and data transfer, ensure only the necessary data is transferred.
RxAngular | Angular |
---|---|
^1.0.0 | >=12.0.0 |
^2.0.0 | >=13.0.0 |
^14.0.0 | ^14.0.0 |
^15.0.0 | ^15.0.0 |
^16.0.0 | ^16.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.
If you want to contribute to this project, please follow our guideline.
FAQs
@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
The npm package @rx-angular/state receives a total of 7,224 weekly downloads. As such, @rx-angular/state popularity was classified as popular.
We found that @rx-angular/state demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.