MCPcopy
hub / github.com/handsontable/handsontable / set

Method set

handsontable/src/dataMap/dataMap.ts:906–964  ·  view source on GitHub ↗

* Saves single value to the data array. * * @param {number} row Visual row index. * @param {number|string} prop The column property. * @param {string} value The value to set.

(row: number, prop: string | number, value: unknown)

Source from the content-addressed store, hash-verified

904 * @param {string} value The value to set.
905 */
906 set(row: number, prop: string | number, value: unknown) {
907 const physicalRow = this.hot!.toPhysicalRow(row);
908 let newValue = value;
909 let dataRow: Record<string | number, unknown> = this.dataSource![physicalRow] as Record<string | number, unknown>;
910 // TODO: To remove, use 'modifyData' hook instead (see below)
911 const modifiedRowData = this.hot!.runHooks('modifyRowData', physicalRow);
912
913 dataRow = typeof modifiedRowData !== 'number' ? modifiedRowData as Record<string | number, unknown> : dataRow;
914 //
915
916 if (this.hot!.hasHook('modifyData')) {
917 const valueHolder = createObjectPropListener(newValue);
918
919 this.hot!.runHooks('modifyData', row, this.propToCol(prop), valueHolder, 'set');
920
921 if (valueHolder.isTouched()) {
922 newValue = valueHolder.value;
923 }
924 }
925
926 const { dataDotNotation } = this.hot!.getSettings();
927
928 // try to set value under property `prop` (includes dot)
929 if (dataRow && hasOwnProperty(dataRow, prop)) {
930 dataRow[prop] = newValue;
931
932 } else if (dataDotNotation && typeof prop === 'string' && prop.indexOf('.') > -1) {
933 let out: Record<string, unknown> = dataRow;
934 let i = 0;
935 let ilen;
936
937 const sliced = prop.split('.');
938
939 for (i = 0, ilen = sliced.length - 1; i < ilen; i++) {
940 if (sliced[i] === '__proto__' || sliced[i] === 'constructor' || sliced[i] === 'prototype') {
941 // Security: prototype-polluting is not allowed
942 return;
943 }
944
945 if (typeof out[sliced[i]] === 'undefined') {
946 out[sliced[i]] = {};
947 }
948 out = out[sliced[i]] as Record<string, unknown>;
949 }
950
951 out[sliced[i]] = newValue;
952 } else if (typeof prop === 'function') {
953 (prop as (row: unknown, value: unknown) => void)(
954 this.dataSource!.slice(physicalRow, physicalRow + 1)[0], newValue);
955
956 } else {
957 if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
958 // Security: prototype-polluting is not allowed
959 return;
960 }
961
962 dataRow[prop] = newValue;
963 }

Callers 15

clearMethod · 0.95
RendererComponent2Function · 0.45
redux.spec.tsxFile · 0.45
HotTableContextProviderFunction · 0.45
createNewGlobalSettingsFunction · 0.45
createColumnSettingsFunction · 0.45
stringifyToJSONFunction · 0.45
trackComponentRefMethod · 0.45
trackEmbeddedViewMethod · 0.45
registryForMethod · 0.45
findMainRendererThreadFunction · 0.45

Calls 9

propToColMethod · 0.95
createObjectPropListenerFunction · 0.90
hasOwnPropertyFunction · 0.90
toPhysicalRowMethod · 0.80
hasHookMethod · 0.80
isTouchedMethod · 0.80
runHooksMethod · 0.65
getSettingsMethod · 0.65
sliceMethod · 0.45

Tested by 3

RendererComponent2Function · 0.36
setFunction · 0.36
setValueAtIndexFunction · 0.36