@@ -247,12 +247,8 @@ export class FormState<T, State = DefaultState, Error extends string = DefaultEr
247
247
* @param notifyParent Should this form notify the parent form about this change?
248
248
*/
249
249
public setValues ( values : Partial < T > , validate ?: boolean , isDefault : boolean = false , notifyChild : boolean = true , notifyParent : boolean = true ) {
250
- // No set is used because this could cause problems with array keys, which must always be in the right order
251
250
let keys = Object . keys ( isDefault ? this . defaultValues : this . values ) ;
252
- let newKeys = Object . keys ( values ) ;
253
- for ( let i = 0 ; i < newKeys . length ; i ++ ) {
254
- if ( ! keys . includes ( newKeys [ i ] ) ) keys . push ( newKeys [ i ] ) ;
255
- }
251
+ addDistinct ( keys , Object . keys ( values ) ) ;
256
252
257
253
// Traverse backwards, so when removing array items, the whole array gets shifted in the right direction
258
254
for ( let i = keys . length - 1 ; i >= 0 ; i -- ) {
@@ -412,10 +408,10 @@ export class FormState<T, State = DefaultState, Error extends string = DefaultEr
412
408
public setState ( newState : State , notifyChild : boolean = true , notifyParent : boolean = true ) {
413
409
this . _state = newState ;
414
410
415
- let c = Object . keys ( this . values ) ;
411
+ let c = Object . keys ( this . values ) as ( keyof T ) [ ] ;
416
412
if ( notifyChild ) c . forEach ( ( e ) => this . childMap [ e ] ?. setState ( newState , true , false ) ) ;
417
413
418
- c . forEach ( ( e ) => this . fireListeners ( e as keyof T ) ) ;
414
+ c . forEach ( ( e ) => this . fireListeners ( e ) ) ;
419
415
this . fireAnyListeners ( ) ;
420
416
if ( notifyParent ) this . updateParentState ( ) ;
421
417
}
0 commit comments