@@ -8,7 +8,7 @@ const defaultEq = <T>(oldValue: T, newValue: T): boolean => oldValue === newValu
88 * @template T The type of the stored value.
99 *
1010 * @param val The initial value of the reactive variable.
11- * @param options Optional configuration for the reactive variable.
11+ * @param opts Optional configuration for the reactive variable.
1212 *
1313 * @returns A reactive variable function that allows getting, setting, and listening for updates.
1414 *
@@ -53,22 +53,22 @@ const defaultEq = <T>(oldValue: T, newValue: T): boolean => oldValue === newValu
5353 * positiveVar(5) // there will be no logs
5454 * ```
5555 */
56- export function rv < T > ( val : T , options ?: RvInitOptions < T > ) : Rv < T > {
57- const { eq = defaultEq , on } = options ?? < RvInitOptions < T > > { }
56+ export function rv < T > ( val : T , opts ?: RvInitOptions < T > ) : Rv < T > {
57+ const { eq = defaultEq , on } = opts ?? < RvInitOptions < T > > { }
5858
5959 const listeners = new Set < Listener < T > > ( )
6060
6161 if ( on ) listeners . add ( on )
6262
63- const fn : Rv < T > = ( ...args : [ ] | [ newValue : T , options ?: RvOptions < T > ] ) : T => {
63+ const fn : Rv < T > = ( ...args : [ ] | [ newValue : T , opts ?: RvOptions < T > ] ) : T => {
6464 if ( args . length === 0 ) return val
6565
66- const [ newValue , options ] = args
66+ const [ newValue , opts ] = args
6767
6868 let eqfn : EqualFn < T > = eq
6969
70- if ( typeof options ?. eq !== 'undefined' ) {
71- eqfn = options . eq === false ? defaultEq : options . eq
70+ if ( typeof opts ?. eq !== 'undefined' ) {
71+ eqfn = opts . eq === false ? defaultEq : opts . eq
7272 }
7373
7474 if ( eqfn ( val , newValue ) ) return val
@@ -81,6 +81,9 @@ export function rv<T>(val: T, options?: RvInitOptions<T>): Rv<T> {
8181 return val
8282 }
8383
84+ fn . off = ( f ) : void => void listeners . delete ( f )
85+ fn . size = ( ) : number => listeners . size
86+
8487 fn . on = ( listener ) : CleanupFn => {
8588 listeners . add ( listener )
8689
@@ -97,6 +100,7 @@ export function rv<T>(val: T, options?: RvInitOptions<T>): Rv<T> {
97100 * The function is immediately executed to determine the initial value.
98101 *
99102 * @template T The type of the stored value.
103+ *
100104 * @param init A function that returns the initial value.
101105 * @param options Optional configuration for equality comparison and event listeners.
102106 *
0 commit comments