| Total Complexity | 3 |
| Complexity/F | 3 |
| Lines of Code | 38 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import Field from "../Field"; |
||
| 2 | |||
| 3 | export default class MorphTo extends Field { |
||
| 4 | |||
| 5 | constructor(name) { |
||
| 6 | super(name); |
||
| 7 | } |
||
| 8 | |||
| 9 | get value() { |
||
| 10 | const name = this.$parent.snakeCaseClassName; |
||
| 11 | |||
| 12 | const type = this.$parent[`${name}_type`]; |
||
| 13 | const id = this.$parent[`${name}_id`]; |
||
| 14 | |||
| 15 | return globalThis.Store.classInstances[type].constructor.find(id); |
||
| 16 | } |
||
| 17 | |||
| 18 | protected setFillPropertyOnParent(): void { |
||
| 19 | Object.defineProperty(this.$parent, |
||
| 20 | `_${this.name}`, |
||
| 21 | { |
||
| 22 | set: (value) => { |
||
| 23 | if (!Array.isArray(value)) { |
||
| 24 | value = [value]; |
||
| 25 | } |
||
| 26 | |||
| 27 | const name = this.$parent.snakeCaseClassName; |
||
| 28 | const type = `${name}_type`; |
||
| 29 | const id = `${name}_id`; |
||
| 30 | |||
| 31 | for (const record of value) { |
||
| 32 | record['id'] = record[id]; |
||
| 33 | globalThis.Store.classInstances[record[type]].constructor.insert(record); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | }); |
||
| 37 | } |
||
| 38 | } |