Skip to content

Commit

Permalink
chore: change params of makeObservable to object
Browse files Browse the repository at this point in the history
  • Loading branch information
jajugoguma committed Dec 18, 2023
1 parent ae3f0e5 commit 754e60c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
30 changes: 20 additions & 10 deletions packages/toast-ui.grid/src/dispatch/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,19 @@ export function updateHeights(store: Store) {
: filteredRawData.map((row) => getRowHeight(row, rowHeight));
}

export function makeObservable(
store: Store,
rowIndex: number,
export function makeObservable({
store,
rowIndex,
silent = false,
lazyObservable = false,
forced = false
) {
forced = false,
}: {
store: Store;
rowIndex: number;
silent?: boolean;
lazyObservable?: boolean;
forced?: boolean;
}) {
const { data, column, id } = store;
const { rawData, viewData } = data;
const { treeColumnName } = column;
Expand All @@ -153,7 +159,9 @@ export function makeObservable(

if (treeColumnName) {
const parentRow = findRowByRowKey(data, column, id, rawRow._attributes.tree!.parentRowKey);
rawData[rowIndex] = createTreeRawRow(id, rawRow, parentRow || null, column, { lazyObservable });
rawData[rowIndex] = createTreeRawRow(id, rawRow, parentRow || null, column, {
lazyObservable,
});
} else {
rawData[rowIndex] = createRawRow(id, rawRow, rowIndex, column, { lazyObservable });
}
Expand Down Expand Up @@ -183,7 +191,7 @@ export function setValue(
return;
}
if (checkCellState) {
makeObservable(store, rowIndex);
makeObservable({ store, rowIndex });
const { disabled, editable } = viewData[rowIndex].valueMap[columnName];

if (disabled || !editable) {
Expand Down Expand Up @@ -608,7 +616,7 @@ export function appendRow(store: Store, row: OptRow, options: OptAppendRow) {

silentSplice(rawData, at, 0, rawRow);
silentSplice(viewData, at, 0, viewRow);
makeObservable(store, at);
makeObservable({ store, rowIndex: at });
updatePageOptions(store, { totalCount: pageOptions.totalCount! + 1 });
updateHeights(store);

Expand Down Expand Up @@ -852,7 +860,7 @@ export function setRow(store: Store, rowIndex: number, row: OptRow) {

silentSplice(rawData, rowIndex, 1, rawRow);
silentSplice(viewData, rowIndex, 1, viewRow);
makeObservable(store, rowIndex);
makeObservable({ store, rowIndex });

sortByCurrentState(store);

Expand Down Expand Up @@ -927,7 +935,9 @@ export function setRows(store: Store, rows: OptRow[]) {

createdRowInfos
.filter(({ rowIndex }) => isBetween(rowIndex, rowRange[0], rowRange[1]))
.forEach(({ rowIndex }) => makeObservable(store, rowIndex, false, true));
.forEach(({ rowIndex }) =>
makeObservable({ store, rowIndex, silent: false, lazyObservable: true })
);

if (isRowSpanEnabled(sortState, column)) {
createdRowInfos
Expand Down
4 changes: 2 additions & 2 deletions packages/toast-ui.grid/src/dispatch/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function startEditing(store: Store, rowKey: RowKey, columnName: string) {
}

// makes the data observable to judge editable, disable of the cell
makeObservable(store, findIndexByRowKey(data, column, id, rowKey, false));
makeObservable({ store, rowIndex: findIndexByRowKey(data, column, id, rowKey, false) });

if (!isEditableCell(store, foundIndex, columnName)) {
return;
Expand Down Expand Up @@ -158,7 +158,7 @@ export function saveAndFinishEditing(store: Store, value?: string) {
const { rowKey, columnName } = editingAddress;

// makes the data observable to judge editable, disable of the cell.
makeObservable(store, findIndexByRowKey(data, column, id, rowKey, false));
makeObservable({ store, rowIndex: findIndexByRowKey(data, column, id, rowKey, false) });

// if value is 'undefined', editing result is saved and finished.
if (isUndefined(value)) {
Expand Down
8 changes: 7 additions & 1 deletion packages/toast-ui.grid/src/dispatch/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ function sortData(store: Store) {
const { rowKey } = rawRow;

if (isObservable(rawRow) || rowKeysInViewport.includes(rowKey)) {
makeObservable(store, index, false, false, true);
makeObservable({
store,
rowIndex: index,
silent: false,
lazyObservable: false,
forced: true,
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/toast-ui.grid/src/query/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getObservableList(store: Store, filteredViewData: ViewRow[], start: num

for (let i = start; i <= end; i += 1) {
if (!isObservable(filteredViewData[i].valueMap)) {
makeObservable(store, i, true);
makeObservable({ store, rowIndex: i, silent: true });

if (i === end) {
notify(store.data, 'rawData', 'filteredRawData', 'viewData', 'filteredViewData');
Expand Down
4 changes: 2 additions & 2 deletions packages/toast-ui.grid/src/query/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function isEditableCell(store: Store, rowIndex: number, columnName: strin

// get index based on whole data(not filtered data)
const index = filteredIndex ? filteredIndex[rowIndex] : rowIndex;
makeObservable(store, index, true);
makeObservable({ store, rowIndex: index, silent: true });

const { disabled, editable } = filteredViewData[rowIndex].valueMap[columnName];

Expand Down Expand Up @@ -303,7 +303,7 @@ export function getFormattedValue(store: Store, rowKey: RowKey, columnName: stri
const { viewData } = data;

if (rowIndex !== -1) {
makeObservable(store, rowIndex);
makeObservable({ store, rowIndex });
const viewCell = viewData[rowIndex].valueMap[columnName];
return viewCell ? viewCell.formattedValue : null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/toast-ui.grid/src/query/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getInvalidRows(store: Store, rowKeys?: RowKey[]) {
const needToValidateRow = !rowKeys || rowKeys.includes(row.rowKey);

if (!isObservable(row) && needToValidateRow) {
makeObservable(store, rowIndex, true);
makeObservable({ store, rowIndex, silent: true });
}
});

Expand Down

0 comments on commit 754e60c

Please sign in to comment.