Skip to Content

compareBy Method

Sets a custom comparison strategy that will be used to determine if the state has changed. This comparison can be one of the predefined comparison types ('equals' or 'strict') or a custom comparison function

@param comparison: Comparison
The comparison method to use for evaluating state changes

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

API

compareBy(comparison: Comparison): this;

Example

import {changeDefaultComparison} from '@bitfiber/rx'; import {signalState} from '@bitfiber/ng/rx'; const data1 = signalState<number>(10, s => s // Uses the `equals` function from the package '@bitfiber/utils' for comparing values // this comparison is by default .compareBy('equals')); const data2 = signalState<number>(10, s => s // Uses '===' for comparing values .compareBy('strict')); const data3 = signalState<number | string>(10, s => s // Uses a custom function for comparing values .compareBy((a, b) => Number(a) === Number(b))); // By default, uses the `equals` function for comparing values. // To set a different comparison type for all states by default, use this function changeDefaultComparison('strict');
Last updated on