Gathering detailed insights and metrics for ngrx-immer
Gathering detailed insights and metrics for ngrx-immer
Gathering detailed insights and metrics for ngrx-immer
Gathering detailed insights and metrics for ngrx-immer
npm install ngrx-immer
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
120 Stars
33 Commits
7 Forks
1 Watching
3 Branches
5 Contributors
Updated on 18 Nov 2024
TypeScript (97.07%)
JavaScript (2.93%)
Cumulative downloads
Total Downloads
Last day
3.7%
3,009
Compared to previous day
Last week
-7.3%
12,716
Compared to previous week
Last month
11.4%
55,976
Compared to previous month
Last year
114.2%
637,684
Compared to previous year
1
4
Immer wrappers around NgRx methods to simplify mutating state
1npm install ngrx-immer
Do not forget to install immer
createImmerReducer
(@ngrx/store)Creates an NgRx reducer, but allows you to mutate state without having to use to spread operator.
on
method1import { createImmerReducer } from 'ngrx-immer/store'; 2 3const todoReducer = createImmerReducer( 4 { todos: [] }, 5 on(newTodo, (state, action) => { 6 state.todos.push({ text: action.todo, completed: false }); 7 return state; 8 }), 9 on(completeTodo, (state, action) => { 10 state.todos[action.index].completed = true; 11 return state; 12 }), 13);
immerOn
(@ngrx/store)Creates an NgRx reducer, but allows you to mutate state without having to use to spread operator.
1import { immerOn } from 'ngrx-immer/store'; 2 3const todoReducer = createReducer( 4 { todos: [] }, 5 on(newTodo, (state, action) => { 6 return { 7 ...state, 8 todos: [...state.todos, action.todo], 9 }; 10 }), 11 immerOn(completeTodo, (state, action) => { 12 state.todos[action.index].completed = true; 13 }), 14);
ImmerComponentStore
(@ngrx/component-store)Wraps Immer around the Component Store updater
and setState
methods.
1import { ImmerComponentStore } from 'ngrx-immer/component-store'; 2 3@Injectable() 4export class MoviesStore extends ImmerComponentStore<MoviesState> { 5 constructor() { 6 super({ movies: [] }); 7 } 8 9 readonly addMovie = this.updater((state, movie: Movie) => { 10 state.movies.push(movie); 11 }); 12}
immerPatchState
(@ngrx/signals)[!IMPORTANT]
Because@ngrx/signals
is in developer preview, theimmerPatchState
function is also in developer preview. It is ready to try, but may change before becoming stable.
Provides an Immer-version of the patchState
function from the @ngrx/signals
package. In addition to partial state objects and updaters that update the state immutably, it accepts updater functions that update the state in a mutable manner. Similar to patchState
, the immerPatchState
function can be used to update the state of both SignalStore and SignalState.
1const UserStore = signalStore( 2 withState({ 3 user: { firstName: 'Konrad', lastName: 'Schultz' }, 4 address: { city: 'Vienna', zip: '1010' }, 5 }), 6 withMethods((store) => ({ 7 setLastName(lastName: string): void { 8 immerPatchState(store, (state) => { 9 state.user.lastName = lastName; 10 }); 11 }, 12 setCity(city: string): void { 13 immerPatchState(store, (state) => { 14 state.address.city = city; 15 }); 16 }, 17 })) 18);
Please note, that the updater function can only mutate a change without returning it or return an immutable state without mutable change.
This one is going to throw a runtime error:
1// will throw because of both returning and mutable change 2immerPatchState(userStore, (state) => { 3 state.name.lastname = 'Sanders'; // mutable change 4 return state; // returning state 5});
immerReducer
Inspired by Alex Okrushko, immerReducer
is a reducer method that uses the Immer produce
method.
This method is used by all the methods in ngrx-immer
provides.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
packaging workflow detected
Details
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More