Skip to content

Commit

Permalink
feat: remove old code and lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
redonkulus committed Dec 16, 2024
1 parent 542ff15 commit d10b486
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 132 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"author": "Hank Hsiao <hankxiao@yahoo-inc.com>",
"dependencies": {
"eventemitter3": "^5.0.0",
"lodash": "^4.17.15",
"raf": "^3.0.0"
},
"devDependencies": {
Expand Down Expand Up @@ -79,5 +78,6 @@
"prettier": {
"singleQuote": true,
"tabWidth": 4
}
},
"browserslist": "> 0.25%, not dead"
}
16 changes: 0 additions & 16 deletions src/lib/leIE8.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/lib/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

import assign from 'lodash/assign';
import globalVars from '../globalVars';

const { supportPassiveEvent } = globalVars;
Expand All @@ -29,7 +28,7 @@ function listen(target, eventType, handler, options) {
let type = eventType;

const eventOptions = supportPassiveEvent
? assign({}, defaultEventOption, options)
? Object.assign({}, defaultEventOption, options)
: false;

if (!target.addEventListener && target.attachEvent) {
Expand Down
33 changes: 17 additions & 16 deletions src/mainEventConnectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/

import clone from 'lodash/clone';
import throttle from 'lodash/throttle';
import noop from 'lodash/noop';

import AugmentedEvent from './AugmentedEvent';
import globalVars from './globalVars';
import leIE8 from './lib/leIE8';
import listen from './lib/listen';
import rAFThrottle from './lib/rAFThrottle';

Expand All @@ -34,6 +29,19 @@ function getHash(domNode) {
return domNode.id || `target-id-${hashId++}`; // eslint-disable-line
}

function noop() {}

function throttle(func, wait) {
let lastCall = 0;
return function (...args) {
const now = Date.now();
if (now - lastCall >= wait) {
lastCall = now;
func.apply(this, args);
}
};
}

/**
* Connect a throttled event to a throttled main event, and return an event remover.
* The number of connections to a throttled main event will be kept. If all throttled events
Expand Down Expand Up @@ -147,17 +155,10 @@ function connectContinuousEvent(target, mainEvent, event) {

ae.main.update(e);
EE.emit(throttledMainEvent, e, ae.main);
if (!leIE8) {
timer = setTimeout(
endCallback.bind(null, e),
throttleRate + EVENT_END_DELAY,
);
} else {
// For browser less then and equal to IE8, event object need to be cloned for setTimeout.
timer = setTimeout(() => {
endCallback(clone(e));
}, throttleRate + EVENT_END_DELAY);
}
timer = setTimeout(
endCallback.bind(null, e),
throttleRate + EVENT_END_DELAY,
);
}

listeners[throttledMainEvent] = listen(
Expand Down
7 changes: 0 additions & 7 deletions src/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import globalVars from './globalVars';
import leIE8 from './lib/leIE8'; // less then or equal to IE8
import mainEventConnectors from './mainEventConnectors';

// constants
Expand Down Expand Up @@ -34,12 +33,6 @@ function subscribe(type, cb, options = {}) {
throttleRate = 'raf';
}

// turn off throttle if the browser is IE8 or less, because window.event will be reset
// when using any delayed function, i.g., setTimeout, or rAF.
if (leIE8) {
throttleRate = 0;
}

// once those variables enabled, then never disabled.
globalVars.enableScrollInfo =
globalVars.enableScrollInfo || options.enableScrollInfo || false;
Expand Down
87 changes: 0 additions & 87 deletions tests/unit/subscribe-ie8.js

This file was deleted.

0 comments on commit d10b486

Please sign in to comment.