Store Features
Log the state signals and computed signals of the store on every change, with the option to provide a filter function to log only the necessary signals.
Import the withLogger trait from @ngrx-traits/signals.
import { withLogger } from '@ngrx-traits/signals';
const store = signalStore(
withState({ foo: 'foo' }),
withEntities({entity: type<Product>()}),
withLogger('MyStore'),
);
const store = signalStore(
withState({ foo: 'foo' }),
withEntities({entity: type<Product>()}),
withLogger('orderItemsStore', {
// you can use a function to filter the state that is logged
// filter: ({ entityMap, ids }) => ({
// entityMap,
// ids,
// }),
// or you can use an array of keys of props names that should be logged
filter: ['idsSelected'],
}),
);
const store = signalStore(
withState({ foo: 'foo', bar: 'bar' }),
withLogger('MyStore', { showDiff: true }),
);
// patchState(store, { foo: 'foo2' }) logs:
// MyStore store changed: { bar: 'bar', foo: 'foo2' }
// MyStore store changes diff :
// - foo: foo
// + foo: foo2
| Property | Description | Value |
|---|---|---|
| name | Name to log in the console, passed as the first argument | string |
| filter | Optional either a function to filter the state that is logged or an array of props names of the state that should be included | (store)=> filteredStore | string[] |
| showDiff | Optional, if true logs the diff between the previous and the current state on every change | boolean |