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