Skip to content

Commit

Permalink
Migrate hover event to TS
Browse files Browse the repository at this point in the history
  • Loading branch information
Rochmar Nicolas (DevExpress) committed Jul 19, 2024
1 parent ff90981 commit 5557dd7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 75 deletions.
135 changes: 60 additions & 75 deletions packages/devextreme/js/__internal/events/m_hover.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
};
15 changes: 15 additions & 0 deletions packages/devextreme/js/events/hover.js
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 5557dd7

Please sign in to comment.