From 6fcdd2220be0019f0c7df1202c42b5bb3d16753d Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Fri, 12 Jan 2024 18:10:14 -0500 Subject: [PATCH] fix(core): SlickEvent handler event should be type of ArgType - continuation of previous PR #1327 to add proper types to SlickEventHandler arguments --- packages/common/src/core/slickCore.ts | 8 ++++---- packages/common/src/core/slickDataview.ts | 2 +- .../src/interfaces/rowDetailView.interface.ts | 3 +++ .../src/slickRowDetailView.ts | 13 +++++++------ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/common/src/core/slickCore.ts b/packages/common/src/core/slickCore.ts index c85edc2dc..35b8b1cca 100644 --- a/packages/common/src/core/slickCore.ts +++ b/packages/common/src/core/slickCore.ts @@ -10,7 +10,7 @@ import { MergeTypes } from '../enums/index'; import type { CSSStyleDeclarationWritable, EditController } from '../interfaces'; -export type Handler = (e: SlickEventData, args: ArgType) => void; +export type Handler = (e: SlickEventData, args: ArgType) => void; export interface BasePubSub { publish(_eventName: string | any, _data?: ArgType): any; @@ -203,8 +203,8 @@ export class SlickEvent { * @param {Object} [scope] - The scope ("this") within which the handler will be executed. * If not specified, the scope will be set to the Event instance. */ - notify(args: ArgType, evt?: SlickEventData | Event | MergeTypes | null, scope?: any, ignorePrevEventDataValue = false) { - const sed = evt instanceof SlickEventData ? evt : new SlickEventData(evt, args); + notify(args: ArgType, evt?: SlickEventData | Event | MergeTypes | null, scope?: any, ignorePrevEventDataValue = false) { + const sed = evt instanceof SlickEventData ? evt : new SlickEventData(evt, args); if (ignorePrevEventDataValue) { sed.resetReturnValue(); } @@ -217,7 +217,7 @@ export class SlickEvent { // user can optionally add a global PubSub Service which makes it easy to publish/subscribe to events if (typeof this._pubSubService?.publish === 'function' && this.eventName) { - const ret = this._pubSubService.publish<{ args: ArgType; eventData?: SlickEventData; nativeEvent?: Event; }>(this.eventName, { args, eventData: sed }); + const ret = this._pubSubService.publish<{ args: ArgType; eventData?: SlickEventData; nativeEvent?: Event; }>(this.eventName, { args, eventData: sed }); sed.addReturnValue(ret); } return sed; diff --git a/packages/common/src/core/slickDataview.ts b/packages/common/src/core/slickDataview.ts index 0dc5c4046..e978116cf 100644 --- a/packages/common/src/core/slickDataview.ts +++ b/packages/common/src/core/slickDataview.ts @@ -1409,7 +1409,7 @@ export class SlickDataView implements CustomD } }; - grid.onSelectedRowsChanged.subscribe((_e: SlickEventData, args: { rows: number[]; }) => { + grid.onSelectedRowsChanged.subscribe((_e, args) => { if (!inHandler) { const newSelectedRowIds = this.mapRowsToIds(args.rows); const selectedRowsChangedArgs = { diff --git a/packages/common/src/interfaces/rowDetailView.interface.ts b/packages/common/src/interfaces/rowDetailView.interface.ts index e96092d00..2a1b6e12a 100644 --- a/packages/common/src/interfaces/rowDetailView.interface.ts +++ b/packages/common/src/interfaces/rowDetailView.interface.ts @@ -37,6 +37,9 @@ export interface OnRowDetailAsyncResponseArgs { /** An explicit view to use instead of template (Optional) */ detailView?: any; + + /** SlickGrid instance */ + grid: SlickGrid; } /** Fired when the async response finished */ diff --git a/packages/row-detail-view-plugin/src/slickRowDetailView.ts b/packages/row-detail-view-plugin/src/slickRowDetailView.ts index 2b00706d1..83b16ef30 100644 --- a/packages/row-detail-view-plugin/src/slickRowDetailView.ts +++ b/packages/row-detail-view-plugin/src/slickRowDetailView.ts @@ -305,7 +305,8 @@ export class SlickRowDetailView implements ExternalResource, UniversalRowDetailV this.onAsyncResponse.notify({ item, itemDetail: item, - detailView: item[`${this._keyPrefix}detailContent`] + detailView: item[`${this._keyPrefix}detailContent`], + grid: this._grid }); this.applyTemplateNewLineHeight(item); this.dataView.updateItem(item[this._dataViewIdProperty], item); @@ -334,7 +335,7 @@ export class SlickRowDetailView implements ExternalResource, UniversalRowDetailV * subscribe to the onAsyncResponse so that the plugin knows when the user server side calls finished * the response has to be as "args.item" (or "args.itemDetail") with it's data back */ - handleOnAsyncResponse(_e: SlickEventData, args: { item: any; itemDetail: any; detailView?: any; }) { + handleOnAsyncResponse(e: SlickEventData, args: { item: any; itemDetail: any; detailView?: any; }) { if (!args || (!args.item && !args.itemDetail)) { console.error('SlickRowDetailView plugin requires the onAsyncResponse() to supply "args.item" property.'); return; @@ -353,7 +354,7 @@ export class SlickRowDetailView implements ExternalResource, UniversalRowDetailV grid: this._grid, item: itemDetail, itemDetail, - }); + }, e, this); } /** @@ -711,7 +712,7 @@ export class SlickRowDetailView implements ExternalResource, UniversalRowDetailV grid: this._grid, item: dataContext, expandedRows: this._expandedRows, - }); + }, e, this); e.stopPropagation(); e.stopImmediatePropagation(); @@ -737,7 +738,7 @@ export class SlickRowDetailView implements ExternalResource, UniversalRowDetailV rowIndex, expandedRows: this._expandedRows, rowIdsOutOfViewport: this.syncOutOfViewportArray(rowId, true) - }); + }, null, this); } protected notifyBackToViewportWhenDomExist(item: any, rowId: number | string) { @@ -753,7 +754,7 @@ export class SlickRowDetailView implements ExternalResource, UniversalRowDetailV rowIndex, expandedRows: this._expandedRows, rowIdsOutOfViewport: this.syncOutOfViewportArray(rowId, false) - }); + }, null, this); } }, 100); }