11import { useReducer , useState } from "react" ;
22
3- export interface Signal < T > {
3+ export interface Immediate < T > {
44 /** Get latest value */
55 get ( ) : T ;
66 set ( value : T ) : void ;
@@ -10,12 +10,12 @@ function emptyReducer<T>(value: T): T {
1010 return value ;
1111}
1212
13- interface CreateSignalOptions < T > {
14- initialValue : T ;
13+ interface CreateImmediateOptions < T > {
14+ readonly initialValue : T ;
1515 setValue ( v : T ) : void ;
1616}
1717
18- function createSignal < T > ( options : CreateSignalOptions < T > ) : Signal < T > {
18+ function createImmediate < T > ( options : CreateImmediateOptions < T > ) : Immediate < T > {
1919 let value = options . initialValue ;
2020
2121 return {
@@ -30,17 +30,17 @@ function createSignal<T>(options: CreateSignalOptions<T>): Signal<T> {
3030}
3131
3232/**
33- * A replacement for `useState` that returns a "Signal ", which in this case is an object
34- * that allows to read the latest value, and to write a new value. It's object identity
33+ * A replacement for `useState` that returns an "Immediate ", which in this case is an object
34+ * that allows to read the latest value, and to write a new value. Its object identity
3535 * is stable, and does not change when writing a new value. That also means that it's
3636 * not reactive (you can't depend on it in useMemo or useEffect). For that, use the
3737 * second value from the returned tuple.
3838 * @param initialValue
3939 * @returns
4040 */
41- export function useSignal < T > ( initialValue : T ) : [ Signal < T > , T ] {
41+ export function useImmediate < T > ( initialValue : T ) : [ Immediate < T > , T ] {
4242 const [ value , setValue ] = useState ( initialValue ) ;
43- const [ signal ] = useReducer ( emptyReducer < Signal < T > > , { initialValue, setValue } , createSignal < T > ) ;
43+ const [ immediate ] = useReducer ( emptyReducer < Immediate < T > > , { initialValue, setValue } , createImmediate < T > ) ;
4444
45- return [ signal , value ] as const ;
45+ return [ immediate , value ] as const ;
4646}
0 commit comments