relay-forms-nodeps 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +23 -108
  2. package/lib/RelayFormsTypes.d.ts +1 -0
  3. package/lib/Utils.d.ts +5 -8
  4. package/lib/Utils.js +10 -65
  5. package/lib/es/RelayFormsTypes.d.ts +1 -0
  6. package/lib/es/Utils.d.ts +5 -8
  7. package/lib/es/Utils.js +10 -67
  8. package/lib/es/relay/RelayRecordProxy.d.ts +1 -0
  9. package/lib/es/relay/RelayRecordProxy.js +3 -0
  10. package/lib/es/relay/RelayRecordSourceMutator.d.ts +1 -0
  11. package/lib/es/relay/RelayRecordSourceMutator.js +13 -0
  12. package/lib/es/relay/RelayTypes.d.ts +1 -0
  13. package/lib/es/relay/queries.d.ts +6 -4
  14. package/lib/es/relay/queries.js +6 -3
  15. package/lib/es/useFormSetValue.d.ts +5 -1
  16. package/lib/es/useFormSetValue.js +162 -64
  17. package/lib/es/useFormState.d.ts +12 -2
  18. package/lib/es/useFormState.js +10 -40
  19. package/lib/es/useFormSubmit.js +104 -89
  20. package/lib/es/useFormValue.js +1 -1
  21. package/lib/relay/RelayRecordProxy.d.ts +1 -0
  22. package/lib/relay/RelayRecordProxy.js +3 -0
  23. package/lib/relay/RelayRecordSourceMutator.d.ts +1 -0
  24. package/lib/relay/RelayRecordSourceMutator.js +13 -0
  25. package/lib/relay/RelayTypes.d.ts +1 -0
  26. package/lib/relay/queries.d.ts +6 -4
  27. package/lib/relay/queries.js +6 -3
  28. package/lib/umd/relay-forms-nodeps.js +319 -273
  29. package/lib/umd/relay-forms-nodeps.js.map +1 -1
  30. package/lib/umd/relay-forms-nodeps.min.js +1 -1
  31. package/lib/umd/relay-forms-nodeps.min.js.map +1 -1
  32. package/lib/useFormSetValue.d.ts +5 -1
  33. package/lib/useFormSetValue.js +162 -63
  34. package/lib/useFormState.d.ts +12 -2
  35. package/lib/useFormState.js +10 -40
  36. package/lib/useFormSubmit.js +103 -88
  37. package/lib/useFormValue.js +1 -1
  38. package/package.json +15 -2
  39. package/yarn-error.log +31 -31
@@ -223,14 +223,6 @@ function hasOverlappingIDs(seenRecords, updatedRecordIDs) {
223
223
  return false;
224
224
  }
225
225
 
226
- function useForceUpdate() {
227
- var _a = React.useReducer(function (x) {
228
- return x + 1;
229
- }, 0),
230
- forceUpdate = _a[1];
231
- return forceUpdate;
232
- }
233
-
234
226
  var id = {
235
227
  name: 'id'
236
228
  };
@@ -246,6 +238,9 @@ var error = {
246
238
  var value = {
247
239
  name: 'value'
248
240
  };
241
+ var label = {
242
+ name: 'label'
243
+ };
249
244
  var kindFragment = 'Fragment';
250
245
  var QueryErrors = {
251
246
  id: '1',
@@ -262,9 +257,9 @@ var QueryErrors = {
262
257
  name: 'isValidating'
263
258
  }, {
264
259
  kind: LINKED_FIELD,
265
- name: 'entries',
260
+ name: 'errors',
266
261
  plural: true,
267
- selections: [id, key, error, check]
262
+ selections: [id, key, error, check, label]
268
263
  }]
269
264
  }] /*: any*/
270
265
  }
