Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]patchStateWithImmer #14

Merged
merged 6 commits into from
Jan 3, 2025
Merged

[feat]patchStateWithImmer #14

merged 6 commits into from
Jan 3, 2025

Conversation

mzkmnk
Copy link
Member

@mzkmnk mzkmnk commented Jan 3, 2025

Issue

#9

Content

This function leverages Immer's produce to let you write mutable-looking
changes in the updater callback while actually creating a new, immutable
state object under the hood.

** e.g **

import {signalStore} from "@ngrx/signals";

export const UserSignalStore = signalStore(
  withState<{ name: string, age: number }>({name: 'John', age: 30}),
  withMethods((store) => ({
    editUser: (name: string) => {
      // here
      patchStateWithImmer(store, (state) => {
        state.user.name = name;
      });
    },
  }))
)

@mzkmnk mzkmnk force-pushed the feat/#9-patch-state-with-immer branch from 77b1bb9 to afa6a13 Compare January 3, 2025 11:56
@mzkmnk mzkmnk marked this pull request as ready for review January 3, 2025 13:33
mzkmnk added 2 commits January 3, 2025 23:21
add:patch-state-with-immer test code
@mzkmnk mzkmnk merged commit f3d1a2a into main Jan 3, 2025
1 check passed
@mzkmnk mzkmnk deleted the feat/#9-patch-state-with-immer branch January 3, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant