set Method

Updates the state to the provided value immediately, but the emission of this new value to subscribers will be performed 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 value: T
The new value to set as the current state

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

API

set(value: T): this;

Example

import {state} from '@bitfiber/rx';
 
const data = state<number>(0);
 
// Sets a new state value and emits the updated state to its subscribers
data.set(7);