@@ -46,11 +46,9 @@ export class ValueNodeMap {
4646 }
4747}
4848
49- export namespace Inspector {
50- /** Prop becomes stale or live (is being currently listened to reactively or not) */
51- export type OnPropStateChange = ( key : string , state : PropGetterState ) => void
52- export type OnValueUpdate = ( id : ValueItemID ) => void
53- }
49+ /** Prop becomes stale or live (is being currently listened to reactively or not) */
50+ export type OnPropStateChange = ( key : string , state : PropGetterState ) => void
51+ export type OnValueUpdate = ( id : ValueItemID ) => void
5452
5553export type ObservedPropsMap = WeakMap < Solid . Component [ 'props' ] , ObservedProps >
5654
@@ -63,13 +61,13 @@ const $NOT_SET = Symbol('not-set')
6361export class ObservedProps {
6462 constructor ( readonly props : Solid . Component [ 'props' ] ) { }
6563
66- private onPropStateChange ?: Inspector . OnPropStateChange | undefined
67- private onValueUpdate ?: Inspector . OnValueUpdate | undefined
64+ private onPropStateChange ?: OnPropStateChange | undefined
65+ private onValueUpdate ?: OnValueUpdate | undefined
6866 private observedGetters = { } as Record < string , { v : unknown | typeof $NOT_SET ; n : number } >
6967
7068 observe (
71- onPropStateChange : Inspector . OnPropStateChange ,
72- onValueUpdate : Inspector . OnValueUpdate ,
69+ onPropStateChange : OnPropStateChange ,
70+ onValueUpdate : OnValueUpdate ,
7371 ) {
7472 this . onPropStateChange = onPropStateChange
7573 this . onValueUpdate = onValueUpdate
@@ -157,8 +155,8 @@ export function clearOwnerObservers(owner: Solid.Owner, observedPropsMap: Observ
157155
158156// Globals set before collecting the owner details
159157let ValueMap ! : ValueNodeMap
160- let OnValueUpdate : Inspector . OnValueUpdate
161- let OnPropStateChange : Inspector . OnPropStateChange
158+ let OnValueUpdate : OnValueUpdate
159+ let OnPropStateChange : OnPropStateChange
162160let PropsMap : ObservedPropsMap
163161
164162const $INSPECTOR = Symbol ( 'inspector' )
@@ -199,26 +197,48 @@ function mapSourceValue<TEl extends object>(
199197 }
200198}
201199
200+ /**
201+ * Pre-observe component props without gathering data.
202+ * To get fresh values when the component is later inspected.
203+ */
204+ export function preObserveComponentProps (
205+ component : Solid . Component ,
206+ props_map : ObservedPropsMap ,
207+ ) : void {
208+ let props = component . props
209+
210+ // Only observe static shape props (not proxy props)
211+ if ( utils . is_solid_proxy ( props ) ) return
212+
213+ let observed = props_map . get ( props )
214+ if ( ! observed ) props_map . set ( props , ( observed = new ObservedProps ( props ) ) )
215+
216+ // Set up getters for all props to enable tracking
217+ for ( let [ key , desc ] of Object . entries ( Object . getOwnPropertyDescriptors ( props ) ) ) {
218+ if ( desc . get ) {
219+ let id : ValueItemID = `prop:${ key } `
220+ observed . observeProp ( key , id , desc . get )
221+ }
222+ }
223+ }
224+
202225function mapProps < TEl extends object > (
203226 props : Solid . Component [ 'props' ] ,
204227 eli : ElementInterface < TEl > ,
205228) {
206229 // proxy props need to be checked for changes in keys
207- const isProxy = ! ! ( props as any ) [ setup . solid . $PROXY ]
208- const record : Mapped . Props [ 'record' ] = { }
209-
230+ let is_proxy = utils . is_solid_proxy ( props )
210231 let checkProxyProps : ( ( ) => ReturnType < typeof compareProxyPropKeys > ) | undefined
232+
233+ let record : Mapped . Props [ 'record' ] = { }
211234
212235 // PROXY PROPS
213- if ( isProxy ) {
214- let propsKeys = Object . keys ( props )
236+ if ( is_proxy ) {
237+ let keys = Object . keys ( props )
215238
216- for ( const key of propsKeys ) record [ key ] = { getter : PropGetterState . Stale , value : null }
239+ for ( let key of keys ) record [ key ] = { getter : PropGetterState . Stale , value : null }
217240
218- checkProxyProps = ( ) => {
219- const _oldKeys = propsKeys
220- return compareProxyPropKeys ( _oldKeys , ( propsKeys = Object . keys ( props ) ) )
221- }
241+ checkProxyProps = ( ) => compareProxyPropKeys ( keys , ( keys = Object . keys ( props ) ) )
222242 }
223243 // STATIC SHAPE
224244 else {
@@ -227,13 +247,13 @@ function mapProps<TEl extends object>(
227247
228248 observed . observe ( OnPropStateChange , OnValueUpdate )
229249
230- for ( const [ key , desc ] of Object . entries ( Object . getOwnPropertyDescriptors ( props ) ) ) {
231- const id : ValueItemID = `prop:${ key } `
250+ for ( let [ key , desc ] of Object . entries ( Object . getOwnPropertyDescriptors ( props ) ) ) {
251+ let id : ValueItemID = `prop:${ key } `
232252 // GETTER
233253 if ( desc . get ) {
234- const { getValue, isStale} = observed . observeProp ( key , id , desc . get )
254+ let { getValue, isStale} = observed . observeProp ( key , id , desc . get )
235255 ValueMap . add ( id , getValue )
236- const lastValue = getValue ( )
256+ let lastValue = getValue ( )
237257 record [ key ] = {
238258 getter : isStale ? PropGetterState . Stale : PropGetterState . Live ,
239259 value : lastValue !== $NOT_SET ? encodeValue ( getValue ( ) , false , eli ) : null ,
@@ -252,12 +272,12 @@ function mapProps<TEl extends object>(
252272 }
253273 }
254274
255- return { props : { proxy : isProxy , record} , checkProxyProps}
275+ return { props : { proxy : is_proxy , record} , checkProxyProps}
256276}
257277
258278export type CollectDetailsConfig < TEl extends object > = {
259- onPropStateChange : Inspector . OnPropStateChange
260- onValueUpdate : Inspector . OnValueUpdate
279+ onPropStateChange : OnPropStateChange
280+ onValueUpdate : OnValueUpdate
261281 observedPropsMap : ObservedPropsMap
262282 eli : ElementInterface < TEl > ,
263283}
@@ -270,10 +290,10 @@ export function collectOwnerDetails<TEl extends object>(
270290 const { onValueUpdate, eli} = config
271291
272292 // Set globals
273- ValueMap = new ValueNodeMap ( )
274- OnValueUpdate = onValueUpdate
293+ ValueMap = new ValueNodeMap ( )
294+ OnValueUpdate = onValueUpdate
275295 OnPropStateChange = config . onPropStateChange
276- PropsMap = config . observedPropsMap
296+ PropsMap = config . observedPropsMap
277297
278298 const id = getSdtId ( owner , ObjectType . Owner )
279299 const type = utils . markOwnerType ( owner )
0 commit comments