(object, path, value, cb = null)
| 2 | |
| 3 | export class StateEditor { |
| 4 | set(object, path, value, cb = null) { |
| 5 | const sections = Array.isArray(path) ? path : path.split('.') |
| 6 | while (sections.length > 1) { |
| 7 | object = object[sections.shift()] |
| 8 | if (this.isRef(object)) { |
| 9 | object = this.getRefValue(object) |
| 10 | } |
| 11 | } |
| 12 | const field = sections[0] |
| 13 | if (cb) { |
| 14 | cb(object, field, value) |
| 15 | } |
| 16 | else if (this.isRef(object[field])) { |
| 17 | this.setRefValue(object[field], value) |
| 18 | } |
| 19 | else { |
| 20 | object[field] = value |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | get(object, path) { |
| 25 | const sections = Array.isArray(path) ? path : path.split('.') |
no test coverage detected