@@ -296,7 +291,7 @@ var FragmentSet = {
296
291
  var FragmentValue = {
297
292
  kind: kindFragment,
298
293
  name: 'fragmentValue',
299
- selections: [id, value, error]
294
+ selections: [id, value, error, label]
300
295
  };
301
296
 
302
297
  /**
@@ -328,16 +323,6 @@ function createOperationDescriptor(request) {
328
323
  }
329
324
 
330
325
  var PREFIX_LOCAL_FORM = 'local:form';
331
- var internalCommitLocalUpdate = function (environment, updater) {
332
- environment.commitUpdate(function (store) {
333
- var localForm = store.get(PREFIX_LOCAL_FORM);
334
- if (!localForm) {
335
- localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries');
336
- store.getRoot().setLinkedRecord(localForm, 'form');
337
- }
338
- updater(store, localForm);
339
- });
340
- };
341
326
  function getFieldId(key) {
342
327
  return PREFIX_LOCAL_FORM + '.' + key;
343
328
  }
@@ -347,291 +332,336 @@ function getSnapshot(environment, fragment, key) {
347
332
  };
348
333
  return environment.lookup(getSingularSelector(fragment, item));
349
334
  }
350
- var commitResetIntoRelay = function (entries, environment) {
351
- internalCommitLocalUpdate(environment, function (store, form) {
352
- form.setValue(false, 'isSubmitting');
353
- form.setValue(false, 'isValidating');
354
- entries.forEach(function (entry) {
355
- return store.get(getFieldId(entry.key)).setValue('RESET', 'check');
356
- });
357
- });
358
- };
359
- var commitValidateIntoRelay = function (entries, isSubmitting, environment) {
360
- internalCommitLocalUpdate(environment, function (store, form) {
361
- form.setValue(isSubmitting, 'isSubmitting');
362
- form.setValue(true, 'isValidating');
363
- entries.forEach(function (entry) {
364
- return store.get(getFieldId(entry.key)).setValue('START', 'check');
365
- });
366
- });
367
- };
368
- var commitSubmitEndRelay = function (environment) {
369
- internalCommitLocalUpdate(environment, function (_, form) {
370
- form.setValue(false, 'isSubmitting');
371
- });
372
- };
373
- var commitValidateEndRelay = function (environment) {
374
- internalCommitLocalUpdate(environment, function (_, form) {
375
- form.setValue(false, 'isValidating');
376
- });
377
- };
378
- var commitResetField = function (environment, key) {
379
- var id = getFieldId(key);
380
- internalCommitLocalUpdate(environment, function (store, form) {
381
- var entriesArray = form.getLinkedRecords('entries');
382
- var newEntries = entriesArray.filter(function (value) {
383
- return value.getDataID() != id;
384
- });
385
- form.setLinkedRecords(newEntries, 'entries');
386
- store.delete(id);
387
- });
388
- };
389
- var commitValue = function (key, value, check, environment) {
390
- var id = getFieldId(key);
391
- internalCommitLocalUpdate(environment, function (store, form) {
392
- var field = store.get(id);
393
- if (!field) {
394
- field = store.create(id);
395
- var entriesArray = form.getLinkedRecords('entries');
396
- entriesArray.push(field);
397
- form.setLinkedRecords(entriesArray, 'entries');
335
+ function commit(environment, updater) {
336
+ environment.commitUpdate(function (store) {
337
+ var localForm = store.get(PREFIX_LOCAL_FORM);
338
+ if (!localForm) {
339
+ localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries').setLinkedRecords([], 'errors');
340
+ store.getRoot().setLinkedRecord(localForm, 'form');
398
341
  }
399
- field.setValue(id, 'id').setValue(key, 'key').setValue(check, 'check').setValue(value, 'value');
400
- });
401
- };
402
- var commitErrorIntoRelay = function (key, error, environment) {
403
- internalCommitLocalUpdate(environment, function (store) {
404
- store.get(getFieldId(key)).setValue(error, 'error').setValue('DONE', 'check');
342
+ updater(store, localForm);
405
343
  });
406
- };
344
+ }
407
345
  var operationQueryForm = createOperationDescriptor(QueryFields);
408
346
  var operationQueryErrorsForm = createOperationDescriptor(QueryErrors);
409
347
 
410
348
  var useFormState = function () {
411
- var ref = React__default["default"].useRef({
412
- errors: undefined,
413
- isValidating: false,
414
- isSubmitting: false,
415
- isValid: false
416
- });
417
- var forceUpdate = useForceUpdate();
418
349
  var environment = useStore();
350
+ var snapshot = React__default["default"].useMemo(function () {
351
+ return environment.lookup(operationQueryErrorsForm.fragment);
352
+ }, [environment]);
353
+ var _a = React__default["default"].useState(snapshot.data.form),
354
+ data = _a[0],
355
+ setData = _a[1];
419
356
  React__default["default"].useEffect(function () {
420
- function checkError(s) {
421
- var data = s.data;
422
- var form = data.form;
423
- var entries = form.entries;
424
- var current = ref.current;
425
- var entryErrors = entries.filter(function (value) {
426
- return !!value.error;
427
- });
428
- var entryValidated = entries.filter(function (value) {
429
- return value.check === 'DONE';
430
- });
431
- var errors = entryErrors.length > 0 ? entryErrors : undefined;
432
- var isValidating = form.isValidating;
433
- var isSubmitting = form.isSubmitting;
434
- var isValid = entries.length === entryValidated.length && (!errors || Object.keys(errors).length === 0);
435
- var newState = {
436
- errors: errors,
437
- isValid: isValid,
438
- isValidating: isValidating,
439
- isSubmitting: isSubmitting
440
- };
441
- if (!areEqual(current, newState)) {
442
- ref.current = newState;
443
- forceUpdate();
444
- }
445
- }
446
- var snapshot = environment.lookup(operationQueryErrorsForm.fragment);
447
- checkError(snapshot);
448
357
  return environment.subscribe(snapshot, function (s) {
449
- checkError(s);
358
+ setData(s.data.form);
450
359
  }).dispose;
451
- }, [environment, forceUpdate]);
452
- return ref.current;
360
+ // eslint-disable-next-line react-hooks/exhaustive-deps
361
+ }, [snapshot]);
362
+ return data;
453
363
  };
454
364
 
455
- var useFormSubmit = function (_a) {
456
- var onSubmit = _a.onSubmit;
457
- var environment = useStore();
458
- React__default["default"].useEffect(function () {
459
- return environment.retain(operationQueryForm).dispose;
460
- }, [environment]);
461
- var ref = React__default["default"].useRef({
462
- isSubmitting: false,
463
- isValidating: false,
464
- error: undefined,
465
- subscription: undefined
466
- });
467
- var internalValidate = React__default["default"].useCallback(function (snapshot, isSubmitting) {
468
- ref.current.isValidating = true;
469
- var data = snapshot.data;
470
- var filtered = data.form.entries.filter(function (value) {
471
- return value.check === 'INIT';
472
- });
473
- commitValidateIntoRelay(filtered, isSubmitting, environment);
474
- }, [environment]);
475
- var execute = React__default["default"].useCallback(function (environment, snapshot, dispose, onSubmit) {
476
- var data = snapshot.data;
477
- var entries = data.form.entries;
478
- var filtered = entries.filter(function (value) {
479
- return value.check === 'DONE';
480
- });
481
- if (filtered.length === entries.length) {
482
- var errors = entries.filter(function (value) {
483
- return !!value.error;
484
- });
485
- commitValidateEndRelay(environment);
486
- ref.current.isValidating = false;
487
- var internalDispose = function () {
488
- dispose();
489
- if (ref.current.isSubmitting) {
490
- ref.current.isSubmitting = false;
491
- commitSubmitEndRelay(environment);
492
- }
493
- };
494
- if (ref.current.isSubmitting && onSubmit && errors.length === 0) {
495
- var result_1 = {};
496
- entries.forEach(function (entry) {
497
- result_1[entry.key] = entry.value;
498
- });
499
- var submit_1 = onSubmit(result_1);
500
- if (isPromise(submit_1)) {
501
- submit_1.then(internalDispose).catch(internalDispose);
502
- return;
503
- }
504
- }
505
- internalDispose();
365
+ function useForceUpdate() {
366
+ var _a = React.useReducer(function (x) {
367
+ return x + 1;
368
+ }, 0),
369
+ forceUpdate = _a[1];
370
+ return forceUpdate;
371
+ }
372
+
373
+ var INIT = 0;
374
+ var TOBEVALIDATE = 1;
375
+ var VALIDATING = 2;
376
+ var DONE = 3;
377
+ var DONEVALIDATED = 4;
378
+ var RESET = 5;
379
+ function getInitCheck(validate) {
380
+ return validate ? TOBEVALIDATE : DONE;
381
+ }
382
+ function isDone(check) {
383
+ return check === DONE || check === DONEVALIDATED;
384
+ }
385
+ function logicSetValue(params) {
386
+ var environment = params.environment,
387
+ key = params.key,
388
+ initialValue = params.initialValue,
389
+ forceUpdate = params.forceUpdate,
390
+ validateOnChange = params.validateOnChange,
391
+ label = params.label;
392
+ var validate = undefined;
393
+ var firstSet = true;
394
+ var localId = getFieldId(key);
395
+ function getValidate() {
396
+ return validate;
397
+ }
398
+ var ref = {
399
+ check: INIT,
400
+ isChecking: false
401
+ };
402
+ var dataResult = {
403
+ value: initialValue,
404
+ error: undefined
405
+ };
406
+ function commitField(commitValue) {
407
+ if (commitValue === void 0) {
408
+ commitValue = true;
506
409
  }
507
- }, []);
508
- var reset = React__default["default"].useCallback(function () {
509
- var snapshot = environment.lookup(operationQueryForm.fragment);
510
- if (ref.current.isValidating && ref.current.isSubmitting) {
410
+ commit(environment, function (store, form) {
411
+ var field = store.get(localId);
412
+ if (!field) {
413
+ field = store.create(localId).setValue(localId, 'id').setValue(label, 'label').setValue(key, 'key');
414
+ var entriesArray = form.getLinkedRecords('entries');
415
+ entriesArray.push(field);
416
+ form.setLinkedRecords(entriesArray, 'entries');
417
+ }
418
+ if (ref.check === VALIDATING) {
419
+ form.setValue(true, 'isValidating');
420
+ }
421
+ field.setValue(ref.check, 'check').setValue(dataResult.error, 'error');
422
+ if (commitValue) field.setValue(dataResult.value, 'value');
423
+ });
424
+ }
425
+ function setValidate(newValidate) {
426
+ if (validate === newValidate && !firstSet) {
427
+ // first set only needs this
511
428
  return;
512
429
  }
513
- var data = snapshot.data;
514
- commitResetIntoRelay(data.form.entries, environment);
515
- }, [environment]);
516
- var subscribe = React__default["default"].useCallback(function (submit) {
517
- if (submit === void 0) {
518
- submit = false;
430
+ firstSet = false;
431
+ validate = newValidate;
432
+ // validation was called
433
+ if (ref.check === DONEVALIDATED && validate) {
434
+ ref.check = VALIDATING;
435
+ } else {
436
+ // reinit
437
+ ref.check = getInitCheck(validate);
519
438
  }
520
- var snapshot = environment.lookup(operationQueryForm.fragment);
521
- var subscription = ref.current.subscription;
522
- subscription && subscription.dispose();
523
- function dispose() {
524
- subscription && subscription.dispose();
525
- ref.current.subscription = null;
439
+ commitField();
440
+ }
441
+ function getData() {
442
+ return dataResult;
443
+ }
444
+ function changeData(value, error) {
445
+ dataResult = {
446
+ value: value,
447
+ error: error
448
+ };
449
+ forceUpdate();
450
+ }
451
+ function setValue(newValue) {
452
+ setValueInternal(newValue);
453
+ }
454
+ function setValueInternal(newValue, error) {
455
+ if (ref.check === DONEVALIDATED) {
456
+ ref.check = VALIDATING;
526
457
  }
527
- ref.current.subscription = environment.subscribe(snapshot, function (s) {
528
- return execute(environment, s, dispose, onSubmit);
529
- });
530
- internalValidate(snapshot, submit);
531
- execute(environment, snapshot, dispose, onSubmit);
532
- }, [environment, internalValidate, execute, onSubmit]);
533
- var validate = React__default["default"].useCallback(function () {
534
- if (!ref.current.isValidating) {
535
- subscribe(false);
458
+ changeData(newValue, error);
459
+ commitField();
460
+ }
461
+ function finalizeCheck(error) {
462
+ ref.isChecking = false;
463
+ ref.check = DONEVALIDATED;
464
+ if (dataResult.error !== error) {
465
+ changeData(dataResult.value, error);
536
466
  }
537
- }, [subscribe]);
538
- var submit = React__default["default"].useCallback(function (event) {
539
- if (event) {
540
- event.preventDefault();
467
+ commitField(false);
468
+ }
469
+ function internalValidate(value, validateFunction) {
470
+ ref.isChecking = true;
471
+ var result = validateFunction(value);
472
+ function internalFinalize(error) {
473
+ var validate = getValidate();
474
+ if (value !== dataResult.value || validate !== validateFunction) {
475
+ internalValidate(dataResult.value, validate);
476
+ return;
477
+ }
478
+ finalizeCheck(error);
541
479
  }
542
- if (!ref.current.isSubmitting) {
543
- ref.current.isSubmitting = true;
544
- subscribe(true);
480
+ if (isPromise(result)) {
481
+ result.then(internalFinalize).catch(internalFinalize);
482
+ } else {
483
+ internalFinalize(result);
545
484
  }
546
- }, [subscribe]);
547
- var result = React__default["default"].useMemo(function () {
548
- return {
549
- submit: submit,
550
- validate: validate,
551
- reset: reset
485
+ }
486
+ function subscribe() {
487
+ var snapshot = getSnapshot(environment, FragmentSet, key);
488
+ var disposeSubscrition = environment.subscribe(snapshot, function (s) {
489
+ var data = s.data;
490
+ var dataCheck = data.check;
491
+ var isValidating = dataCheck === VALIDATING;
492
+ var isReset = dataCheck === RESET;
493
+ ref.check = dataCheck;
494
+ var validate = getValidate();
495
+ if (isReset) {
496
+ ref.check = getInitCheck(validate);
497
+ setValueInternal(initialValue);
498
+ } else if (isValidating && !ref.isChecking) {
499
+ internalValidate(dataResult.value, validate);
500
+ }
501
+ }).dispose;
502
+ var dispose = function () {
503
+ disposeSubscrition();
504
+ commit(environment, function (store, form) {
505
+ var entriesArray = form.getLinkedRecords('entries');
506
+ var newEntries = entriesArray.filter(function (value) {
507
+ return value.getDataID() != localId;
508
+ });
509
+ form.setLinkedRecords(newEntries, 'entries');
510
+ store.delete(localId);
511
+ });
552
512
  };
553
- }, [submit, validate, reset]);
554
- return result;
555
- };
556
-
513
+ if (validateOnChange) {
514
+ internalValidate(initialValue, getValidate());
515
+ }
516
+ return dispose;
517
+ }
518
+ return {
519
+ subscribe: subscribe,
520
+ getData: getData,
521
+ setValue: setValue,
522
+ setValidate: setValidate
523
+ };
524
+ }
557
525
  function useFormSetValue(_a) {
558
526
  var key = _a.key,
559
527
  initialValue = _a.initialValue,
560
528
  validate = _a.validate,
561
- validateOnChange = _a.validateOnChange;
529
+ validateOnChange = _a.validateOnChange,
530
+ label = _a.label;
562
531
  var forceUpdate = useForceUpdate();
563
532
  var environment = useStore();
564
- var ref = React__default["default"].useRef({
565
- value: initialValue,
566
- error: undefined,
567
- check: validate ? 'INIT' : 'DONE',
568
- isChecking: false
569
- });
570
- var setValue = React__default["default"].useCallback(function (newValue) {
571
- ref.current.value = newValue;
572
- if (ref.current.check === 'DONE' && validate) {
573
- ref.current.check = 'START';
574
- }
575
- commitValue(key, newValue, ref.current.check, environment);
576
- forceUpdate();
577
- }, [environment, key, validate, forceUpdate]);
533
+ var resolver = React__default["default"].useMemo(function () {
534
+ return logicSetValue({
535
+ environment: environment,
536
+ key: key,
537
+ label: label,
538
+ initialValue: initialValue,
539
+ forceUpdate: forceUpdate,
540
+ validateOnChange: validateOnChange
541
+ });
542
+ }, [environment, key, initialValue, forceUpdate, validateOnChange, label]);
543
+ resolver.setValidate(validate);
578
544
  React__default["default"].useEffect(function () {
579
- //commitResetField(environment, key);
580
- commitValue(key, initialValue, ref.current.check, environment);
581
- var snapshot = getSnapshot(environment, FragmentSet, key);
582
- var disposeSubscrition = environment.subscribe(snapshot, function (s) {
583
- var check = s.data.check;
584
- var isStart = check === 'START';
585
- var isReset = check === 'RESET';
586
- ref.current.check = check;
587
- if (isReset) {
588
- ref.current.check = validate ? 'INIT' : 'DONE';
589
- setValue(initialValue);
590
- } else {
591
- if (!validate) {
592
- commitErrorIntoRelay(key, undefined, environment);
593
- return;
594
- }
595
- if (isStart && !ref.current.isChecking) {
596
- internalValidate(ref.current.value);
597
- }
598
- }
599
- }).dispose;
600
- var dispose = function () {
601
- disposeSubscrition();
602
- commitResetField(environment, key);
545
+ return resolver.subscribe();
546
+ }, [resolver]);
547
+ return [resolver.getData(), resolver.setValue];
548
+ }
549
+
550
+ function logicSubmit(environment, onSubmit) {
551
+ function dispose() {
552
+ subscription && subscription.dispose();
553
+ subscription = undefined;
554
+ }
555
+ var isSubmitting = false;
556
+ var subscription;
557
+ function execute(snapshot) {
558
+ var disposeSubmit = function () {
559
+ isSubmitting = false;
560
+ commit(environment, function (_, form) {
561
+ form.setValue(false, 'isSubmitting');
562
+ });
603
563
  };
604
- function finalizeCheck(error) {
605
- ref.current.isChecking = false;
606
- if (ref.current.error !== error) {
607
- ref.current.error = error;
608
- forceUpdate();
564
+ var data = snapshot.data;
565
+ var entries = data.form.entries;
566
+ var filtered = entries.filter(function (value) {
567
+ return isDone(value.check);
568
+ });
569
+ var isValidating = filtered.length !== entries.length;
570
+ var errors = entries.filter(function (value) {
571
+ return !!value.error;
572
+ }).map(function (value) {
573
+ return value.id;
574
+ });
575
+ var isValid = !isValidating && errors.length === 0;
576
+ commit(environment, function (store, form) {
577
+ form.setValue(isValidating, 'isValidating').setValue(isValid, 'isValid');
578
+ var errorFields = [];
579
+ errors.forEach(function (id) {
580
+ errorFields.push(store.get(id));
581
+ });
582
+ form.setLinkedRecords(errorFields, 'errors');
583
+ });
584
+ if (isValid && isSubmitting) {
585
+ dispose();
586
+ var result_1 = {};
587
+ entries.forEach(function (entry) {
588
+ result_1[entry.key] = entry.value;
589
+ });
590
+ var submit_1 = onSubmit(result_1);
591
+ if (isPromise(submit_1)) {
592
+ submit_1.then(disposeSubmit).catch(disposeSubmit);
593
+ return;
609
594
  }
610
- commitErrorIntoRelay(key, error, environment);
595
+ } else if (!isValidating) {
596
+ disposeSubmit();
611
597
  }
612
- function internalValidate(value) {
613
- ref.current.isChecking = true;
614
- var result = validate(value);
615
- function internalFinalize(error) {
616
- if (value !== ref.current.value) {
617
- internalValidate(ref.current.value);
618
- return;
619
- }
620
- finalizeCheck(error);
621
- }
622
- if (isPromise(result)) {
623
- result.then(internalFinalize).catch(internalFinalize);
624
- } else {
625
- internalFinalize(result);
626
- }
598
+ }
599
+ function reset() {
600
+ if (!isSubmitting) {
601
+ dispose();
602
+ commit(environment, function (_, form) {
603
+ form.setValue(false, 'isSubmitting').setValue(false, 'isValidating').setLinkedRecords([], 'errors').getLinkedRecords('entries').forEach(function (entry) {
604
+ return entry.setValue(RESET, 'check').setValue(undefined, 'error');
605
+ });
606
+ });
627
607
  }
628
- if (validateOnChange) {
629
- internalValidate(initialValue);
608
+ }
609
+ function validate() {
610
+ commit(environment, function (_, form) {
611
+ var tobeValitating = form.setValue(isSubmitting, 'isSubmitting').getLinkedRecords('entries').filter(function (value) {
612
+ return value.getValue('check') === TOBEVALIDATE;
613
+ });
614
+ form.setValue(tobeValitating.length === 0, 'isValidating');
615
+ tobeValitating.forEach(function (entry) {
616
+ return entry.setValue(VALIDATING, 'check');
617
+ });
618
+ });
619
+ var snapshot = environment.lookup(operationQueryForm.fragment);
620
+ if (!subscription) {
621
+ subscription = environment.subscribe(snapshot, function (s) {
622
+ return execute(s);
623
+ });
630
624
  }
631
- return dispose;
632
- }, [environment, initialValue, key, setValue, validate, validateOnChange, forceUpdate]);
633
- return [ref.current, setValue];
625
+ execute(snapshot);
626
+ }
627
+ function submit(event) {
628
+ event && event.preventDefault();
629
+ if (!isSubmitting) {
630
+ isSubmitting = true;
631
+ validate();
632
+ }
633
+ }
634
+ function subscribe() {
635
+ var disposeRetain = environment.retain(operationQueryForm).dispose;
636
+ return function () {
637
+ dispose();
638
+ disposeRetain();
639
+ };
640
+ }
641
+ var result = {
642
+ submit: submit,
643
+ validate: validate,
644
+ reset: reset
645
+ };
646
+ function getData() {
647
+ return result;
648
+ }
649
+ return {
650
+ subscribe: subscribe,
651
+ getData: getData
652
+ };
634
653
  }
654
+ var useFormSubmit = function (_a) {
655
+ var onSubmit = _a.onSubmit;
656
+ var environment = useStore();
657
+ var resolver = React__default["default"].useMemo(function () {
658
+ return logicSubmit(environment, onSubmit);
659
+ }, [environment, onSubmit]);
660
+ React__default["default"].useEffect(function () {
661
+ return resolver.subscribe();
662
+ }, [resolver]);
663
+ return resolver.getData();
664
+ };
635
665
 
636
666
  function useFormValue(key) {
637
667
  var environment = useStore();
@@ -645,7 +675,7 @@ function useFormValue(key) {
645
675
  return environment.subscribe(snapshot, function (s) {
646
676
  setData(s.data);
647
677
  }).dispose;
648
- }, [environment, snapshot, setData]);
678
+ }, [environment, snapshot]);
649
679
  return data;
650
680
  }
651
681
 
@@ -1048,6 +1078,19 @@ var RelayRecordSourceMutator = /** @class */function () {
1048
1078
  RelayRecordSourceMutator.prototype.getStatus = function (dataID) {
1049
1079
  return this._sink.has(dataID) ? this._sink.getStatus(dataID) : this._base.getStatus(dataID);
1050
1080
  };
1081
+ RelayRecordSourceMutator.prototype.getValue = function (dataID, storageKey) {
1082
+ for (var ii = 0; ii < this.__sources.length; ii++) {
1083
+ var record = this.__sources[ii].get(dataID);
1084
+ if (record) {
1085
+ var value = RelayModernRecord.getValue(record, storageKey);
1086
+ if (value !== undefined) {
1087
+ return value;
1088
+ }
1089
+ } else if (record === null) {
1090
+ return null;
1091
+ }
1092
+ }
1093
+ };
1051
1094
  RelayRecordSourceMutator.prototype.setValue = function (dataID, storageKey, value) {
1052
1095
  var sinkRecord = this._getSinkRecord(dataID);
1053
1096
  RelayModernRecord.setValue(sinkRecord, storageKey, value);
@@ -1097,6 +1140,9 @@ var RelayRecordProxy = /** @class */function () {
1097
1140
  this._mutator.setValue(this._dataID, name, value);
1098
1141
  return this;
1099
1142
  };
1143
+ RelayRecordProxy.prototype.getValue = function (name) {
1144
+ return this._mutator.getValue(this._dataID, name);
1145
+ };
1100
1146
  RelayRecordProxy.prototype.setLinkedRecord = function (record, name) {
1101
1147
  var linkedID = record.getDataID();
1102
1148
  this._mutator.setLinkedRecordID(this._dataID, name, linkedID);