update Method

Updates the current state using an updater function that takes the current state value as its argument and returns the new state value. The state is updated immediately, but the emission of this new value to subscribers will occur asynchronously. This means that if multiple synchronous updates are made in quick succession, only the last update will be emitted, optimizing the emission process to prevent unnecessary updates

@param updater: (state: T) => T
A function that takes the current state value as its argument and returns the new state value

@returns this
The instance of the state, allowing for method chaining

API

update(updater: (state: T) => T): this;

Example

import {signalState} from '@bitfiber/ng/rx';
 
const data = signalState<number>(0);
 
// Updates the current state and emits the updated state to its subscribers
data.update(state => state + 1);