relay-forms-nodeps 1.0.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 (96) hide show
  1. package/.babelrc.js +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +124 -0
  4. package/lib/RelayFormsTypes.d.ts +37 -0
  5. package/lib/RelayFormsTypes.js +5 -0
  6. package/lib/Utils.d.ts +11 -0
  7. package/lib/Utils.js +87 -0
  8. package/lib/es/RelayFormsTypes.d.ts +37 -0
  9. package/lib/es/RelayFormsTypes.js +0 -0
  10. package/lib/es/Utils.d.ts +11 -0
  11. package/lib/es/Utils.js +81 -0
  12. package/lib/es/index.d.ts +9 -0
  13. package/lib/es/index.js +7 -0
  14. package/lib/es/relay/RelayModernRecord.d.ts +107 -0
  15. package/lib/es/relay/RelayModernRecord.js +183 -0
  16. package/lib/es/relay/RelayModernSelector.d.ts +11 -0
  17. package/lib/es/relay/RelayModernSelector.js +29 -0
  18. package/lib/es/relay/RelayModernStore.d.ts +51 -0
  19. package/lib/es/relay/RelayModernStore.js +355 -0
  20. package/lib/es/relay/RelayReader.d.ts +14 -0
  21. package/lib/es/relay/RelayReader.js +86 -0
  22. package/lib/es/relay/RelayRecordProxy.d.ts +28 -0
  23. package/lib/es/relay/RelayRecordProxy.js +57 -0
  24. package/lib/es/relay/RelayRecordSource.d.ts +28 -0
  25. package/lib/es/relay/RelayRecordSource.js +70 -0
  26. package/lib/es/relay/RelayRecordSourceMutator.d.ts +36 -0
  27. package/lib/es/relay/RelayRecordSourceMutator.js +75 -0
  28. package/lib/es/relay/RelayRecordSourceProxy.d.ts +25 -0
  29. package/lib/es/relay/RelayRecordSourceProxy.js +52 -0
  30. package/lib/es/relay/RelayReferenceMarker.d.ts +10 -0
  31. package/lib/es/relay/RelayReferenceMarker.js +54 -0
  32. package/lib/es/relay/RelayStoreProvider.d.ts +7 -0
  33. package/lib/es/relay/RelayStoreProvider.js +16 -0
  34. package/lib/es/relay/RelayStoreUtils.d.ts +51 -0
  35. package/lib/es/relay/RelayStoreUtils.js +199 -0
  36. package/lib/es/relay/RelayTypes.d.ts +92 -0
  37. package/lib/es/relay/RelayTypes.js +0 -0
  38. package/lib/es/relay/queries.d.ts +86 -0
  39. package/lib/es/relay/queries.js +68 -0
  40. package/lib/es/useForceUpdate.d.ts +1 -0
  41. package/lib/es/useForceUpdate.js +8 -0
  42. package/lib/es/useFormSetValue.d.ts +2 -0
  43. package/lib/es/useFormSetValue.js +84 -0
  44. package/lib/es/useFormState.d.ts +2 -0
  45. package/lib/es/useFormState.js +49 -0
  46. package/lib/es/useFormSubmit.d.ts +2 -0
  47. package/lib/es/useFormSubmit.js +105 -0
  48. package/lib/es/useFormValue.d.ts +2 -0
  49. package/lib/es/useFormValue.js +19 -0
  50. package/lib/index.d.ts +9 -0
  51. package/lib/index.js +20 -0
  52. package/lib/relay/RelayModernRecord.d.ts +107 -0
  53. package/lib/relay/RelayModernRecord.js +188 -0
  54. package/lib/relay/RelayModernSelector.d.ts +11 -0
  55. package/lib/relay/RelayModernSelector.js +36 -0
  56. package/lib/relay/RelayModernStore.d.ts +51 -0
  57. package/lib/relay/RelayModernStore.js +359 -0
  58. package/lib/relay/RelayReader.d.ts +14 -0
  59. package/lib/relay/RelayReader.js +92 -0
  60. package/lib/relay/RelayRecordProxy.d.ts +28 -0
  61. package/lib/relay/RelayRecordProxy.js +60 -0
  62. package/lib/relay/RelayRecordSource.d.ts +28 -0
  63. package/lib/relay/RelayRecordSource.js +75 -0
  64. package/lib/relay/RelayRecordSourceMutator.d.ts +36 -0
  65. package/lib/relay/RelayRecordSourceMutator.js +80 -0
  66. package/lib/relay/RelayRecordSourceProxy.d.ts +25 -0
  67. package/lib/relay/RelayRecordSourceProxy.js +57 -0
  68. package/lib/relay/RelayReferenceMarker.d.ts +10 -0
  69. package/lib/relay/RelayReferenceMarker.js +60 -0
  70. package/lib/relay/RelayStoreProvider.d.ts +7 -0
  71. package/lib/relay/RelayStoreProvider.js +22 -0
  72. package/lib/relay/RelayStoreUtils.d.ts +51 -0
  73. package/lib/relay/RelayStoreUtils.js +208 -0
  74. package/lib/relay/RelayTypes.d.ts +92 -0
  75. package/lib/relay/RelayTypes.js +5 -0
  76. package/lib/relay/queries.d.ts +86 -0
  77. package/lib/relay/queries.js +73 -0
  78. package/lib/umd/relay-forms-nodeps.js +1478 -0
  79. package/lib/umd/relay-forms-nodeps.js.map +1 -0
  80. package/lib/umd/relay-forms-nodeps.min.js +2 -0
  81. package/lib/umd/relay-forms-nodeps.min.js.map +1 -0
  82. package/lib/useForceUpdate.d.ts +1 -0
  83. package/lib/useForceUpdate.js +14 -0
  84. package/lib/useFormSetValue.d.ts +2 -0
  85. package/lib/useFormSetValue.js +90 -0
  86. package/lib/useFormState.d.ts +2 -0
  87. package/lib/useFormState.js +54 -0
  88. package/lib/useFormSubmit.d.ts +2 -0
  89. package/lib/useFormSubmit.js +110 -0
  90. package/lib/useFormValue.d.ts +2 -0
  91. package/lib/useFormValue.js +25 -0
  92. package/package.json +89 -0
  93. package/replace.config.js +5 -0
  94. package/rollup.config.js +92 -0
  95. package/tsconfig.esm.json +7 -0
  96. package/yarn-error.log +127 -0
