@@ -85,19 +85,22 @@ export function observable<T>(input: Accessor<T>): Observable<T> {
8585}
8686
8787type Producer < T > =
88- | ( ( setter : Setter < T > ) => ( ) => void )
89- | { subscribe : ( fn : ( v : T ) => void ) => ( ( ) => void ) | { unsubscribe : ( ) => void } } ;
88+ | ( ( setter : Setter < T > ) => ( ) => void )
89+ | { subscribe : ( fn : ( v : T ) => void ) => ( ( ) => void ) | { unsubscribe : ( ) => void } } ;
9090
9191export function from < T > ( producer : Producer < T > , initalValue : T ) : Accessor < T > ;
92- export function from < T > ( producer : Producer < T | undefined > ) : Accessor < T | undefined > ;
93- export function from < T > ( producer : Producer < T | undefined > , initalValue : T | undefined = undefined ) : Accessor < T | undefined > {
94- const [ s , set ] = createSignal < T | undefined > ( initalValue , { equals : false } ) ;
95- if ( "subscribe" in producer ) {
96- const unsub = producer . subscribe ( v => set ( ( ) => v ) ) ;
97- onCleanup ( ( ) => ( "unsubscribe" in unsub ? unsub . unsubscribe ( ) : unsub ( ) ) ) ;
98- } else {
99- const clean = producer ( set ) ;
100- onCleanup ( clean ) ;
101- }
102- return s ;
92+ export function from < T > ( producer : Producer < T | undefined > ) : Accessor < T | undefined > ;
93+ export function from < T > (
94+ producer : Producer < T | undefined > ,
95+ initalValue : T | undefined = undefined
96+ ) : Accessor < T | undefined > {
97+ const [ s , set ] = createSignal < T | undefined > ( initalValue , { equals : false } ) ;
98+ if ( "subscribe" in producer ) {
99+ const unsub = producer . subscribe ( v => set ( ( ) => v ) ) ;
100+ onCleanup ( ( ) => ( "unsubscribe" in unsub ? unsub . unsubscribe ( ) : unsub ( ) ) ) ;
101+ } else {
102+ const clean = producer ( set ) ;
103+ onCleanup ( clean ) ;
104+ }
105+ return s ;
103106}
0 commit comments