@performant-software/shared-components 0.5.4 → 0.5.7

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.
@@ -1,63 +0,0 @@
1
- // @flow
2
-
3
- import _ from 'underscore';
4
- import StringUtils from '../utils/String';
5
-
6
- /**
7
- * Class for handling transforming nested attributes of a parent object. This class will handle transforming the
8
- * object into a payload to be sent to a POST/PUT request on an API. This class currently supports transforming into
9
- * a plain Javascript object or a FormData object.
10
- */
11
- class NestedAttributesTransform {
12
- /**
13
- * Constructs a new BaseTransform object. This constructor should never be used directly.
14
- */
15
- constructor() {
16
- if (this.constructor === NestedAttributesTransform) {
17
- throw new TypeError('Abstract class "NestedAttributesTransform" cannot be instantiated directly.');
18
- }
19
- }
20
-
21
- /**
22
- * Returns the array of payload keys.
23
- *
24
- * @returns {*[]}
25
- */
26
- getPayloadKeys() {
27
- // Implemented in sub-class.
28
- return [];
29
- }
30
-
31
- /**
32
- * Appends the passed record's collection to the form data.
33
- *
34
- * @param formData
35
- * @param prefix
36
- * @param record
37
- * @param collection
38
- */
39
- toFormData(formData: FormData, prefix: string, record: any, collection: string) {
40
- _.each(record[collection], (item, index) => {
41
- _.each(this.getPayloadKeys(), (key) => {
42
- formData.append(`${prefix}[${collection}][${index}][${key}]`, StringUtils.toString(item[key]));
43
- });
44
- });
45
- }
46
-
47
- /**
48
- * Transforms the passed record's collection to a payload object.
49
- *
50
- * @param record
51
- * @param collection
52
- *
53
- * @returns {{[p: string]: *}}
54
- */
55
- toPayload(record: any, collection: string) {
56
- return {
57
- [collection]: _.map(record[collection],
58
- (item, index) => ({ ..._.pick(item, this.getPayloadKeys()), order: index }))
59
- };
60
- }
61
- }
62
-
63
- export default NestedAttributesTransform;
@@ -1,14 +0,0 @@
1
- // @flow
2
-
3
- /**
4
- * Returns true if passed value is a promise (i.e, has a .then method)
5
- *
6
- * @param *
7
- *
8
- * @returns {boolean}
9
- */
10
- const isPromise = (value: any) => !!value && typeof value === 'object' && typeof value.then === 'function';
11
-
12
- export default {
13
- isPromise
14
- };