Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 7fcc1f2

Browse files
authored
chore: remove unneeded event if condition wrappers (#468)
1 parent 377a211 commit 7fcc1f2

File tree

1 file changed

+59
-73
lines changed

1 file changed

+59
-73
lines changed

src/slickgrid-react/extensions/slickRowDetailView.ts

Lines changed: 59 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -134,79 +134,65 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
134134
this.rowDetailViewOptions.onExtensionRegistered(this);
135135
}
136136

137-
if (this.onAsyncResponse) {
138-
this._eventHandler.subscribe(this.onAsyncResponse, (event, args) => {
139-
if (typeof this.rowDetailViewOptions?.onAsyncResponse === 'function') {
140-
this.rowDetailViewOptions.onAsyncResponse(event, args);
141-
}
142-
});
143-
}
144-
145-
if (this.onAsyncEndUpdate) {
146-
this._eventHandler.subscribe(this.onAsyncEndUpdate, async (event, args) => {
147-
// dispose preload if exists
148-
this._preloadRoot?.unmount();
149-
150-
// triggers after backend called "onAsyncResponse.notify()"
151-
await this.renderViewModel(args?.item);
152-
153-
if (typeof this.rowDetailViewOptions?.onAsyncEndUpdate === 'function') {
154-
this.rowDetailViewOptions.onAsyncEndUpdate(event, args);
155-
}
156-
});
157-
}
158-
159-
if (this.onAfterRowDetailToggle) {
160-
this._eventHandler.subscribe(this.onAfterRowDetailToggle, async (event, args) => {
161-
// display preload template & re-render all the other Detail Views after toggling
162-
// the preload View will eventually go away once the data gets loaded after the "onAsyncEndUpdate" event
163-
await this.renderPreloadView(args.item);
164-
165-
if (typeof this.rowDetailViewOptions?.onAfterRowDetailToggle === 'function') {
166-
this.rowDetailViewOptions.onAfterRowDetailToggle(event, args);
167-
}
168-
});
169-
}
170-
171-
if (this.onBeforeRowDetailToggle) {
172-
this._eventHandler.subscribe(this.onBeforeRowDetailToggle, (event, args) => {
173-
// before toggling row detail, we need to create View Component if it doesn't exist
174-
this.handleOnBeforeRowDetailToggle(event, args);
175-
176-
if (typeof this.rowDetailViewOptions?.onBeforeRowDetailToggle === 'function') {
177-
return this.rowDetailViewOptions.onBeforeRowDetailToggle(event, args);
178-
}
179-
return true;
180-
});
181-
}
182-
183-
if (this.onRowBackToViewportRange) {
184-
this._eventHandler.subscribe(this.onRowBackToViewportRange, async (event, args) => {
185-
// when row is back to viewport range, we will re-render the View Component(s)
186-
await this.handleOnRowBackToViewportRange(event, args);
187-
188-
if (typeof this.rowDetailViewOptions?.onRowBackToViewportRange === 'function') {
189-
this.rowDetailViewOptions.onRowBackToViewportRange(event, args);
190-
}
191-
});
192-
}
193-
194-
if (this.onBeforeRowOutOfViewportRange) {
195-
this._eventHandler.subscribe(this.onBeforeRowOutOfViewportRange, (event, args) => {
196-
if (typeof this.rowDetailViewOptions?.onBeforeRowOutOfViewportRange === 'function') {
197-
this.rowDetailViewOptions.onBeforeRowOutOfViewportRange(event, args);
198-
}
199-
this.disposeView(args.item);
200-
});
201-
}
202-
203-
if (this.onRowOutOfViewportRange) {
204-
this._eventHandler.subscribe(this.onRowOutOfViewportRange, (event, args) => {
205-
if (typeof this.rowDetailViewOptions?.onRowOutOfViewportRange === 'function') {
206-
this.rowDetailViewOptions.onRowOutOfViewportRange(event, args);
207-
}
208-
});
209-
}
137+
this._eventHandler.subscribe(this.onAsyncResponse, (event, args) => {
138+
if (typeof this.rowDetailViewOptions?.onAsyncResponse === 'function') {
139+
this.rowDetailViewOptions.onAsyncResponse(event, args);
140+
}
141+
});
142+
143+
this._eventHandler.subscribe(this.onAsyncEndUpdate, async (event, args) => {
144+
// dispose preload if exists
145+
this._preloadRoot?.unmount();
146+
147+
// triggers after backend called "onAsyncResponse.notify()"
148+
await this.renderViewModel(args?.item);
149+
150+
if (typeof this.rowDetailViewOptions?.onAsyncEndUpdate === 'function') {
151+
this.rowDetailViewOptions.onAsyncEndUpdate(event, args);
152+
}
153+
});
154+
155+
this._eventHandler.subscribe(this.onAfterRowDetailToggle, async (event, args) => {
156+
// display preload template & re-render all the other Detail Views after toggling
157+
// the preload View will eventually go away once the data gets loaded after the "onAsyncEndUpdate" event
158+
await this.renderPreloadView(args.item);
159+
160+
if (typeof this.rowDetailViewOptions?.onAfterRowDetailToggle === 'function') {
161+
this.rowDetailViewOptions.onAfterRowDetailToggle(event, args);
162+
}
163+
});
164+
165+
this._eventHandler.subscribe(this.onBeforeRowDetailToggle, (event, args) => {
166+
// before toggling row detail, we need to create View Component if it doesn't exist
167+
this.handleOnBeforeRowDetailToggle(event, args);
168+
169+
if (typeof this.rowDetailViewOptions?.onBeforeRowDetailToggle === 'function') {
170+
return this.rowDetailViewOptions.onBeforeRowDetailToggle(event, args);
171+
}
172+
return true;
173+
});
174+
175+
this._eventHandler.subscribe(this.onRowBackToViewportRange, async (event, args) => {
176+
// when row is back to viewport range, we will re-render the View Component(s)
177+
await this.handleOnRowBackToViewportRange(event, args);
178+
179+
if (typeof this.rowDetailViewOptions?.onRowBackToViewportRange === 'function') {
180+
this.rowDetailViewOptions.onRowBackToViewportRange(event, args);
181+
}
182+
});
183+
184+
this._eventHandler.subscribe(this.onBeforeRowOutOfViewportRange, (event, args) => {
185+
if (typeof this.rowDetailViewOptions?.onBeforeRowOutOfViewportRange === 'function') {
186+
this.rowDetailViewOptions.onBeforeRowOutOfViewportRange(event, args);
187+
}
188+
this.disposeView(args.item);
189+
});
190+
191+
this._eventHandler.subscribe(this.onRowOutOfViewportRange, (event, args) => {
192+
if (typeof this.rowDetailViewOptions?.onRowOutOfViewportRange === 'function') {
193+
this.rowDetailViewOptions.onRowOutOfViewportRange(event, args);
194+
}
195+
});
210196

211197
// --
212198
// hook some events needed by the Plugin itself

0 commit comments

Comments
 (0)