Skip to content

Commit 5c59b4f

Browse files
Scheduler: Rename observer to scheduler (#30627)
1 parent 5ce4f55 commit 5c59b4f

File tree

15 files changed

+104
-84
lines changed

15 files changed

+104
-84
lines changed

packages/devextreme/js/__internal/scheduler/appointments/appointment/m_appointment.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
REDUCED_APPOINTMENT_PARTS_CLASSES,
2525
} from '../../m_classes';
2626
import { getRecurrenceProcessor } from '../../m_recurrence';
27+
import type { SubscribeKey, SubscribeMethods } from '../../m_subscribes';
2728
import type { AppointmentDataAccessor } from '../../utils/data_accessor/appointment_data_accessor';
2829
import type { AppointmentProperties } from './m_types';
2930
import {
@@ -72,20 +73,24 @@ export class Appointment extends DOMComponent<AppointmentProperties> {
7273
});
7374
}
7475

75-
notifyObserver(subject, args) {
76-
const observer = this.option('observer');
77-
if (observer) {
78-
observer.fire(subject, args);
79-
}
76+
notifyObserver<Subject extends SubscribeKey>(
77+
funcName: Subject,
78+
args: Parameters<SubscribeMethods[Subject]>,
79+
): void {
80+
this.invoke(funcName, ...args);
8081
}
8182

82-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
83-
invoke(funcName: string) {
84-
const observer = this.option('observer');
83+
invoke<Subject extends SubscribeKey>(
84+
funcName: Subject,
85+
...args: Parameters<SubscribeMethods[Subject]>
86+
): ReturnType<SubscribeMethods[Subject]> | undefined {
87+
const notifyScheduler = this.option('notifyScheduler');
8588

86-
if (observer) {
87-
return observer.fire.apply(observer, arguments);
89+
if (!notifyScheduler) {
90+
return undefined;
8891
}
92+
93+
return notifyScheduler.invoke(funcName, ...args);
8994
}
9095

9196
_optionChanged(args) {

packages/devextreme/js/__internal/scheduler/appointments/appointment/m_types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Orientation } from '@js/common';
2+
import type NotifyScheduler from '@ts/scheduler/base/m_widget_notify_scheduler';
23
import type { TimeZoneCalculator } from '@ts/scheduler/r1/timezone_calculator/calculator';
34
import type { SafeAppointment } from '@ts/scheduler/types';
45
import type { AppointmentDataAccessor } from '@ts/scheduler/utils/data_accessor/appointment_data_accessor';
@@ -8,7 +9,7 @@ export interface AppointmentProperties extends Record<string, unknown> {
89
data: SafeAppointment;
910
groupIndex?: number;
1011
groupTexts: string[];
11-
observer: any;
12+
notifyScheduler: NotifyScheduler | undefined;
1213
geometry: any;
1314
direction: Orientation;
1415
allowResize: boolean;

packages/devextreme/js/__internal/scheduler/appointments/m_appointment_collection.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,17 @@ class SchedulerAppointments extends CollectionWidget {
104104
}
105105

106106
notifyObserver(subject, args) {
107-
const observer: any = this.option('observer');
108-
if (observer) {
109-
observer.fire(subject, args);
107+
const notifyScheduler: any = this.option('notifyScheduler');
108+
if (notifyScheduler) {
109+
notifyScheduler.invoke(subject, args);
110110
}
111111
}
112112

113-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
114113
invoke(funcName: string, ...args) {
115-
const observer: any = this.option('observer');
114+
const notifyScheduler: any = this.option('notifyScheduler');
116115

117-
if (observer) {
118-
return observer.fire.apply(observer, arguments);
116+
if (notifyScheduler) {
117+
return notifyScheduler.invoke(funcName, ...args);
119118
}
120119
}
121120

@@ -645,7 +644,7 @@ class SchedulerAppointments extends CollectionWidget {
645644
data: settings.itemData,
646645
groupIndex: settings.groupIndex,
647646
groupTexts: getGroupTexts(groups, groupsLeafs, resourceById, settings.groupIndex),
648-
observer: this.option('observer'),
647+
notifyScheduler: this.option('notifyScheduler'),
649648
geometry: settings,
650649
direction: settings.direction || 'vertical',
651650
allowResize: false,
@@ -675,7 +674,7 @@ class SchedulerAppointments extends CollectionWidget {
675674
data: settings.itemData,
676675
groupIndex: settings.groupIndex,
677676
groupTexts: getGroupTexts(groups, groupsLeafs, resourceById, settings.groupIndex),
678-
observer: this.option('observer'),
677+
notifyScheduler: this.option('notifyScheduler'),
679678
geometry: settings,
680679
direction: settings.direction || 'vertical',
681680
allowResize,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type Scheduler from '../m_scheduler';
2+
import type { SubscribeKey, SubscribeMethods } from '../m_subscribes';
3+
4+
class NotifyScheduler {
5+
scheduler: Scheduler;
6+
7+
constructor({ scheduler }: { scheduler: Scheduler }) {
8+
this.scheduler = scheduler;
9+
}
10+
11+
invoke<Subject extends SubscribeKey>(
12+
funcName: Subject,
13+
...args: Parameters<SubscribeMethods[Subject]>
14+
): ReturnType<SubscribeMethods[Subject]> {
15+
return this.scheduler.fire(funcName, ...args);
16+
}
17+
}
18+
19+
export default NotifyScheduler;

packages/devextreme/js/__internal/scheduler/base/m_widget_observer.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/devextreme/js/__internal/scheduler/m_publisher_mixin.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/devextreme/js/__internal/scheduler/m_scheduler.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ import { getA11yStatusText } from './a11y_status/a11y_status_text';
3737
import { AppointmentForm } from './appointment_popup/m_form';
3838
import { ACTION_TO_APPOINTMENT, AppointmentPopup } from './appointment_popup/m_popup';
3939
import AppointmentCollection from './appointments/m_appointment_collection';
40+
import NotifyScheduler from './base/m_widget_notify_scheduler';
4041
import { SchedulerHeader } from './header/m_header';
4142
import type { HeaderOptions } from './header/types';
4243
import { CompactAppointmentsHelper } from './m_compact_appointments_helper';
4344
import { AppointmentTooltipInfo } from './m_data_structures';
4445
import { hide as hideLoading, show as showLoading } from './m_loading';
4546
import { getRecurrenceProcessor } from './m_recurrence';
47+
import type { SubscribeKey, SubscribeMethods } from './m_subscribes';
4648
import subscribes from './m_subscribes';
4749
import { utils } from './m_utils';
4850
import timeZoneUtils, { type TimezoneLabel } from './m_utils_time_zone';
@@ -196,6 +198,8 @@ class Scheduler extends SchedulerOptionsBaseWidget {
196198

197199
_subscribes: any;
198200

201+
_notifyScheduler!: NotifyScheduler;
202+
199203
_recurrenceDialog: any;
200204

201205
_layoutManager!: AppointmentLayoutManager;
@@ -742,6 +746,8 @@ class Scheduler extends SchedulerOptionsBaseWidget {
742746
this._subscribes = subscribes;
743747

744748
this.resourceManager = new ResourceManager(this.option('resources'));
749+
750+
this._notifyScheduler = new NotifyScheduler({ scheduler: this });
745751
}
746752

747753
createAppointmentDataProvider() {
@@ -1230,7 +1236,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
12301236

12311237
getAppointmentDataProvider: () => this.appointmentDataProvider,
12321238
dataAccessors: this._dataAccessors,
1233-
observer: this,
1239+
notifyScheduler: this._notifyScheduler,
12341240
onItemRendered: this._getAppointmentRenderedAction(),
12351241
onItemClick: this._createActionByOption('onAppointmentClick'),
12361242
onItemContextMenu: this._createActionByOption('onAppointmentContextMenu'),
@@ -1370,7 +1376,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
13701376
renovateRender: this._isRenovatedRender(isVirtualScrolling),
13711377
}, currentViewOptions);
13721378

1373-
result.observer = this;
1379+
result.notifyScheduler = this._notifyScheduler;
13741380
result.groups = groupsResources;
13751381
result.onCellClick = this._createActionByOption('onCellClick');
13761382
result.onCellContextMenu = this._createActionByOption('onCellContextMenu');
@@ -1713,15 +1719,17 @@ class Scheduler extends SchedulerOptionsBaseWidget {
17131719
this._subscribes[subject] = subscribes[subject] = action;
17141720
}
17151721

1716-
fire(subject) {
1722+
fire<Subject extends SubscribeKey>(
1723+
subject: Subject,
1724+
...args: Parameters<SubscribeMethods[Subject]>
1725+
): ReturnType<SubscribeMethods[Subject]> {
17171726
const callback = this._subscribes[subject];
1718-
const args = Array.prototype.slice.call(arguments);
17191727

17201728
if (!isFunction(callback)) {
17211729
throw errors.Error('E1031', subject);
17221730
}
17231731

1724-
return callback.apply(this, args.slice(1));
1732+
return callback.call(this, ...args);
17251733
}
17261734

17271735
getTargetCellData() {

packages/devextreme/js/__internal/scheduler/m_subscribes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,8 @@ const subscribes = {
316316
removeDroppableCellClass() {
317317
this._workSpace.removeDroppableCellClass();
318318
},
319-
};
319+
} as const;
320+
320321
export default subscribes;
322+
export type SubscribeMethods = typeof subscribes;
323+
export type SubscribeKey = keyof typeof subscribes;

packages/devextreme/js/__internal/scheduler/workspaces/m_work_space.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { getWindow, hasWindow } from '@js/core/utils/window';
3131
import type { dxSchedulerOptions } from '@js/ui/scheduler';
3232
import Scrollable from '@js/ui/scroll_view/ui.scrollable';
3333
import errors from '@js/ui/widget/ui.errors';
34+
import Widget from '@js/ui/widget/ui.widget';
3435
import { getMemoizeScrollTo } from '@ts/core/utils/scroll';
3536
import {
3637
AllDayPanelTitleComponent,
@@ -51,7 +52,7 @@ import {
5152
} from '@ts/scheduler/r1/utils/index';
5253
import type { SafeAppointment, ViewType } from '@ts/scheduler/types';
5354

54-
import WidgetObserver from '../base/m_widget_observer';
55+
import type NotifyScheduler from '../base/m_widget_notify_scheduler';
5556
import { APPOINTMENT_SETTINGS_KEY } from '../constants';
5657
import { Cache } from '../global_cache';
5758
import AppointmentDragBehavior from '../m_appointment_drag_behavior';
@@ -66,6 +67,7 @@ import {
6667
VERTICAL_GROUP_COUNT_CLASSES,
6768
VIRTUAL_CELL_CLASS,
6869
} from '../m_classes';
70+
import type { SubscribeKey, SubscribeMethods } from '../m_subscribes';
6971
import tableCreatorModule from '../m_table_creator';
7072
import { utils } from '../m_utils';
7173
import VerticalShader from '../shaders/m_current_time_shader_vertical';
@@ -109,8 +111,8 @@ const { tableCreator } = tableCreatorModule;
109111
// The constant is needed so that the dragging is not sharp. To prevent small twitches
110112
const DRAGGING_MOUSE_FAULT = 10;
111113

112-
// @ts-expect-error
113-
const { abstract } = WidgetObserver;
114+
// @ts-expect-error Widget exposes a static abstract() helper not typed in its d.ts
115+
const { abstract } = Widget;
114116
const toMs = dateUtils.dateToMilliseconds;
115117

116118
const COMPONENT_CLASS = 'dx-scheduler-work-space';
@@ -202,7 +204,7 @@ type WorkspaceOptionsInternal = Omit<dxSchedulerOptions, 'groups'> & {
202204
startDayHour: number;
203205
endDayHour: number;
204206
};
205-
class SchedulerWorkSpace extends WidgetObserver<WorkspaceOptionsInternal> {
207+
class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
206208
_viewDataProvider: any;
207209

208210
_cache: any;
@@ -393,6 +395,26 @@ class SchedulerWorkSpace extends WidgetObserver<WorkspaceOptionsInternal> {
393395
return this.option('draggingMode') === 'default';
394396
}
395397

398+
notifyObserver<Subject extends SubscribeKey>(
399+
funcName: Subject,
400+
args: Parameters<SubscribeMethods[Subject]>,
401+
): void {
402+
this.invoke(funcName, ...args);
403+
}
404+
405+
invoke<Subject extends SubscribeKey>(
406+
funcName: Subject,
407+
...args: Parameters<SubscribeMethods[Subject]>
408+
): ReturnType<SubscribeMethods[Subject]> | undefined {
409+
const notifyScheduler = this.option('notifyScheduler') as NotifyScheduler | undefined;
410+
411+
if (!notifyScheduler) {
412+
return undefined;
413+
}
414+
415+
return notifyScheduler.invoke(funcName, ...args);
416+
}
417+
396418
_supportedKeys() {
397419
const clickHandler = function (e) {
398420
e.preventDefault();

packages/devextreme/testing/tests/DevExpress.ui.widgets.scheduler/agenda.tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ module('Agenda', {}, () => {
3737
onContentReady: e => {
3838
e.component.onDataSourceChanged(rows);
3939
},
40-
observer: {
41-
fire: (functionName) => {
40+
notifyScheduler: {
41+
invoke: (functionName) => {
4242
if(functionName === 'getLayoutManager') {
4343
return {
4444
getRenderingStrategyInstance: () => {

0 commit comments

Comments
 (0)