(props)
| 1328 | }; |
| 1329 | |
| 1330 | const _subscribe: FromSubscribe<TFieldValues> = (props) => { |
| 1331 | const needsValues = !!(props.formState as Record<string, unknown>)?.values; |
| 1332 | if (needsValues) { |
| 1333 | _valuesSubscriberCount++; |
| 1334 | } |
| 1335 | const { unsubscribe } = _subjects.state.subscribe({ |
| 1336 | next: ( |
| 1337 | formState: Partial<FormState<TFieldValues>> & { |
| 1338 | name?: InternalFieldName; |
| 1339 | values?: TFieldValues | undefined; |
| 1340 | type?: EventType; |
| 1341 | }, |
| 1342 | ) => { |
| 1343 | if ( |
| 1344 | shouldSubscribeByName(props.name, formState.name, props.exact) && |
| 1345 | shouldRenderFormState( |
| 1346 | formState, |
| 1347 | (props.formState as ReadFormState) || _proxyFormState, |
| 1348 | _setFormState, |
| 1349 | props.reRenderRoot, |
| 1350 | ) |
| 1351 | ) { |
| 1352 | const snapshot = { ..._formValues } as TFieldValues; |
| 1353 | |
| 1354 | props.callback({ |
| 1355 | values: snapshot, |
| 1356 | ..._formState, |
| 1357 | ...formState, |
| 1358 | defaultValues: |
| 1359 | _defaultValues as FormState<TFieldValues>['defaultValues'], |
| 1360 | }); |
| 1361 | } |
| 1362 | }, |
| 1363 | }); |
| 1364 | if (!needsValues) { |
| 1365 | return unsubscribe; |
| 1366 | } |
| 1367 | let called = false; |
| 1368 | return () => { |
| 1369 | if (called) { |
| 1370 | return; |
| 1371 | } |
| 1372 | |
| 1373 | called = true; |
| 1374 | _valuesSubscriberCount--; |
| 1375 | unsubscribe(); |
| 1376 | }; |
| 1377 | }; |
| 1378 | |
| 1379 | const subscribe: UseFormSubscribe<TFieldValues> = (props) => { |
| 1380 | _state.mount = true; |
no test coverage detected
searching dependent graphs…