-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloned-resource.js
59 lines (59 loc) · 1.73 KB
/
cloned-resource.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
import { Resource } from './resource';
import { ClonedDocumentResource } from './cloned-document-resource';
import { cloneDeep } from 'lodash';
// unsupported: template constraints.
/**
* @template T
*/
export class ClonedResource extends Resource {
/**
* @param {?} resource
*/
constructor(resource) {
super();
// @note using cloneDeep because the parent may have changed since clone (example: data received from socket while editing clone)
this.parent = cloneDeep(resource);
this.type = this.parent.type; // this line should go to fill method?
delete this.relationships;
/** @type {?} */
let include = Object.keys(this.parent.relationships);
this.fill(this.parent.toObject({ include: include }));
this.copySourceFromParent();
}
/**
* @param {?=} params
* @return {?}
*/
toObject(params) {
return new ClonedDocumentResource(this, this.parent, params).getResourceObject();
}
/**
* @param {?=} params
* @return {?}
*/
superToObject(params) {
return super.toObject(params);
}
/**
* @return {?}
*/
copySourceFromParent() {
this.source = this.parent.source;
for (let relationship in this.relationships) {
this.relationships[relationship].source = this.parent.relationships[relationship].source;
}
}
}
if (false) {
/** @type {?} */
ClonedResource.prototype.parent;
/** @type {?} */
ClonedResource.prototype.attributes;
/** @type {?} */
ClonedResource.prototype.relationships;
}
//# sourceMappingURL=cloned-resource.js.map