Skip to content

Commit

Permalink
Renovation: get rid of Actions (#11962)
Browse files Browse the repository at this point in the history
  • Loading branch information
churkin authored Feb 13, 2020
1 parent 7952153 commit 17a756f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
13 changes: 8 additions & 5 deletions js/events/short.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ function addNamespace(event, namespace) {
return namespace ? pureAddNamespace(event, namespace) : event;
}

function executeAction(action, args) {
return typeof action === 'function' ? action(args) : action.execute(args);
}

export const active = {
on: ($el, active, inactive, opts) => {
const { selector, showTimeout, hideTimeout, namespace } = opts;

eventsEngine.on($el, addNamespace('dxactive', namespace), selector, { timeout: showTimeout },
event => active.execute({ event, element: event.currentTarget })
event => executeAction(active, { event, element: event.currentTarget })
);
eventsEngine.on($el, addNamespace('dxinactive', namespace), selector, { timeout: hideTimeout },
event => inactive.execute({ event, element: event.currentTarget })
event => executeAction(inactive, { event, element: event.currentTarget })
);
},

Expand All @@ -37,9 +41,8 @@ export const resize = {
export const hover = {
on: ($el, start, end, { selector, namespace }) => {
eventsEngine.on($el, addNamespace('dxhoverend', namespace), selector, event => end(event));
eventsEngine.on($el, addNamespace('dxhoverstart', namespace), selector, event => {
start.execute({ element: event.target, event });
});
eventsEngine.on($el, addNamespace('dxhoverstart', namespace), selector,
event => executeAction(start, { element: event.target, event }));
},

off: ($el, { selector, namespace }) => {
Expand Down
19 changes: 6 additions & 13 deletions js/renovation/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { extend } from '../core/utils/extend';
import { focusable } from '../ui/widget/selectors';
import { isFakeClickEvent } from '../events/utils';
import { hasWindow } from '../core/utils/window';
import Action from '../core/action';

const getStyles = ({ width, height }) => {
const computedWidth = typeof width === 'function' ? width() : width;
Expand Down Expand Up @@ -251,12 +250,8 @@ export default class Widget extends JSXComponent<WidgetInput> {

if (isHoverable) {
hover.on(this.widgetRef,
new Action(() => {
if (!this._active) {
this._hovered = true;
}
}, { excludeValidators: ['readOnly'] }),
() => { this._hovered = false; },
() => !this._active && (this._hovered = true),
() => this._hovered = false,
{ selector, namespace },
);

Expand All @@ -277,16 +272,14 @@ export default class Widget extends JSXComponent<WidgetInput> {

if (activeStateEnabled && !disabled) {
active.on(this.widgetRef,
new Action(({ event }) => {
({ event }) => {
this._active = true;
onActive?.(event);
}),
new Action(({ event }) => {
},
({ event }) => {
this._active = false;
onInactive?.(event);
},
{ excludeValidators: ['disabled', 'readOnly'] },
), {
}, {
showTimeout: _feedbackShowTimeout,
hideTimeout: _feedbackHideTimeout,
selector,
Expand Down

0 comments on commit 17a756f

Please sign in to comment.