MCPcopy
hub / github.com/OHIF/Viewers / set

Method set

platform/core/src/utils/objectPath.js:11–43  ·  view source on GitHub ↗

* Set an object property based on "path" (namespace) supplied creating * ... intermediary objects if they do not exist. * @param object {Object} An object where the properties specified on path should be set. * @param path {String} A string representing the property to be set, e.g. "user.st

(object, path, value)

Source from the content-addressed store, hash-verified

9 * ... is not a valid Object, in which case the property cannot be set. No exceptions are thrown.
10 */
11 static set(object, path, value) {
12 let components = ObjectPath.getPathComponents(path),
13 length = components !== null ? components.length : 0,
14 result = false;
15
16 if (length > 0 && ObjectPath.isValidObject(object)) {
17 let i = 0,
18 last = length - 1,
19 currentObject = object;
20
21 while (i < last) {
22 let field = components[i];
23
24 if (field in currentObject) {
25 if (!ObjectPath.isValidObject(currentObject[field])) {
26 break;
27 }
28 } else {
29 currentObject[field] = {};
30 }
31
32 currentObject = currentObject[field];
33 i++;
34 }
35
36 if (i === last) {
37 currentObject[components[last]] = value;
38 result = true;
39 }
40 }
41
42 return result;
43 }
44
45 /**
46 * Get an object property based on "path" (namespace) supplied traversing the object

Callers 15

viewportGridReducerFunction · 0.45
DialogProviderFunction · 0.45
useSessionStorageFunction · 0.45
sortInstancesFunction · 0.45
objectPath.test.jsFile · 0.45
addSameSeriesCompareFunction · 0.45
addImageIdToUIDsMethod · 0.45
addCustomMetadataMethod · 0.45
registerViewportFunction · 0.45
oidc-client.min.jsFile · 0.45
enFunction · 0.45

Calls 2

getPathComponentsMethod · 0.80
isValidObjectMethod · 0.80

Tested by

no test coverage detected