mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-01 01:04:06 +03:00
improve code
This commit is contained in:
@@ -58,7 +58,11 @@ export const OverlayScrollbars: OverlayScrollbarsStatic = (
|
||||
options?,
|
||||
eventListeners?
|
||||
): OverlayScrollbars => {
|
||||
const { _getDefaultOptions, _nativeScrollbarIsOverlaid } = getEnvironment();
|
||||
const {
|
||||
_getDefaultOptions,
|
||||
_nativeScrollbarIsOverlaid,
|
||||
_addListener: addEnvListener,
|
||||
} = getEnvironment();
|
||||
const plugins = getPlugins();
|
||||
const instanceTarget = isHTMLElement(target) ? target : target.target;
|
||||
const potentialInstance = getInstance(instanceTarget);
|
||||
@@ -130,6 +134,8 @@ export const OverlayScrollbars: OverlayScrollbarsStatic = (
|
||||
});
|
||||
});
|
||||
|
||||
const removeEnvListener = addEnvListener(update.bind(0, {}, true));
|
||||
|
||||
const instance: OverlayScrollbars = {
|
||||
options(newOptions?: PartialOptions<OSOptions>) {
|
||||
if (newOptions) {
|
||||
@@ -152,6 +158,7 @@ export const OverlayScrollbars: OverlayScrollbarsStatic = (
|
||||
},
|
||||
destroy: () => {
|
||||
removeInstance(instanceTarget);
|
||||
removeEnvListener();
|
||||
removeEvent();
|
||||
|
||||
destroyScrollbars();
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { runEach } from 'support';
|
||||
import { getEnvironment } from 'environment';
|
||||
import { createState, createOptionCheck } from 'setups/setups';
|
||||
import { createStructureSetupElements } from 'setups/structureSetup/structureSetup.elements';
|
||||
import {
|
||||
createStructureSetupUpdate,
|
||||
StructureSetupUpdateHints,
|
||||
} from 'setups/structureSetup/structureSetup.update';
|
||||
import { createStructureSetupUpdate } from 'setups/structureSetup/structureSetup.update';
|
||||
import { createStructureSetupObservers } from 'setups/structureSetup/structureSetup.observers';
|
||||
import type { StructureSetupUpdateHints } from 'setups/structureSetup/structureSetup.update';
|
||||
import type { StructureSetupElementsObj } from 'setups/structureSetup/structureSetup.elements';
|
||||
import type { TRBL, CacheValues, XY, WH } from 'support';
|
||||
import type { OSOptions } from 'options';
|
||||
@@ -91,10 +88,6 @@ export const createStructureSetup = (
|
||||
}
|
||||
);
|
||||
|
||||
const removeEnvListener = getEnvironment()._addListener(
|
||||
updateStructure.bind(0, checkOptionsFallback, {}, true)
|
||||
);
|
||||
|
||||
const structureSetupState = getUpdateState.bind(0) as (() => StructureSetupState) &
|
||||
StructureSetupStaticState;
|
||||
structureSetupState._addOnUpdatedListener = (listener) => {
|
||||
@@ -111,7 +104,6 @@ export const createStructureSetup = (
|
||||
structureSetupState,
|
||||
() => {
|
||||
onUpdatedListeners.clear();
|
||||
removeEnvListener();
|
||||
destroyObservers();
|
||||
destroyElements();
|
||||
},
|
||||
|
||||
@@ -292,20 +292,20 @@ describe('array utilities', () => {
|
||||
describe('runEach', () => {
|
||||
test('array', () => {
|
||||
const arr = [jest.fn(), null, jest.fn(), undefined, jest.fn()];
|
||||
runEach(arr);
|
||||
runEach(arr, ['a', 'b', 'c', 'd']);
|
||||
arr.forEach((fn) => {
|
||||
if (fn) {
|
||||
expect(fn).toHaveBeenCalled();
|
||||
expect(fn).toHaveBeenCalledWith('a', 'b', 'c', 'd');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('set', () => {
|
||||
const set = new Set([jest.fn(), null, jest.fn(), undefined, jest.fn()]);
|
||||
runEach(set);
|
||||
runEach(set, [1, 2, 3, 4]);
|
||||
set.forEach((fn) => {
|
||||
if (fn) {
|
||||
expect(fn).toHaveBeenCalled();
|
||||
expect(fn).toHaveBeenCalledWith(1, 2, 3, 4);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user