@@ -5,39 +5,44 @@ import {NodeType} from './constants.ts'
55import { type Solid } from './types.ts'
66import setup from './setup.ts'
77
8- export const isObject = ( o : unknown ) : o is object => typeof o === 'object' && ! ! o
8+ export const isSolidOwner = ( o : Solid . Owner | Solid . Store | Solid . Signal ) : o is Solid . Owner =>
9+ 'owned' in o
910
10- export const isSolidOwner = (
11- o : Readonly < Solid . Owner | Solid . Store | Solid . Signal > ,
12- ) : o is Solid . Owner => 'owned' in o
13-
14- export const isSolidComputation = ( o : Readonly < Solid . Owner > ) : o is Solid . Computation =>
11+ export const isSolidComputation = ( o : Solid . Owner ) : o is Solid . Computation =>
1512 ! ! ( o as any ) . fn
1613
17- export const isSolidRoot = ( o : Readonly < Solid . Owner > ) : o is Solid . Root => ! ( 'fn' in o )
14+ export const isSolidRoot = ( o : Solid . Owner ) : o is Solid . Root =>
15+ ! ( 'fn' in o )
1816
19- export const isSolidMemo = ( o : Readonly < Solid . Owner > ) : o is Solid . Memo =>
17+ export const isSolidMemo = ( o : Solid . Owner ) : o is Solid . Memo =>
2018 'fn' in o && 'comparator' in o
2119
22- export const isSolidComponent = ( o : Readonly < Solid . Owner > ) : o is Solid . Component => 'component' in o
20+ export const isSolidComponent = ( o : Solid . Owner ) : o is Solid . Component =>
21+ 'component' in o
2322
24- export const isStoreNode = ( o : object ) : o is Solid . StoreNode => setup . store . $NODE in o
23+ export const isStoreNode = ( o : object ) : o is Solid . StoreNode =>
24+ setup . store . $NODE in o
2525
26- export const isSolidStore = (
27- o : Solid . Owner | Solid . SourceMapValue | Solid . Store ,
28- ) : o is Solid . Store => ! ( 'observers' in o ) && 'value' in o && isObject ( o . value ) && setup . solid . $PROXY in o . value
26+ export const isSolidStore = ( o : Solid . Owner | Solid . SourceMapValue | Solid . Store ) : o is Solid . Store =>
27+ ! ( 'observers' in o ) &&
28+ typeof o . value === 'object' &&
29+ o . value != null &&
30+ setup . solid . $PROXY in o . value
2931
3032export const isSolidSignal = ( o : Solid . SourceMapValue ) : o is Solid . Signal =>
31- 'value' in o && 'observers' in o && 'observerSlots' in o && 'comparator' in o
33+ 'value' in o &&
34+ 'observers' in o &&
35+ 'observerSlots' in o &&
36+ 'comparator' in o
3237
33- export function getNodeType ( o : Readonly < Solid . Signal | Solid . Owner | Solid . Store > ) : NodeType {
38+ export function getNodeType ( o : Solid . Signal | Solid . Owner | Solid . Store ) : NodeType {
3439 if ( isSolidOwner ( o ) ) return getOwnerType ( o )
3540 return isSolidStore ( o ) ? NodeType . Store : NodeType . Signal
3641}
3742
3843const SOLID_REFRESH_PREFIX = '[solid-refresh]'
3944
40- export const getOwnerType = ( o : Readonly < Solid . Owner > ) : NodeType => {
45+ export const getOwnerType = ( o : Solid . Owner ) : NodeType => {
4146 if ( typeof o . sdtType !== 'undefined' ) return o . sdtType
4247 if ( ! isSolidComputation ( o ) ) {
4348 if ( 'sources' in o ) return NodeType . CatchError
@@ -72,7 +77,7 @@ export const getOwnerType = (o: Readonly<Solid.Owner>): NodeType => {
7277
7378export const getNodeName = ( o : {
7479 component ?: ( ( ..._ : any ) => any ) & { displayName ?: string } ,
75- name ?: string
80+ name ?: string ,
7681} ) : string | undefined => {
7782
7883 let name : string | undefined
@@ -135,25 +140,25 @@ export function getComponentRefreshNode(owner: Readonly<Solid.Component>): Solid
135140 return null
136141}
137142
143+
138144export function resolveElements ( value : unknown ) : HTMLElement [ ] | null {
139- const resolved = getResolvedElements ( value )
140- if ( Array . isArray ( resolved ) ) return resolved . length ? resolved : null
141- return resolved ? [ resolved ] : null
142- }
143- function getResolvedElements ( value : unknown ) : HTMLElement | HTMLElement [ ] | null {
145+
144146 // do not call a function, unless it's a signal (to prevent creating new nodes)
145- if ( typeof value === 'function' && ! value . length && value . name === 'bound readSignal' )
146- return getResolvedElements ( value ( ) )
147+ if ( typeof value === 'function' && ! value . length && value . name === 'bound readSignal' ) {
148+ return resolveElements ( value ( ) )
149+ }
150+
147151 if ( Array . isArray ( value ) ) {
148152 const results : HTMLElement [ ] = [ ]
149153 for ( const item of value ) {
150- const result = getResolvedElements ( item )
154+ const result = resolveElements ( item )
151155 if ( result )
152156 Array . isArray ( result ) ? results . push . apply ( results , result ) : results . push ( result )
153157 }
154- return results
158+ return results . length ? results : null
155159 }
156- return value instanceof HTMLElement ? value : null
160+
161+ return value instanceof HTMLElement ? [ value ] : null
157162}
158163
159164/**
0 commit comments