package/.babelrc.js ADDED
@@ -0,0 +1,5 @@
1
+ const plugin = require('babel-preset-fbjs/plugins/dev-expression');
2
+
3
+ module.exports = {
4
+ plugins: [plugin]
5
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Lorenzo Di Giacomo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # relay-forms-nodeps ![](https://github.com/morrys/relay-forms/workflows/Build/badge.svg)
2
+ Build forms in React with Relay
3
+
4
+ ## Installation
5
+
6
+ Install relay-forms-nodeps using yarn or npm:
7
+
8
+ ```
9
+ yarn add relay-forms-nodeps
10
+ ```
11
+
12
+ ## Contributing
13
+
14
+ * **Give a star** to the repository and **share it**, you will **help** the **project** and the **people** who will find it useful
15
+
16
+ * **Create issues**, your **questions** are a **valuable help**
17
+
18
+ * **PRs are welcome**, but it is always **better to open the issue first** so as to **help** me and other people **evaluating it**
19
+
20
+ * **Please sponsor me**
21
+
22
+ ## Simple Example
23
+
24
+ ```ts
25
+ import * as React from 'react';
26
+ import { useCallback } from 'react';
27
+ import { Store, createStore, useFormSubmit, useFormState, useFormSetValue, StoreProvider } from 'relay-forms-nodeps';
28
+
29
+ export const store: Store = createStore();
30
+
31
+ export const Form: React.FC = () => {
32
+ const [state, setState] = React.useState(undefined);
33
+ return (
34
+ <StoreProvider store={store}>
35
+ <FormInternal
36
+ onSubmit={setState}
37
+ />
38
+ {state && <div data-testid={'submit-done'}>SUBMIT :)</div>}
39
+ </StoreProvider>
40
+ );
41
+ };
42
+
43
+ export const HAVE_ERRORS = 'have errors';
44
+
45
+ export const Errors: React.FC<any> = () => {
46
+ const { errors, isSubmitting, isValidating } = useFormState();
47
+ return (
48
+ <>
49
+ <div>{errors ? HAVE_ERRORS : ''}</div>;
50
+ <div>{'' + isSubmitting}</div>;
51
+ <div>{'' + isValidating}</div>;
52
+ </>
53
+ );
54
+ };
55
+
56
+ const validateField = (value: any, name: string) => {
57
+ if (value && value.length < 5) {
58
+ return getFieldError(name, value);
59
+ }
60
+ return undefined;
61
+ });
62
+
63
+ export const FormInternal: React.FC<any> = ({ onSubmit }) => {
64
+ const data = useFormSubmit({ onSubmit });
65
+
66
+ return (
67
+ <form onSubmit={data.submit} action="#">
68
+ <div>
69
+ <Field fieldKey="firstName" placeholder="first name" validate={validateField} />
70
+ </div>
71
+ <div>
72
+ <Field fieldKey="lastName" placeholder="last name" />
73
+ </div>
74
+ <div>
75
+ <Field fieldKey="email" placeholder="email" validate={validateField} />
76
+ </div>
77
+ <Errors />
78
+ <button type="button" data-testid={'button-validate'} onClick={data.validate}>
79
+ only validate
80
+ </button>
81
+ <button data-testid={'button-submit'} type="submit">
82
+ submit
83
+ </button>
84
+ </form>
85
+ );
86
+ };
87
+
88
+ export const getFieldError = (name, value) =>
89
+ name + ' wrong length, minimum 5 current ' + value.length;
90
+
91
+ export const Field: React.FC<any> = ({ placeholder, fieldKey, validate }) => {
92
+ const validateCallback = useCallback(
93
+ (value: any) => {
94
+ return validate(value, fieldKey);
95
+ },
96
+ [fieldKey, validate],
97
+ );
98
+
99
+ const [{ error }, setValue] = useFormSetValue({
100
+ key: fieldKey,
101
+ validate: validate ? validateCallback : undefined,
102
+ initialValue: "try",
103
+ });
104
+
105
+ const setValueCallback = useCallback(
106
+ (event) => {
107
+ const value = event.target.value;
108
+ setValue(value);
109
+ },
110
+ [setValue],
111
+ );
112
+ return (
113
+ <>
114
+ {error && <div>{error}</div>}
115
+ <input
116
+ type="text"
117
+ value="try"
118
+ placeholder={placeholder}
119
+ onChange={(value) => setValueCallback(value)}
120
+ />
121
+ </>
122
+ );
123
+ };
124
+ ```
@@ -0,0 +1,37 @@
1
+ /// <reference types="react" />
2
+ export declare type FunctionOnSubmit<ValueType> = (values: ValueType) => Promise<void> | void;
3
+ export declare type FormSubmitOptions<ValueType> = {
4
+ onSubmit: FunctionOnSubmit<ValueType>;
5
+ };
6
+ export declare type FormSubmitReturn = {
7
+ submit: (event?: React.BaseSyntheticEvent<any, any, any>) => void;
8
+ validate: () => void;
9
+ reset: () => void;
10
+ };
11
+ export declare type FormSetValueOptions<ValueType> = {
12
+ key: string;
13
+ initialValue?: ValueType;
14
+ validate?: (value: ValueType) => Promise<string | undefined> | string | undefined;
15
+ validateOnChange?: boolean;
16
+ };
17
+ export declare type FormSetValueStateReturn<ValueType> = {
18
+ error: undefined | null | Error;
19
+ value?: ValueType;
20
+ };
21
+ export declare type FormValueStateReturn<ValueType> = {
22
+ readonly id: string;
23
+ readonly value: ValueType | null;
24
+ readonly error: string | null;
25
+ };
26
+ export declare type FormSetValueFunctionReturn<ValueType> = (newValue: ValueType) => void;
27
+ export declare type FormSetValueReturn<ValueType> = [FormSetValueStateReturn<ValueType>, FormSetValueFunctionReturn<ValueType>];
28
+ export declare type FormStateReturn = {
29
+ errors: ReadonlyArray<{
30
+ readonly id: string;
31
+ readonly key: string;
32
+ readonly error: string | null;
33
+ } | null | undefined>;
34
+ isValidating: boolean;
35
+ isSubmitting: boolean;
36
+ isValid: boolean;
37
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/lib/Utils.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { Store, Snapshot } from './relay/RelayTypes';
2
+ export declare function getSnapshot(environment: Store, fragment: any, key: string): Snapshot;
3
+ export declare const commitResetIntoRelay: (entries: any, environment: any) => void;
4
+ export declare const commitValidateIntoRelay: (entries: any, isSubmitting: any, environment: any) => void;
5
+ export declare const commitSubmitEndRelay: (environment: any) => void;
6
+ export declare const commitValidateEndRelay: (environment: any) => void;
7
+ export declare const commitResetField: (environment: any, key: any) => void;
8
+ export declare const commitValue: (key: any, value: any, check: any, environment: any) => void;
9
+ export declare const commitErrorIntoRelay: (key: any, error: any, environment: any) => void;
10
+ export declare const operationQueryForm: any;
11
+ export declare const operationQueryErrorsForm: any;
package/lib/Utils.js ADDED
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var queries_1 = require("./relay/queries");
7
+ var RelayModernSelector_1 = require("./relay/RelayModernSelector");
8
+ var PREFIX_LOCAL_FORM = 'local:form';
9
+ var internalCommitLocalUpdate = function (environment, updater) {
10
+ environment.commitUpdate(function (store) {
11
+ var localForm = store.get(PREFIX_LOCAL_FORM);
12
+ if (!localForm) {
13
+ localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries');
14
+ store.getRoot().setLinkedRecord(localForm, 'form');
15
+ }
16
+ updater(store, localForm);
17
+ });
18
+ };
19
+ function getFieldId(key) {
20
+ return PREFIX_LOCAL_FORM + '.' + key;
21
+ }
22
+ function getSnapshot(environment, fragment, key) {
23
+ var item = {
24
+ __id: getFieldId(key)
25
+ };
26
+ return environment.lookup(RelayModernSelector_1.getSingularSelector(fragment, item));
27
+ }
28
+ exports.getSnapshot = getSnapshot;
29
+ exports.commitResetIntoRelay = function (entries, environment) {
30
+ internalCommitLocalUpdate(environment, function (store, form) {
31
+ form.setValue(false, 'isSubmitting');
32
+ form.setValue(false, 'isValidating');
33
+ entries.forEach(function (entry) {
34
+ return store.get(getFieldId(entry.key)).setValue('RESET', 'check');
35
+ });
36
+ });
37
+ };
38
+ exports.commitValidateIntoRelay = function (entries, isSubmitting, environment) {
39
+ internalCommitLocalUpdate(environment, function (store, form) {
40
+ form.setValue(isSubmitting, 'isSubmitting');
41
+ form.setValue(true, 'isValidating');
42
+ entries.forEach(function (entry) {
43
+ return store.get(getFieldId(entry.key)).setValue('START', 'check');
44
+ });
45
+ });
46
+ };
47
+ exports.commitSubmitEndRelay = function (environment) {
48
+ internalCommitLocalUpdate(environment, function (_, form) {
49
+ form.setValue(false, 'isSubmitting');
50
+ });
51
+ };
52
+ exports.commitValidateEndRelay = function (environment) {
53
+ internalCommitLocalUpdate(environment, function (_, form) {
54
+ form.setValue(false, 'isValidating');
55
+ });
56
+ };
57
+ exports.commitResetField = function (environment, key) {
58
+ var id = getFieldId(key);
59
+ internalCommitLocalUpdate(environment, function (store, form) {
60
+ var entriesArray = form.getLinkedRecords('entries');
61
+ var newEntries = entriesArray.filter(function (value) {
62
+ return value.getDataID() != id;
63
+ });
64
+ form.setLinkedRecords(newEntries, 'entries');
65
+ store.delete(id);
66
+ });
67
+ };
68
+ exports.commitValue = function (key, value, check, environment) {
69
+ var id = getFieldId(key);
70
+ internalCommitLocalUpdate(environment, function (store, form) {
71
+ var field = store.get(id);
72
+ if (!field) {
73
+ field = store.create(id);
74
+ var entriesArray = form.getLinkedRecords('entries');
75
+ entriesArray.push(field);
76
+ form.setLinkedRecords(entriesArray, 'entries');
77
+ }
78
+ field.setValue(id, 'id').setValue(key, 'key').setValue(check, 'check').setValue(value, 'value');
79
+ });
80
+ };
81
+ exports.commitErrorIntoRelay = function (key, error, environment) {
82
+ internalCommitLocalUpdate(environment, function (store) {
83
+ store.get(getFieldId(key)).setValue(error, 'error').setValue('DONE', 'check');
84
+ });
85
+ };
86
+ exports.operationQueryForm = RelayModernSelector_1.createOperationDescriptor(queries_1.QueryFields);
87
+ exports.operationQueryErrorsForm = RelayModernSelector_1.createOperationDescriptor(queries_1.QueryErrors);
@@ -0,0 +1,37 @@
1
+ /// <reference types="react" />
2
+ export declare type FunctionOnSubmit<ValueType> = (values: ValueType) => Promise<void> | void;
3
+ export declare type FormSubmitOptions<ValueType> = {
4
+ onSubmit: FunctionOnSubmit<ValueType>;
5
+ };
6
+ export declare type FormSubmitReturn = {
7
+ submit: (event?: React.BaseSyntheticEvent<any, any, any>) => void;
8
+ validate: () => void;
9
+ reset: () => void;
10
+ };
11
+ export declare type FormSetValueOptions<ValueType> = {
12
+ key: string;
13
+ initialValue?: ValueType;
14
+ validate?: (value: ValueType) => Promise<string | undefined> | string | undefined;
15
+ validateOnChange?: boolean;
16
+ };
17
+ export declare type FormSetValueStateReturn<ValueType> = {
18
+ error: undefined | null | Error;
19
+ value?: ValueType;
20
+ };
21
+ export declare type FormValueStateReturn<ValueType> = {
22
+ readonly id: string;
23
+ readonly value: ValueType | null;
24
+ readonly error: string | null;
25
+ };
26
+ export declare type FormSetValueFunctionReturn<ValueType> = (newValue: ValueType) => void;
27
+ export declare type FormSetValueReturn<ValueType> = [FormSetValueStateReturn<ValueType>, FormSetValueFunctionReturn<ValueType>];
28
+ export declare type FormStateReturn = {
29
+ errors: ReadonlyArray<{
30
+ readonly id: string;
31
+ readonly key: string;
32
+ readonly error: string | null;
33
+ } | null | undefined>;
34
+ isValidating: boolean;
35
+ isSubmitting: boolean;
36
+ isValid: boolean;
37
+ };
File without changes
@@ -0,0 +1,11 @@
1
+ import { Store, Snapshot } from './relay/RelayTypes';
2
+ export declare function getSnapshot(environment: Store, fragment: any, key: string): Snapshot;
3
+ export declare const commitResetIntoRelay: (entries: any, environment: any) => void;
4
+ export declare const commitValidateIntoRelay: (entries: any, isSubmitting: any, environment: any) => void;
5
+ export declare const commitSubmitEndRelay: (environment: any) => void;
6
+ export declare const commitValidateEndRelay: (environment: any) => void;
7
+ export declare const commitResetField: (environment: any, key: any) => void;
8
+ export declare const commitValue: (key: any, value: any, check: any, environment: any) => void;
9
+ export declare const commitErrorIntoRelay: (key: any, error: any, environment: any) => void;
10
+ export declare const operationQueryForm: any;
11
+ export declare const operationQueryErrorsForm: any;
@@ -0,0 +1,81 @@
1
+ import { QueryErrors, QueryFields } from './relay/queries';
2
+ import { getSingularSelector, createOperationDescriptor } from './relay/RelayModernSelector';
3
+ var PREFIX_LOCAL_FORM = 'local:form';
4
+ var internalCommitLocalUpdate = function (environment, updater) {
5
+ environment.commitUpdate(function (store) {
6
+ var localForm = store.get(PREFIX_LOCAL_FORM);
7
+ if (!localForm) {
8
+ localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries');
9
+ store.getRoot().setLinkedRecord(localForm, 'form');
10
+ }
11
+ updater(store, localForm);
12
+ });
13
+ };
14
+ function getFieldId(key) {
15
+ return PREFIX_LOCAL_FORM + '.' + key;
16
+ }
17
+ export function getSnapshot(environment, fragment, key) {
18
+ var item = {
19
+ __id: getFieldId(key)
20
+ };
21
+ return environment.lookup(getSingularSelector(fragment, item));
22
+ }
23
+ export var commitResetIntoRelay = function (entries, environment) {
24
+ internalCommitLocalUpdate(environment, function (store, form) {
25
+ form.setValue(false, 'isSubmitting');
26
+ form.setValue(false, 'isValidating');
27
+ entries.forEach(function (entry) {
28
+ return store.get(getFieldId(entry.key)).setValue('RESET', 'check');
29
+ });
30
+ });
31
+ };
32
+ export var commitValidateIntoRelay = function (entries, isSubmitting, environment) {
33
+ internalCommitLocalUpdate(environment, function (store, form) {
34
+ form.setValue(isSubmitting, 'isSubmitting');
35
+ form.setValue(true, 'isValidating');
36
+ entries.forEach(function (entry) {
37
+ return store.get(getFieldId(entry.key)).setValue('START', 'check');
38
+ });
39
+ });
40
+ };
41
+ export var commitSubmitEndRelay = function (environment) {
42
+ internalCommitLocalUpdate(environment, function (_, form) {
43
+ form.setValue(false, 'isSubmitting');
44
+ });
45
+ };
46
+ export var commitValidateEndRelay = function (environment) {
47
+ internalCommitLocalUpdate(environment, function (_, form) {
48
+ form.setValue(false, 'isValidating');
49
+ });
50
+ };
51
+ export var commitResetField = function (environment, key) {
52
+ var id = getFieldId(key);
53
+ internalCommitLocalUpdate(environment, function (store, form) {
54
+ var entriesArray = form.getLinkedRecords('entries');
55
+ var newEntries = entriesArray.filter(function (value) {
56
+ return value.getDataID() != id;
57
+ });
58
+ form.setLinkedRecords(newEntries, 'entries');
59
+ store.delete(id);
60
+ });
61
+ };
62
+ export var commitValue = function (key, value, check, environment) {
63
+ var id = getFieldId(key);
64
+ internalCommitLocalUpdate(environment, function (store, form) {
65
+ var field = store.get(id);
66
+ if (!field) {
67
+ field = store.create(id);
68
+ var entriesArray = form.getLinkedRecords('entries');
69
+ entriesArray.push(field);
70
+ form.setLinkedRecords(entriesArray, 'entries');
71
+ }
72
+ field.setValue(id, 'id').setValue(key, 'key').setValue(check, 'check').setValue(value, 'value');
73
+ });
74
+ };
75
+ export var commitErrorIntoRelay = function (key, error, environment) {
76
+ internalCommitLocalUpdate(environment, function (store) {
77
+ store.get(getFieldId(key)).setValue(error, 'error').setValue('DONE', 'check');
78
+ });
79
+ };
80
+ export var operationQueryForm = createOperationDescriptor(QueryFields);
81
+ export var operationQueryErrorsForm = createOperationDescriptor(QueryErrors);
@@ -0,0 +1,9 @@
1
+ export { useFormState } from './useFormState';
2
+ export { useFormSubmit } from './useFormSubmit';
3
+ export { useFormSetValue } from './useFormSetValue';
4
+ export { useFormValue } from './useFormValue';
5
+ export { StoreProvider } from './relay/RelayStoreProvider';
6
+ export { RelayModernStore as Store, createStore } from './relay/RelayModernStore';
7
+ export { RelayRecordSource as RecordSource } from './relay/RelayRecordSource';
8
+ export * from './RelayFormsTypes';
9
+ export * from './relay/RelayTypes';
@@ -0,0 +1,7 @@
1
+ export { useFormState } from './useFormState';
2
+ export { useFormSubmit } from './useFormSubmit';
3
+ export { useFormSetValue } from './useFormSetValue';
4
+ export { useFormValue } from './useFormValue';
5
+ export { StoreProvider } from './relay/RelayStoreProvider';
6
+ export { RelayModernStore as Store, createStore } from './relay/RelayModernStore';
7
+ export { RelayRecordSource as RecordSource } from './relay/RelayRecordSource';
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @public
3
+ *
4
+ * Low-level record manipulation methods.
5
+ *
6
+ * A note about perf: we use long-hand property access rather than computed
7
+ * properties in this file for speed ie.
8
+ *
9
+ * const object = {};
10
+ * object[KEY] = value;
11
+ * record[storageKey] = object;
12
+ *
13
+ * instead of:
14
+ *
15
+ * record[storageKey] = {
16
+ * [KEY]: value,
17
+ * };
18
+ *
19
+ * The latter gets transformed by Babel into something like:
20
+ *
21
+ * function _defineProperty(obj, key, value) {
22
+ * if (key in obj) {
23
+ * Object.defineProperty(obj, key, {
24
+ * value: value,
25
+ * enumerable: true,
26
+ * configurable: true,
27
+ * writable: true,
28
+ * });
29
+ * } else {
30
+ * obj[key] = value;
31
+ * }
32
+ * return obj;
33
+ * }
34
+ *
35
+ * record[storageKey] = _defineProperty({}, KEY, value);
36
+ *
37
+ * A quick benchmark shows that computed property access is an order of
38
+ * magnitude slower (times in seconds for 100,000 iterations):
39
+ *
40
+ * best avg sd
41
+ * computed 0.02175 0.02292 0.00113
42
+ * manual 0.00110 0.00123 0.00008
43
+ */
44
+ /**
45
+ * @public
46
+ *
47
+ * Create a new record.
48
+ */
49
+ declare function create(dataID: any): {};
50
+ /**
51
+ * @public
52
+ *
53
+ * Get a scalar (non-link) field value.
54
+ */
55
+ declare function getValue(record: any, storageKey: any): any;
56
+ /**
57
+ * @public
58
+ *
59
+ * Get the value of a field as a reference to another record. Throws if the
60
+ * field has a different type.
61
+ */
62
+ declare function getLinkedRecordID(record: any, storageKey: any): any;
63
+ /**
64
+ * @public
65
+ *
66
+ * Get the value of a field as a list of references to other records. Throws if
67
+ * the field has a different type.
68
+ */
69
+ declare function getLinkedRecordIDs(record: any, storageKey: string): any;
70
+ /**
71
+ * @public
72
+ *
73
+ * Compares the fields of a previous and new record, returning either the
74
+ * previous record if all fields are equal or a new record (with merged fields)
75
+ * if any fields have changed.
76
+ */
77
+ declare function update(prevRecord: any, nextRecord: any): any;
78
+ /**
79
+ * @public
80
+ *
81
+ * Set the value of a storageKey to a scalar.
82
+ * YES
83
+ */
84
+ declare function setValue(record: any, storageKey: any, value: any): void;
85
+ /**
86
+ * @public
87
+ *
88
+ * Set the value of a field to a reference to another record.
89
+ */
90
+ declare function setLinkedRecordID(record: any, storageKey: string, linkedID: any): void;
91
+ /**
92
+ * @public
93
+ *
94
+ * Set the value of a field to a list of references other records.
95
+ */
96
+ declare function setLinkedRecordIDs(record: any, storageKey: string, linkedIDs: any): void;
97
+ export declare const RelayModernRecord: {
98
+ create: typeof create;
99
+ getLinkedRecordID: typeof getLinkedRecordID;
100
+ getLinkedRecordIDs: typeof getLinkedRecordIDs;
101
+ getValue: typeof getValue;
102
+ setValue: typeof setValue;
103
+ setLinkedRecordID: typeof setLinkedRecordID;
104
+ setLinkedRecordIDs: typeof setLinkedRecordIDs;
105
+ update: typeof update;
106
+ };
107
+ export {};