Skip to content

Commit

Permalink
fix(ImmerComponentStore): set defaultState (via constructor) as immut…
Browse files Browse the repository at this point in the history
…able (#27)
  • Loading branch information
SebastianPost1996 committed May 17, 2024
1 parent e6c5c21 commit 6435bc2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/component-store/immer-component-store.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable, Optional } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { ComponentStore } from '@ngrx/component-store';
import { ComponentStore, INITIAL_STATE_TOKEN } from '@ngrx/component-store';

import { immerReducer } from 'ngrx-immer/shared';
import { produce } from 'immer';

/**
* Immer wrapper around `ImmerComponentStore` to mutate state
Expand All @@ -12,6 +13,10 @@ import { immerReducer } from 'ngrx-immer/shared';
export class ImmerComponentStore<
State extends object
> extends ComponentStore<State> {
constructor(@Optional() @Inject(INITIAL_STATE_TOKEN) defaultState?: State) {
super(produce(defaultState, s => s));
}

updater<
ProvidedType = void,
OriginType = ProvidedType,
Expand Down

0 comments on commit 6435bc2

Please sign in to comment.