Skip to content

Commit 6755626

Browse files
Calendar, CalendarViews, Swipeable, DropDownButton: convert into ES6 class (DevExpress#29217)
1 parent ca9503a commit 6755626

File tree

9 files changed

+1168
-852
lines changed

9 files changed

+1168
-852
lines changed

packages/devextreme/js/__internal/events/gesture/m_swipeable.ts

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
swipe as swipeEventSwipe,
66
} from '@js/common/core/events/swipe';
77
import { addNamespace } from '@js/common/core/events/utils/index';
8-
import DOMComponent from '@js/core/dom_component';
9-
import { extend } from '@js/core/utils/extend';
8+
import type { Properties as DOMComponentProperties } from '@js/core/dom_component';
109
import { each } from '@js/core/utils/iterator';
1110
import { name } from '@js/core/utils/public_component';
11+
import DOMComponent from '@ts/core/widget/dom_component';
12+
import type { OptionChanged } from '@ts/core/widget/types';
1213

1314
const DX_SWIPEABLE = 'dxSwipeable';
1415
const SWIPEABLE_CLASS = 'dx-swipeable';
@@ -21,11 +22,26 @@ const ACTION_TO_EVENT_MAP = {
2122
};
2223

2324
const IMMEDIATE_TIMEOUT = 180;
24-
// @ts-expect-error
25-
const Swipeable = DOMComponent.inherit({
2625

27-
_getDefaultOptions() {
28-
return extend(this.callBase(), {
26+
export interface SwipeableProperties extends DOMComponentProperties {
27+
elastic?: boolean;
28+
immediate?: boolean;
29+
immediateTimeout?: number;
30+
direction?: string;
31+
itemSizeFunc?: (() => number) | null;
32+
onStart?: ((e) => void) | null;
33+
onUpdated?: ((e) => void) | null;
34+
onEnd?: ((e) => void) | null;
35+
onCancel?: ((e) => void) | null;
36+
disabled?: boolean;
37+
}
38+
39+
class Swipeable extends DOMComponent<Swipeable, SwipeableProperties> {
40+
_eventData?: Record<string, unknown>;
41+
42+
_getDefaultOptions(): SwipeableProperties {
43+
return {
44+
...super._getDefaultOptions(),
2945
elastic: true,
3046
immediate: false,
3147
immediateTimeout: IMMEDIATE_TIMEOUT,
@@ -35,17 +51,17 @@ const Swipeable = DOMComponent.inherit({
3551
onUpdated: null,
3652
onEnd: null,
3753
onCancel: null,
38-
});
39-
},
54+
};
55+
}
4056

41-
_render() {
42-
this.callBase();
57+
_render(): void {
58+
super._render();
4359

4460
this.$element().addClass(SWIPEABLE_CLASS);
4561
this._attachEventHandlers();
46-
},
62+
}
4763

48-
_attachEventHandlers() {
64+
_attachEventHandlers(): void {
4965
this._detachEventHandlers();
5066

5167
if (this.option('disabled')) {
@@ -57,29 +73,29 @@ const Swipeable = DOMComponent.inherit({
5773
this._createEventData();
5874

5975
each(ACTION_TO_EVENT_MAP, (actionName, eventName) => {
76+
// @ts-expect-error ts-error
6077
const action = this._createActionByOption(actionName, { context: this });
61-
78+
// @ts-expect-error ts-error
6279
eventName = addNamespace(eventName, NAME);
63-
6480
eventsEngine.on(this.$element(), eventName, this._eventData, (e) => action({ event: e }));
6581
});
66-
},
82+
}
6783

68-
_createEventData() {
84+
_createEventData(): void {
6985
this._eventData = {
7086
elastic: this.option('elastic'),
7187
itemSizeFunc: this.option('itemSizeFunc'),
7288
direction: this.option('direction'),
7389
immediate: this.option('immediate'),
7490
immediateTimeout: this.option('immediateTimeout'),
7591
};
76-
},
92+
}
7793

78-
_detachEventHandlers() {
94+
_detachEventHandlers(): void {
7995
eventsEngine.off(this.$element(), `.${DX_SWIPEABLE}`);
80-
},
96+
}
8197

82-
_optionChanged(args) {
98+
_optionChanged(args: OptionChanged<SwipeableProperties>): void {
8399
switch (args.name) {
84100
case 'disabled':
85101
case 'onStart':
@@ -96,14 +112,15 @@ const Swipeable = DOMComponent.inherit({
96112
case 'rtlEnabled':
97113
break;
98114
default:
99-
this.callBase(args);
115+
super._optionChanged(args);
100116
}
101-
},
117+
}
102118

103-
_useTemplates() {
119+
// eslint-disable-next-line class-methods-use-this
120+
_useTemplates(): boolean {
104121
return false;
105-
},
106-
});
122+
}
123+
}
107124

108125
name(Swipeable, DX_SWIPEABLE);
109126

0 commit comments

Comments
 (0)