From 5557dd791329283ef34d301aa4ab0e9650969956 Mon Sep 17 00:00:00 2001 From: "Rochmar Nicolas (DevExpress)" Date: Fri, 19 Jul 2024 14:10:24 +0800 Subject: [PATCH] Migrate hover event to TS --- .../js/__internal/events/m_hover.ts | 135 ++++++++---------- packages/devextreme/js/events/hover.js | 15 ++ 2 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 packages/devextreme/js/events/hover.js diff --git a/packages/devextreme/js/__internal/events/m_hover.ts b/packages/devextreme/js/__internal/events/m_hover.ts index b75977591040..d28353334c2b 100644 --- a/packages/devextreme/js/__internal/events/m_hover.ts +++ b/packages/devextreme/js/__internal/events/m_hover.ts @@ -1,10 +1,10 @@ -import eventsEngine from '../events/core/events_engine'; -import { removeData, data as elementData } from '../core/element_data'; -import Class from '../core/class'; -import devices from '../core/devices'; -import registerEvent from './core/event_registrator'; -import { addNamespace, isTouchEvent, fireEvent } from './utils/index'; -import pointerEvents from './pointer'; +import Class from '@js/core/class'; +import devices from '@js/core/devices'; +import { data as elementData, removeData } from '@js/core/element_data'; +import registerEvent from '@js/events/core/event_registrator'; +import eventsEngine from '@js/events/core/events_engine'; +import pointerEvents from '@js/events/pointer'; +import { addNamespace, fireEvent, isTouchEvent } from '@js/events/utils/index'; const HOVERSTART_NAMESPACE = 'dxHoverStart'; const HOVERSTART = 'dxhoverstart'; @@ -14,100 +14,85 @@ const HOVEREND_NAMESPACE = 'dxHoverEnd'; const HOVEREND = 'dxhoverend'; const POINTERLEAVE_NAMESPACED_EVENT_NAME = addNamespace(pointerEvents.leave, HOVEREND_NAMESPACE); - const Hover = Class.inherit({ - noBubble: true, - - ctor: function() { - this._handlerArrayKeyPath = this._eventNamespace + '_HandlerStore'; - }, + noBubble: true, - setup: function(element) { - elementData(element, this._handlerArrayKeyPath, {}); - }, + ctor() { + this._handlerArrayKeyPath = `${this._eventNamespace}_HandlerStore`; + }, - add: function(element, handleObj) { - const that = this; - const handler = function(e) { - that._handler(e); - }; + setup(element) { + elementData(element, this._handlerArrayKeyPath, {}); + }, - eventsEngine.on(element, this._originalEventName, handleObj.selector, handler); - elementData(element, this._handlerArrayKeyPath)[handleObj.guid] = handler; - }, + add(element, handleObj) { + const that = this; + const handler = function (e) { + that._handler(e); + }; - _handler: function(e) { - if(isTouchEvent(e) || devices.isSimulator()) { - return; - } + eventsEngine.on(element, this._originalEventName, handleObj.selector, handler); + elementData(element, this._handlerArrayKeyPath)[handleObj.guid] = handler; + }, - fireEvent({ - type: this._eventName, - originalEvent: e, - delegateTarget: e.delegateTarget - }); - }, + _handler(e) { + if (isTouchEvent(e) || devices.isSimulator()) { + return; + } - remove: function(element, handleObj) { - const handler = elementData(element, this._handlerArrayKeyPath)[handleObj.guid]; + fireEvent({ + type: this._eventName, + originalEvent: e, + delegateTarget: e.delegateTarget, + }); + }, - eventsEngine.off(element, this._originalEventName, handleObj.selector, handler); - }, + remove(element, handleObj) { + const handler = elementData(element, this._handlerArrayKeyPath)[handleObj.guid]; + // @ts-expect-error + eventsEngine.off(element, this._originalEventName, handleObj.selector, handler); + }, - teardown: function(element) { - removeData(element, this._handlerArrayKeyPath); - } + teardown(element) { + removeData(element, this._handlerArrayKeyPath); + }, }); const HoverStart = Hover.inherit({ - ctor: function() { - this._eventNamespace = HOVERSTART_NAMESPACE; - this._eventName = HOVERSTART; - this._originalEventName = POINTERENTER_NAMESPACED_EVENT_NAME; - this.callBase(); - }, - - _handler: function(e) { - const pointers = e.pointers || []; - if(!pointers.length) { - this.callBase(e); - } + ctor() { + this._eventNamespace = HOVERSTART_NAMESPACE; + this._eventName = HOVERSTART; + this._originalEventName = POINTERENTER_NAMESPACED_EVENT_NAME; + this.callBase(); + }, + + _handler(e) { + const pointers = e.pointers || []; + if (!pointers.length) { + this.callBase(e); } + }, }); const HoverEnd = Hover.inherit({ - ctor: function() { - this._eventNamespace = HOVEREND_NAMESPACE; - this._eventName = HOVEREND; - this._originalEventName = POINTERLEAVE_NAMESPACED_EVENT_NAME; - this.callBase(); - } + ctor() { + this._eventNamespace = HOVEREND_NAMESPACE; + this._eventName = HOVEREND; + this._originalEventName = POINTERLEAVE_NAMESPACED_EVENT_NAME; + this.callBase(); + }, }); -/** - * @name UI Events.dxhoverstart - * @type eventType - * @type_function_param1 event:event - * @module events/hover -*/ - -/** - * @name UI Events.dxhoverend - * @type eventType - * @type_function_param1 event:event - * @module events/hover -*/ - registerEvent(HOVERSTART, new HoverStart()); registerEvent(HOVEREND, new HoverEnd()); export { - HOVERSTART as start, - HOVEREND as end + HOVEREND as end, + HOVERSTART as start, }; diff --git a/packages/devextreme/js/events/hover.js b/packages/devextreme/js/events/hover.js new file mode 100644 index 000000000000..e603188362d0 --- /dev/null +++ b/packages/devextreme/js/events/hover.js @@ -0,0 +1,15 @@ +/** + * @name UI Events.dxhoverstart + * @type eventType + * @type_function_param1 event:event + * @module events/hover +*/ + +/** + * @name UI Events.dxhoverend + * @type eventType + * @type_function_param1 event:event + * @module events/hover +*/ + +export * from '../__internal/events/m_hover';