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

ImmerComponentStore: defaultState (via constructor) is not immutable #26

Closed
SebastianPost1996 opened this issue May 15, 2024 · 3 comments

Comments

@SebastianPost1996
Copy link
Contributor

When initializing a store and defining the initial state in the constructor, that initial store is not produced by immer and thus not immutable until a state change has been performed.

interface TestState {
  test: string;
}

@Injectable({ providedIn: 'root' })
export class TestStore extends ImmerComponentStore<TestState> {
  constructor() {
    super({ test: 'foo' });
    this.get().test = 'bar'; // should throw an error but does not
  }
}

Replacing the defaultState in the super call by a produced value correctly causes an error to be thrown.

super(produce({ test: 'foo' }, x => x));
@SebastianPost1996 SebastianPost1996 changed the title defaultState (via constructor) is not immutable ImmerComponentStore: defaultState (via constructor) is not immutable May 15, 2024
@timdeschryver
Copy link
Owner

Thanks for raising this issue, do you want to create a PR for this @SebastianPost1996 ?

@SebastianPost1996
Copy link
Contributor Author

Added PR: #27

@timdeschryver
Copy link
Owner

Closes #27

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

No branches or pull requests

2 participants