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.
- package/.babelrc.js +5 -0
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/lib/RelayFormsTypes.d.ts +37 -0
- package/lib/RelayFormsTypes.js +5 -0
- package/lib/Utils.d.ts +11 -0
- package/lib/Utils.js +87 -0
- package/lib/es/RelayFormsTypes.d.ts +37 -0
- package/lib/es/RelayFormsTypes.js +0 -0
- package/lib/es/Utils.d.ts +11 -0
- package/lib/es/Utils.js +81 -0
- package/lib/es/index.d.ts +9 -0
- package/lib/es/index.js +7 -0
- package/lib/es/relay/RelayModernRecord.d.ts +107 -0
- package/lib/es/relay/RelayModernRecord.js +183 -0
- package/lib/es/relay/RelayModernSelector.d.ts +11 -0
- package/lib/es/relay/RelayModernSelector.js +29 -0
- package/lib/es/relay/RelayModernStore.d.ts +51 -0
- package/lib/es/relay/RelayModernStore.js +355 -0
- package/lib/es/relay/RelayReader.d.ts +14 -0
- package/lib/es/relay/RelayReader.js +86 -0
- package/lib/es/relay/RelayRecordProxy.d.ts +28 -0
- package/lib/es/relay/RelayRecordProxy.js +57 -0
- package/lib/es/relay/RelayRecordSource.d.ts +28 -0
- package/lib/es/relay/RelayRecordSource.js +70 -0
- package/lib/es/relay/RelayRecordSourceMutator.d.ts +36 -0
- package/lib/es/relay/RelayRecordSourceMutator.js +75 -0
- package/lib/es/relay/RelayRecordSourceProxy.d.ts +25 -0
- package/lib/es/relay/RelayRecordSourceProxy.js +52 -0
- package/lib/es/relay/RelayReferenceMarker.d.ts +10 -0
- package/lib/es/relay/RelayReferenceMarker.js +54 -0
- package/lib/es/relay/RelayStoreProvider.d.ts +7 -0
- package/lib/es/relay/RelayStoreProvider.js +16 -0
- package/lib/es/relay/RelayStoreUtils.d.ts +51 -0
- package/lib/es/relay/RelayStoreUtils.js +199 -0
- package/lib/es/relay/RelayTypes.d.ts +92 -0
- package/lib/es/relay/RelayTypes.js +0 -0
- package/lib/es/relay/queries.d.ts +86 -0
- package/lib/es/relay/queries.js +68 -0
- package/lib/es/useForceUpdate.d.ts +1 -0
- package/lib/es/useForceUpdate.js +8 -0
- package/lib/es/useFormSetValue.d.ts +2 -0
- package/lib/es/useFormSetValue.js +84 -0
- package/lib/es/useFormState.d.ts +2 -0
- package/lib/es/useFormState.js +49 -0
- package/lib/es/useFormSubmit.d.ts +2 -0
- package/lib/es/useFormSubmit.js +105 -0
- package/lib/es/useFormValue.d.ts +2 -0
- package/lib/es/useFormValue.js +19 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +20 -0
- package/lib/relay/RelayModernRecord.d.ts +107 -0
- package/lib/relay/RelayModernRecord.js +188 -0
- package/lib/relay/RelayModernSelector.d.ts +11 -0
- package/lib/relay/RelayModernSelector.js +36 -0
- package/lib/relay/RelayModernStore.d.ts +51 -0
- package/lib/relay/RelayModernStore.js +359 -0
- package/lib/relay/RelayReader.d.ts +14 -0
- package/lib/relay/RelayReader.js +92 -0
- package/lib/relay/RelayRecordProxy.d.ts +28 -0
- package/lib/relay/RelayRecordProxy.js +60 -0
- package/lib/relay/RelayRecordSource.d.ts +28 -0
- package/lib/relay/RelayRecordSource.js +75 -0
- package/lib/relay/RelayRecordSourceMutator.d.ts +36 -0
- package/lib/relay/RelayRecordSourceMutator.js +80 -0
- package/lib/relay/RelayRecordSourceProxy.d.ts +25 -0
- package/lib/relay/RelayRecordSourceProxy.js +57 -0
- package/lib/relay/RelayReferenceMarker.d.ts +10 -0
- package/lib/relay/RelayReferenceMarker.js +60 -0
- package/lib/relay/RelayStoreProvider.d.ts +7 -0
- package/lib/relay/RelayStoreProvider.js +22 -0
- package/lib/relay/RelayStoreUtils.d.ts +51 -0
- package/lib/relay/RelayStoreUtils.js +208 -0
- package/lib/relay/RelayTypes.d.ts +92 -0
- package/lib/relay/RelayTypes.js +5 -0
- package/lib/relay/queries.d.ts +86 -0
- package/lib/relay/queries.js +73 -0
- package/lib/umd/relay-forms-nodeps.js +1478 -0
- package/lib/umd/relay-forms-nodeps.js.map +1 -0
- package/lib/umd/relay-forms-nodeps.min.js +2 -0
- package/lib/umd/relay-forms-nodeps.min.js.map +1 -0
- package/lib/useForceUpdate.d.ts +1 -0
- package/lib/useForceUpdate.js +14 -0
- package/lib/useFormSetValue.d.ts +2 -0
- package/lib/useFormSetValue.js +90 -0
- package/lib/useFormState.d.ts +2 -0
- package/lib/useFormState.js +54 -0
- package/lib/useFormSubmit.d.ts +2 -0
- package/lib/useFormSubmit.js +110 -0
- package/lib/useFormValue.d.ts +2 -0
- package/lib/useFormValue.js +25 -0
- package/package.json +89 -0
- package/replace.config.js +5 -0
- package/rollup.config.js +92 -0
- package/tsconfig.esm.json +7 -0
- package/yarn-error.log +127 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useStore } from './relay/RelayStoreProvider';
|
|
3
|
+
import { isPromise } from './relay/RelayStoreUtils';
|
|
4
|
+
import { commitValidateEndRelay, commitValidateIntoRelay, commitSubmitEndRelay, operationQueryForm, commitResetIntoRelay } from './Utils';
|
|
5
|
+
export var useFormSubmit = function (_a) {
|
|
6
|
+
var onSubmit = _a.onSubmit;
|
|
7
|
+
var environment = useStore();
|
|
8
|
+
React.useEffect(function () {
|
|
9
|
+
return environment.retain(operationQueryForm).dispose;
|
|
10
|
+
}, [environment]);
|
|
11
|
+
var ref = React.useRef({
|
|
12
|
+
isSubmitting: false,
|
|
13
|
+
isValidating: false,
|
|
14
|
+
error: undefined,
|
|
15
|
+
subscription: undefined
|
|
16
|
+
});
|
|
17
|
+
var internalValidate = React.useCallback(function (snapshot, isSubmitting) {
|
|
18
|
+
ref.current.isValidating = true;
|
|
19
|
+
var data = snapshot.data;
|
|
20
|
+
var filtered = data.form.entries.filter(function (value) {
|
|
21
|
+
return value.check === 'INIT';
|
|
22
|
+
});
|
|
23
|
+
commitValidateIntoRelay(filtered, isSubmitting, environment);
|
|
24
|
+
}, [environment]);
|
|
25
|
+
var execute = React.useCallback(function (environment, snapshot, dispose, onSubmit) {
|
|
26
|
+
var data = snapshot.data;
|
|
27
|
+
var entries = data.form.entries;
|
|
28
|
+
var filtered = entries.filter(function (value) {
|
|
29
|
+
return value.check === 'DONE';
|
|
30
|
+
});
|
|
31
|
+
if (filtered.length === entries.length) {
|
|
32
|
+
var errors = entries.filter(function (value) {
|
|
33
|
+
return !!value.error;
|
|
34
|
+
});
|
|
35
|
+
commitValidateEndRelay(environment);
|
|
36
|
+
ref.current.isValidating = false;
|
|
37
|
+
var internalDispose = function () {
|
|
38
|
+
dispose();
|
|
39
|
+
if (ref.current.isSubmitting) {
|
|
40
|
+
ref.current.isSubmitting = false;
|
|
41
|
+
commitSubmitEndRelay(environment);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
if (ref.current.isSubmitting && onSubmit && errors.length === 0) {
|
|
45
|
+
var result_1 = {};
|
|
46
|
+
entries.forEach(function (entry) {
|
|
47
|
+
result_1[entry.key] = entry.value;
|
|
48
|
+
});
|
|
49
|
+
var submit_1 = onSubmit(result_1);
|
|
50
|
+
if (isPromise(submit_1)) {
|
|
51
|
+
submit_1.then(internalDispose).catch(internalDispose);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
internalDispose();
|
|
56
|
+
}
|
|
57
|
+
}, []);
|
|
58
|
+
var reset = React.useCallback(function () {
|
|
59
|
+
var snapshot = environment.lookup(operationQueryForm.fragment);
|
|
60
|
+
if (ref.current.isValidating && ref.current.isSubmitting) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
var data = snapshot.data;
|
|
64
|
+
commitResetIntoRelay(data.form.entries, environment);
|
|
65
|
+
}, [environment]);
|
|
66
|
+
var subscribe = React.useCallback(function (submit) {
|
|
67
|
+
if (submit === void 0) {
|
|
68
|
+
submit = false;
|
|
69
|
+
}
|
|
70
|
+
var snapshot = environment.lookup(operationQueryForm.fragment);
|
|
71
|
+
var subscription = ref.current.subscription;
|
|
72
|
+
subscription && subscription.dispose();
|
|
73
|
+
function dispose() {
|
|
74
|
+
subscription && subscription.dispose();
|
|
75
|
+
ref.current.subscription = null;
|
|
76
|
+
}
|
|
77
|
+
ref.current.subscription = environment.subscribe(snapshot, function (s) {
|
|
78
|
+
return execute(environment, s, dispose, onSubmit);
|
|
79
|
+
});
|
|
80
|
+
internalValidate(snapshot, submit);
|
|
81
|
+
execute(environment, snapshot, dispose, onSubmit);
|
|
82
|
+
}, [environment, internalValidate, execute, onSubmit]);
|
|
83
|
+
var validate = React.useCallback(function () {
|
|
84
|
+
if (!ref.current.isValidating) {
|
|
85
|
+
subscribe(false);
|
|
86
|
+
}
|
|
87
|
+
}, [subscribe]);
|
|
88
|
+
var submit = React.useCallback(function (event) {
|
|
89
|
+
if (event) {
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
}
|
|
92
|
+
if (!ref.current.isSubmitting) {
|
|
93
|
+
ref.current.isSubmitting = true;
|
|
94
|
+
subscribe(true);
|
|
95
|
+
}
|
|
96
|
+
}, [subscribe]);
|
|
97
|
+
var result = React.useMemo(function () {
|
|
98
|
+
return {
|
|
99
|
+
submit: submit,
|
|
100
|
+
validate: validate,
|
|
101
|
+
reset: reset
|
|
102
|
+
};
|
|
103
|
+
}, [submit, validate, reset]);
|
|
104
|
+
return result;
|
|
105
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FragmentValue } from './relay/queries';
|
|
3
|
+
import { useStore } from './relay/RelayStoreProvider';
|
|
4
|
+
import { getSnapshot } from './Utils';
|
|
5
|
+
export function useFormValue(key) {
|
|
6
|
+
var environment = useStore();
|
|
7
|
+
var snapshot = React.useMemo(function () {
|
|
8
|
+
return getSnapshot(environment, FragmentValue, key);
|
|
9
|
+
}, [key, environment]);
|
|
10
|
+
var _a = React.useState(snapshot.data),
|
|
11
|
+
data = _a[0],
|
|
12
|
+
setData = _a[1];
|
|
13
|
+
React.useEffect(function () {
|
|
14
|
+
return environment.subscribe(snapshot, function (s) {
|
|
15
|
+
setData(s.data);
|
|
16
|
+
}).dispose;
|
|
17
|
+
}, [environment, snapshot, setData]);
|
|
18
|
+
return data;
|
|
19
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -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';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var useFormState_1 = require("./useFormState");
|
|
7
|
+
exports.useFormState = useFormState_1.useFormState;
|
|
8
|
+
var useFormSubmit_1 = require("./useFormSubmit");
|
|
9
|
+
exports.useFormSubmit = useFormSubmit_1.useFormSubmit;
|
|
10
|
+
var useFormSetValue_1 = require("./useFormSetValue");
|
|
11
|
+
exports.useFormSetValue = useFormSetValue_1.useFormSetValue;
|
|
12
|
+
var useFormValue_1 = require("./useFormValue");
|
|
13
|
+
exports.useFormValue = useFormValue_1.useFormValue;
|
|
14
|
+
var RelayStoreProvider_1 = require("./relay/RelayStoreProvider");
|
|
15
|
+
exports.StoreProvider = RelayStoreProvider_1.StoreProvider;
|
|
16
|
+
var RelayModernStore_1 = require("./relay/RelayModernStore");
|
|
17
|
+
exports.Store = RelayModernStore_1.RelayModernStore;
|
|
18
|
+
exports.createStore = RelayModernStore_1.createStore;
|
|
19
|
+
var RelayRecordSource_1 = require("./relay/RelayRecordSource");
|
|
20
|
+
exports.RecordSource = RelayRecordSource_1.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 {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __assign = this && this.__assign || function () {
|
|
4
|
+
__assign = Object.assign || function (t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", {
|
|
14
|
+
value: true
|
|
15
|
+
});
|
|
16
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
17
|
+
/**
|
|
18
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
19
|
+
*
|
|
20
|
+
* This source code is licensed under the MIT license found in the
|
|
21
|
+
* LICENSE file in the root directory of this source tree.
|
|
22
|
+
*
|
|
23
|
+
* @flow
|
|
24
|
+
* @format
|
|
25
|
+
*/
|
|
26
|
+
var RelayStoreUtils_1 = require("./RelayStoreUtils");
|
|
27
|
+
var ID_KEY = RelayStoreUtils_1.RelayStoreUtils.ID_KEY,
|
|
28
|
+
REF_KEY = RelayStoreUtils_1.RelayStoreUtils.REF_KEY,
|
|
29
|
+
REFS_KEY = RelayStoreUtils_1.RelayStoreUtils.REFS_KEY;
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
*
|
|
33
|
+
* Low-level record manipulation methods.
|
|
34
|
+
*
|
|
35
|
+
* A note about perf: we use long-hand property access rather than computed
|
|
36
|
+
* properties in this file for speed ie.
|
|
37
|
+
*
|
|
38
|
+
* const object = {};
|
|
39
|
+
* object[KEY] = value;
|
|
40
|
+
* record[storageKey] = object;
|
|
41
|
+
*
|
|
42
|
+
* instead of:
|
|
43
|
+
*
|
|
44
|
+
* record[storageKey] = {
|
|
45
|
+
* [KEY]: value,
|
|
46
|
+
* };
|
|
47
|
+
*
|
|
48
|
+
* The latter gets transformed by Babel into something like:
|
|
49
|
+
*
|
|
50
|
+
* function _defineProperty(obj, key, value) {
|
|
51
|
+
* if (key in obj) {
|
|
52
|
+
* Object.defineProperty(obj, key, {
|
|
53
|
+
* value: value,
|
|
54
|
+
* enumerable: true,
|
|
55
|
+
* configurable: true,
|
|
56
|
+
* writable: true,
|
|
57
|
+
* });
|
|
58
|
+
* } else {
|
|
59
|
+
* obj[key] = value;
|
|
60
|
+
* }
|
|
61
|
+
* return obj;
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* record[storageKey] = _defineProperty({}, KEY, value);
|
|
65
|
+
*
|
|
66
|
+
* A quick benchmark shows that computed property access is an order of
|
|
67
|
+
* magnitude slower (times in seconds for 100,000 iterations):
|
|
68
|
+
*
|
|
69
|
+
* best avg sd
|
|
70
|
+
* computed 0.02175 0.02292 0.00113
|
|
71
|
+
* manual 0.00110 0.00123 0.00008
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* @public
|
|
75
|
+
*
|
|
76
|
+
* Create a new record.
|
|
77
|
+
*/
|
|
78
|
+
function create(dataID) {
|
|
79
|
+
// See perf note above for why we aren't using computed property access.
|
|
80
|
+
var record = {};
|
|
81
|
+
record[ID_KEY] = dataID;
|
|
82
|
+
return record;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @public
|
|
86
|
+
*
|
|
87
|
+
* Get a scalar (non-link) field value.
|
|
88
|
+
*/
|
|
89
|
+
function getValue(record, storageKey) {
|
|
90
|
+
return record[storageKey];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @private
|
|
94
|
+
*
|
|
95
|
+
* Get the value of a field as a reference to another record. Throws if the
|
|
96
|
+
* field has a different type.
|
|
97
|
+
*/
|
|
98
|
+
function getLinkedRecordKey(record, storageKey, key) {
|
|
99
|
+
var link = record[storageKey];
|
|
100
|
+
if (link == null) {
|
|
101
|
+
return link;
|
|
102
|
+
}
|
|
103
|
+
return link[key];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @public
|
|
107
|
+
*
|
|
108
|
+
* Get the value of a field as a reference to another record. Throws if the
|
|
109
|
+
* field has a different type.
|
|
110
|
+
*/
|
|
111
|
+
function getLinkedRecordID(record, storageKey) {
|
|
112
|
+
return getLinkedRecordKey(record, storageKey, REF_KEY);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @public
|
|
116
|
+
*
|
|
117
|
+
* Get the value of a field as a list of references to other records. Throws if
|
|
118
|
+
* the field has a different type.
|
|
119
|
+
*/
|
|
120
|
+
function getLinkedRecordIDs(record, storageKey) {
|
|
121
|
+
return getLinkedRecordKey(record, storageKey, REFS_KEY);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @public
|
|
125
|
+
*
|
|
126
|
+
* Compares the fields of a previous and new record, returning either the
|
|
127
|
+
* previous record if all fields are equal or a new record (with merged fields)
|
|
128
|
+
* if any fields have changed.
|
|
129
|
+
*/
|
|
130
|
+
function update(prevRecord, nextRecord) {
|
|
131
|
+
var updated = null;
|
|
132
|
+
var keys = Object.keys(nextRecord);
|
|
133
|
+
for (var ii = 0; ii < keys.length; ii++) {
|
|
134
|
+
var key = keys[ii];
|
|
135
|
+
if (updated || !RelayStoreUtils_1.areEqual(prevRecord[key], nextRecord[key])) {
|
|
136
|
+
updated = updated !== null ? updated : __assign({}, prevRecord);
|
|
137
|
+
updated[key] = nextRecord[key];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return updated !== null ? updated : prevRecord;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @public
|
|
144
|
+
*
|
|
145
|
+
* Set the value of a storageKey to a scalar.
|
|
146
|
+
* YES
|
|
147
|
+
*/
|
|
148
|
+
function setValue(record, storageKey, value) {
|
|
149
|
+
record[storageKey] = value;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @private
|
|
153
|
+
*
|
|
154
|
+
* Get the value of a field as a reference to another record. Throws if the
|
|
155
|
+
* field has a different type.
|
|
156
|
+
*/
|
|
157
|
+
function setLinkedRecordKey(record, storageKey, linkedID, key) {
|
|
158
|
+
// See perf note above for why we aren't using computed property access.
|
|
159
|
+
var link = {};
|
|
160
|
+
link[key] = linkedID;
|
|
161
|
+
record[storageKey] = link;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @public
|
|
165
|
+
*
|
|
166
|
+
* Set the value of a field to a reference to another record.
|
|
167
|
+
*/
|
|
168
|
+
function setLinkedRecordID(record, storageKey, linkedID) {
|
|
169
|
+
setLinkedRecordKey(record, storageKey, linkedID, REF_KEY);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @public
|
|
173
|
+
*
|
|
174
|
+
* Set the value of a field to a list of references other records.
|
|
175
|
+
*/
|
|
176
|
+
function setLinkedRecordIDs(record, storageKey, linkedIDs) {
|
|
177
|
+
setLinkedRecordKey(record, storageKey, linkedIDs, REFS_KEY);
|
|
178
|
+
}
|
|
179
|
+
exports.RelayModernRecord = {
|
|
180
|
+
create: create,
|
|
181
|
+
getLinkedRecordID: getLinkedRecordID,
|
|
182
|
+
getLinkedRecordIDs: getLinkedRecordIDs,
|
|
183
|
+
getValue: getValue,
|
|
184
|
+
setValue: setValue,
|
|
185
|
+
setLinkedRecordID: setLinkedRecordID,
|
|
186
|
+
setLinkedRecordIDs: setLinkedRecordIDs,
|
|
187
|
+
update: update
|
|
188
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
export declare function getSingularSelector(fragment: any, item: any): any;
|
|
11
|
+
export declare function createOperationDescriptor(request: any): any;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @flow strict-local
|
|
10
|
+
* @format
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
// flowlint ambiguous-object-type:error
|
|
16
|
+
var RelayStoreUtils_1 = require("./RelayStoreUtils");
|
|
17
|
+
var ID_KEY = RelayStoreUtils_1.RelayStoreUtils.ID_KEY;
|
|
18
|
+
function createReaderSelector(node, dataID) {
|
|
19
|
+
return {
|
|
20
|
+
//kind: 'SingularReaderSelector',
|
|
21
|
+
dataID: dataID,
|
|
22
|
+
node: node
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function getSingularSelector(fragment, item) {
|
|
26
|
+
return createReaderSelector(fragment, item[ID_KEY]);
|
|
27
|
+
}
|
|
28
|
+
exports.getSingularSelector = getSingularSelector;
|
|
29
|
+
function createOperationDescriptor(request) {
|
|
30
|
+
var operationDescriptor = {
|
|
31
|
+
fragment: createReaderSelector(request.fragment, RelayStoreUtils_1.RelayStoreUtils.ROOT_ID),
|
|
32
|
+
identifier: request.identifier
|
|
33
|
+
};
|
|
34
|
+
return operationDescriptor;
|
|
35
|
+
}
|
|
36
|
+
exports.createOperationDescriptor = createOperationDescriptor;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
import { MutableRecordSource, Store } from './RelayTypes';
|
|
11
|
+
export declare function createStore(): RelayModernStore;
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*
|
|
15
|
+
* An implementation of the `Store` interface defined in `RelayStoreTypes`.
|
|
16
|
+
*
|
|
17
|
+
* Note that a Store takes ownership of all records provided to it: other
|
|
18
|
+
* objects may continue to hold a reference to such records but may not mutate
|
|
19
|
+
* them. The static Relay core is architected to avoid mutating records that may have been
|
|
20
|
+
* passed to a store: operations that mutate records will either create fresh
|
|
21
|
+
* records or clone existing records and modify the clones. Record immutability
|
|
22
|
+
* is also enforced in development mode by freezing all records passed to a store.
|
|
23
|
+
*/
|
|
24
|
+
export declare class RelayModernStore implements Store {
|
|
25
|
+
_gcRun: any;
|
|
26
|
+
_recordSource: MutableRecordSource;
|
|
27
|
+
_roots: any;
|
|
28
|
+
_updatedRecordIDs: any;
|
|
29
|
+
_currentWriteEpoch: any;
|
|
30
|
+
_subs: any;
|
|
31
|
+
constructor(source: MutableRecordSource);
|
|
32
|
+
getSource(): MutableRecordSource;
|
|
33
|
+
commitUpdate(updater: any): void;
|
|
34
|
+
retain(operation: any): {
|
|
35
|
+
dispose: () => void;
|
|
36
|
+
};
|
|
37
|
+
lookup(selector: any): {
|
|
38
|
+
data: any;
|
|
39
|
+
seenRecords: any;
|
|
40
|
+
selector: any;
|
|
41
|
+
};
|
|
42
|
+
notify(): void;
|
|
43
|
+
_updateSub(source: any, subscription: any, updatedRecordIDs: any, hasUpdatedRecords: boolean): void;
|
|
44
|
+
publish(source: any): void;
|
|
45
|
+
subscribe(snapshot: any, callback: (snapshot: any) => void): {
|
|
46
|
+
dispose: () => void;
|
|
47
|
+
};
|
|
48
|
+
scheduleGC(): void;
|
|
49
|
+
_gcStep: () => void;
|
|
50
|
+
_collect(): Generator<void, void, void>;
|
|
51
|
+
}
|