diff --git a/src/component-store/immer-component-store.ts b/src/component-store/immer-component-store.ts index bc791ab..6fbdd04 100644 --- a/src/component-store/immer-component-store.ts +++ b/src/component-store/immer-component-store.ts @@ -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 @@ -12,6 +13,10 @@ import { immerReducer } from 'ngrx-immer/shared'; export class ImmerComponentStore< State extends object > extends ComponentStore { + constructor(@Optional() @Inject(INITIAL_STATE_TOKEN) defaultState?: State) { + super(produce(defaultState, s => s)); + } + updater< ProvidedType = void, OriginType = ProvidedType,