Skip to content

Commit

Permalink
AG-10884 - Vue change batching fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewGlazier committed May 15, 2024
1 parent 2bd7176 commit 5086ca0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
4 changes: 2 additions & 2 deletions community-modules/core/src/gridApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1982,8 +1982,8 @@ export class GridApi<TData = any> {
}

/** Used internally by grid. Not intended to be used by the client. Interface may change between releases. */
public __internalUpdateGridOptions(options: GridOptions): void {
this.gos.updateGridOptions({ options, source: 'gridOptionsUpdated' });
public __internalUpdateGridOptions(options: GridOptions, force?: boolean): void {
this.gos.updateGridOptions({ options, force, source: 'gridOptionsUpdated' });
}

private deprecatedUpdateGridOption<K extends keyof GridOptions & ManagedGridOptionKey>(key: K, value: GridOptions<TData>[K]) {
Expand Down
4 changes: 2 additions & 2 deletions community-modules/core/src/gridOptionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class GridOptionsService {
}

private static changeSetId = 0;
public updateGridOptions({ options, source = 'api' }: { options: Partial<GridOptions>, source?: PropertyChangedSource }): void {
public updateGridOptions({ options, force, source = 'api' }: { options: Partial<GridOptions>, force?: boolean, source?: PropertyChangedSource }): void {
const changeSet: PropertyChangeSet = { id: GridOptionsService.changeSetId++, properties: [] };
// all events are fired after grid options has finished updating.
const events: PropertyValueChangedEvent<keyof GridOptions>[] = [];
Expand All @@ -246,7 +246,7 @@ export class GridOptionsService {
warnOnce(`${key} is an initial property and cannot be updated.`)
}
const coercedValue = GridOptionsService.getCoercedValue(key as keyof GridOptions, value);
const shouldForce = (typeof coercedValue) === 'object' && source === 'api'; // force objects as they could have been mutated.
const shouldForce = force || ((typeof coercedValue) === 'object' && source === 'api'); // force objects as they could have been mutated.

const previousValue = this.gridOptions[key as keyof GridOptions];
if (shouldForce || previousValue !== coercedValue) {
Expand Down
42 changes: 18 additions & 24 deletions community-modules/vue3/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,8 @@ export const getAgGridProperties = (): [Properties, Properties, Properties] => {
const eventNameAsProps = ComponentUtil.PUBLIC_EVENTS.map((eventName: string) => kebabNameToAttrEventName(kebabProperty(eventName)));
eventNameAsProps.forEach((eventName: string) => props[eventName] = undefined)

const computed: Properties = {
props() {
const options: { [key: string]: any } = {};
ComponentUtil.ALL_PROPERTIES.forEach((propertyName: string) => {
if (this[propertyName] === ComponentUtil.VUE_OMITTED_PROPERTY) { return; }
if (propertyName in this || propertyName in this.gridOptions) {
options[propertyName] = this[propertyName] ?? this.gridOptions[propertyName];
}
});
return options;
},
};
const computed: Properties = {};

const watch: Properties = {
modelValue: {
handler(currentValue: any, previousValue: any) {
Expand All @@ -55,25 +45,29 @@ export const getAgGridProperties = (): [Properties, Properties, Properties] => {
},
deep: true
},
props: {
handler(currentValue: any, previousValue: any) {
if (!this.gridCreated || !this.api) { return; }
const changes: any = {};
Object.entries(currentValue).forEach(([key, value]) => {
if (previousValue[key] === value) return;
changes[key] = value;
});
ComponentUtil.processOnChange(changes, this.api);
},
deep: true,
},
};
let timeout: number | null = null;
let changes: { [key: string]: any } = {};
ComponentUtil.ALL_PROPERTIES
.filter((propertyName: string) => propertyName != 'gridOptions') // dealt with in AgGridVue itself
.forEach((propertyName: string) => {
props[propertyName] = {
default: ComponentUtil.VUE_OMITTED_PROPERTY,
};

watch[propertyName] = {
handler(currentValue: any, previousValue: any) {
changes[propertyName] = currentValue === ComponentUtil.VUE_OMITTED_PROPERTY ? undefined : currentValue;
if (timeout == null) {
timeout = setTimeout(() => {
ComponentUtil.processOnChange(changes, this.api);
timeout = null;
changes = {};
}, 0);
}
},
deep: true,
}
});

return [props, computed, watch];
Expand Down

0 comments on commit 5086ca0

Please sign in to comment.