Subscribe to state changes with optional transformation and filtering.
The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.
Unsubscribe function - call this to stop receiving updates
// Basic subscription
const unsubscribe = repository.subscribe((state) => {
console.log('State updated:', state);
});
// With transformations
const unsubscribe = repository.subscribe(
(userName) => console.log('User:', userName),
{ map: [(state) => state.user?.name] }
);
Function called with state updates (after map/filter applied)
Rest ...args: unknown[]Optional options: StateOptionsOptional transformations and filters for the subscription
Subscribe to state changes with optional transformation and filtering.
The subscription will immediately invoke the callback with the current state (if any), then continue to call it whenever the state changes. The map and filter options allow you to transform and selectively receive updates.
Unsubscribe function - call this to stop receiving updates
// Basic subscription
const unsubscribe = repository.subscribe((state) => {
console.log('State updated:', state);
});
// With transformations
const unsubscribe = repository.subscribe(
(userName) => console.log('User:', userName),
{ map: [(state) => state.user?.name] }
);
Deletes the filter
Returns
a promise that will be resolved when the filter is deleted