![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
ngx-state-manager
Advanced tools
[![npm version](https://badge.fury.io/js/ngx-state-manager.svg)](https://badge.fury.io/js/ngx-state-manager) [![npm downloads](https://img.shields.io/npm/dm/ngx-state-manager.svg)](https://www.npmjs.com/package/ngx-state-manager)
Simple state manager based on Angular services.
This package depends on Angular v13.0.0
.
Install ngx-state-manager from npm:
npm install ngx-state-manager --save
Define your state IState and create TodosStateService extended from abstract class FeatureStateManager. The main thing provided by FeatureStateManager is state instance by wich we're gonna manipulate with state changes. You have to define initial state in super method:
interface Todo {
userId: number;
id: number;
title: string;
completed: boolean;
}
interface IState {
todos: Todo[];
loaded: boolean;
}
@Injectable({
providedIn: 'root',
})
export class TodosStateService extends FeatureStateManager<IState> {
constructor(private http: HttpClient) {
super({
todos: [],
loaded: false,
});
}
getTodos(): Observable<Todo[]> {
if (!this.state.getValue('loaded')) {
this.http.get(GET_TODOS_URL).subscribe(todos => {
this.state.set('todos', todos);
this.state.set('loaded', true);
});
}
return this.state.get('todos');
}
}
Add TodosStateService to your app module using StateManagerModule:
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, StateManagerModule.forRoot([TodosStateService])],
bootstrap: [AppComponent],
})
export class AppModule {}
For your convenience create StateManager that gonna include all state services:
@Injectable({ providedIn: 'root' })
export class StateManagerService {
constructor(
public todos: TodosStateService,
public auth: AuthStateService,
public whatever: MyAnotherStateService
) {}
}
Now you can use StateManager in app component:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
todos$: Observable<Todo[]> = this.stateManager.todos.getTodos();
constructor(public stateManager: StateManager) {}
}
Besides simple state management library provide events broadcasting mechanism. This mechanism is achived using StateManagerEvents.
For example, you need to clear todos after you've logged out. First of all you need define event:
export class LogoutEvent implements StateEvent {
readonly type = 'LogoutEvent';
}
Then inject StateManagerEvents and use broadcast
method with created event as an arguemnt:
@Injectable({ providedIn: 'root' })
export class AuthStateService extends FeatureStateManager<IState> {
constructor(private events$: StateManagerEvents) {
super();
}
logout(): void {
this.state.set('user', null);
localStorage.removeItem(loggedInKey);
this.events$.broadcast(new LogoutEvent());
}
}
To catch event use ListenEvent
decorator with appropriate method
@Injectable({ providedIn: 'root' })
export class TodosStateService extends FeatureStateManager<IState> {
...
@ListenEvent(LogoutEvent)
clear() {
this.state.set('todos', []);
this.state.set('loaded', false);
}
}
You can isolate states and events within particular module using forFeature
method of StateManagerModule:
@NgModule({
imports: [
BrowserModule,
StateManagerModule.forFeature([FeatureStateService]),
],
providers: [FeatureStateService],
})
export class MyFeatureModule {}
FeatureStateManager
has following methods:
getState(key: string): Observable<any>
get observable of value from state by keygetStateValue(key: string): any
get current value from state by value (not observable)State
has following methods:
get(key: string): Observable<any>
get observable of value from state by keyset(key: string, value: any): void
set value to state using keygetValue(key: string): any
get current value from state by value (not observable)StateManagerEvents
has following methods:
broadcast(value: StateEvent): void
broadcast event to all listenersThe MIT License (MIT)
FAQs
[![npm version](https://badge.fury.io/js/ngx-state-manager.svg)](https://badge.fury.io/js/ngx-state-manager) [![npm downloads](https://img.shields.io/npm/dm/ngx-state-manager.svg)](https://www.npmjs.com/package/ngx-state-manager)
The npm package ngx-state-manager receives a total of 2 weekly downloads. As such, ngx-state-manager popularity was classified as not popular.
We found that ngx-state-manager demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.