@@ -105,9 +105,17 @@ export function applyProps<T extends NgtAnyRecord>(instance: NgtInstanceState<T>
105105 return applyProps ( root , { [ targetKey ] : value } ) ;
106106 }
107107
108+ // Layers have no copy function, we must therefore copy the mask property
109+ if ( targetProp instanceof THREE . Layers && value instanceof THREE . Layers ) {
110+ targetProp . mask = value . mask ;
111+ } else if ( is . three < THREE . Color > ( targetProp , 'isColor' ) && is . colorRepresentation ( value ) ) {
112+ targetProp . set ( value ) ;
113+ }
108114 // Copy if properties match signatures
109- if (
110- targetProp ?. copy &&
115+ else if (
116+ targetProp &&
117+ typeof targetProp . set === 'function' &&
118+ typeof targetProp . copy === 'function' &&
111119 ( value as ClassConstructor | undefined ) ?. constructor &&
112120 ( targetProp as ClassConstructor ) . constructor === ( value as ClassConstructor ) . constructor
113121 ) {
@@ -118,29 +126,20 @@ export function applyProps<T extends NgtAnyRecord>(instance: NgtInstanceState<T>
118126 ) {
119127 Object . assign ( root , { [ targetKey ] : value } ) ;
120128 } else {
121- // fetch the default state of the target
122- const ctor = getMemoizedPrototype ( root ) ;
123- // The target key was originally null or undefined, which indicates that the object which
124- // is now present was externally set by the user, we should therefore assign the value directly
125- if ( ctor !== undefined && ctor [ targetKey ] == null ) Object . assign ( root , { [ targetKey ] : value } ) ;
126- // Otherwise copy is correct
127- else targetProp . copy ( value ) ;
129+ targetProp . copy ( value ) ;
128130 }
129131 }
130- // Layers have no copy function, we must therefore copy the mask property
131- else if ( targetProp instanceof THREE . Layers && value instanceof THREE . Layers ) {
132- targetProp . mask = value . mask ;
133- }
134132 // Set array types
135- else if ( targetProp ? .set && Array . isArray ( value ) ) {
136- if ( targetProp . fromArray ) targetProp . fromArray ( value ) ;
133+ else if ( targetProp && typeof targetProp . set === 'function' && Array . isArray ( value ) ) {
134+ if ( typeof targetProp . fromArray === 'function' ) targetProp . fromArray ( value ) ;
137135 else targetProp . set ( ...value ) ;
138136 }
139137 // Set literal types
140- else if ( targetProp ? .set && typeof value !== 'object' ) {
141- const isColor = ( targetProp as THREE . Color | undefined ) ?. isColor ;
138+ else if ( targetProp && typeof targetProp . set === 'function' && typeof value !== 'object' ) {
139+ const isColor = is . three < THREE . Color > ( targetProp , ' isColor' ) ;
142140 // Allow setting array scalars
143- if ( ! isColor && targetProp . setScalar && typeof value === 'number' ) targetProp . setScalar ( value ) ;
141+ if ( ! isColor && typeof targetProp . setScalar === 'function' && typeof value === 'number' )
142+ targetProp . setScalar ( value ) ;
144143 // Otherwise just set single value
145144 else targetProp . set ( value ) ;
146145 }
0 commit comments