mirror of
https://github.com/tenrok/OverlayScrollbars.git
synced 2026-06-07 05:02:26 +03:00
improve project structure
This commit is contained in:
@@ -9,7 +9,6 @@ const testServerLoaderPath = path.resolve(__dirname, './config/jest-test-server.
|
||||
// https://jestjs.io/docs/en/configuration.html
|
||||
|
||||
const base = {
|
||||
cache: false,
|
||||
clearMocks: true,
|
||||
collectCoverage: true,
|
||||
coverageDirectory: './.coverage',
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
CacheUpdateInfo,
|
||||
CachePropsToUpdate,
|
||||
CacheChanged,
|
||||
CacheUpdated,
|
||||
OptionsWithOptionsTemplate,
|
||||
OptionsValidated,
|
||||
transformOptions,
|
||||
@@ -41,7 +41,7 @@ export const createLifecycleBase = <O, C>(
|
||||
defaultOptionsWithTemplate: OptionsWithOptionsTemplate<Required<O>>,
|
||||
cacheUpdateInfo: CacheUpdateInfo<C>,
|
||||
initialOptions: O | undefined,
|
||||
updateFunction: (changedOptions: OptionsValidated<O>, changedCache: CacheChanged<C>) => any
|
||||
updateFunction: (changedOptions: OptionsValidated<O>, changedCache: CacheUpdated<C>) => any
|
||||
): LifecycleBase<O, C> => {
|
||||
const { _template: optionsTemplate, _options: defaultOptions } = transformOptions<Required<O>>(defaultOptionsWithTemplate);
|
||||
const options: Required<O> = assignDeep({}, defaultOptions, validateOptions<O>(initialOptions || ({} as O), optionsTemplate)._validated);
|
||||
+3
-3
@@ -12,10 +12,10 @@ import {
|
||||
optionsTemplateTypes as oTypes,
|
||||
OptionsTemplateValue,
|
||||
} from 'support';
|
||||
import { createLifecycleBase, Lifecycle } from 'overlayscrollbars/lifecycles';
|
||||
import { createLifecycleBase, Lifecycle } from 'lifecycles/lifecycleBase';
|
||||
import { getEnvironment, Environment } from 'environment';
|
||||
import { createSizeObserver } from 'overlayscrollbars/observers/SizeObserver';
|
||||
import { createTrinsicObserver } from 'overlayscrollbars/observers/TrinsicObserver';
|
||||
import { createSizeObserver } from 'observers/sizeObserver';
|
||||
import { createTrinsicObserver } from 'observers/trinsicObserver';
|
||||
|
||||
export type OverflowBehavior = 'hidden' | 'scroll' | 'visible-hidden' | 'visible-scroll';
|
||||
export interface StructureLifecycleOptions {
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { createDOM, offsetSize, jsAPI, runEach, prependChildren, removeElements } from 'support';
|
||||
import { createSizeObserver } from 'overlayscrollbars/observers/SizeObserver';
|
||||
import { createSizeObserver } from 'observers/sizeObserver';
|
||||
|
||||
const classNameTrinsicObserver = 'os-trinsic-observer';
|
||||
const IntersectionObserverConstructor = jsAPI('IntersectionObserver');
|
||||
+14
-12
@@ -1,4 +1,6 @@
|
||||
import { each, keys, isArray, isString } from 'support';
|
||||
import { isArray, isString } from 'support/utils/types';
|
||||
import { keys } from 'support/utils/object';
|
||||
import { each } from 'support/utils/array';
|
||||
|
||||
interface CacheEntry<T> {
|
||||
_current?: T;
|
||||
@@ -10,22 +12,22 @@ type Cache<T> = {
|
||||
[P in keyof T]: CacheEntry<T[P]>;
|
||||
};
|
||||
|
||||
type UpdateCacheProp<T> = <P extends keyof T>(prop: P, value: T[P], compare: CacheEqualFunction<T, P> | null) => void;
|
||||
type UpdateCacheProp<T> = <P extends keyof T>(prop: P, value: T[P], compare: EqualCachePropFunction<T, P> | null) => void;
|
||||
|
||||
type UpdateCachePropFunction<T, P extends keyof T> = (current?: T[P], previous?: T[P]) => T[P];
|
||||
|
||||
type EqualCachePropFunction<T, P extends keyof T> = (a?: T[P], b?: T[P]) => boolean;
|
||||
|
||||
export type CachePropsToUpdate<T> = Array<keyof T> | keyof T;
|
||||
|
||||
export type CacheUpdateFunction<T, P extends keyof T> = (current?: T[P], previous?: T[P]) => T[P];
|
||||
export type CacheUpdate<T> = (propsToUpdate?: CachePropsToUpdate<T>, force?: boolean) => CacheUpdated<T>;
|
||||
|
||||
export type CacheEqualFunction<T, P extends keyof T> = (a?: T[P], b?: T[P]) => boolean;
|
||||
|
||||
export type CacheChange<T> = (propsToUpdate?: CachePropsToUpdate<T>, force?: boolean) => CacheChanged<T>;
|
||||
|
||||
export type CacheChanged<T> = {
|
||||
export type CacheUpdated<T> = {
|
||||
[P in keyof T]?: T[P];
|
||||
};
|
||||
|
||||
export type CacheUpdateInfo<T> = {
|
||||
[P in keyof T]: CacheUpdateFunction<T, P> | [CacheUpdateFunction<T, P>, CacheEqualFunction<T, P>];
|
||||
[P in keyof T]: UpdateCachePropFunction<T, P> | [UpdateCachePropFunction<T, P>, EqualCachePropFunction<T, P>];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -46,7 +48,7 @@ export type CacheUpdateInfo<T> = {
|
||||
* @returns A function which can be called with wither one ar an array of properties which shall be updated. Optionally it can be called with the force param.
|
||||
* This function returns a object which contains all changed cache properties, if a property isn't in this object it means that it didn't change.
|
||||
*/
|
||||
export const createCache = <T>(cacheUpdateInfo: CacheUpdateInfo<T>): CacheChange<T> => {
|
||||
export const createCache = <T>(cacheUpdateInfo: CacheUpdateInfo<T>): CacheUpdate<T> => {
|
||||
const cache: Cache<T> = {} as T;
|
||||
const allProps: Array<keyof T> = keys(cacheUpdateInfo) as Array<keyof T>;
|
||||
|
||||
@@ -62,8 +64,8 @@ export const createCache = <T>(cacheUpdateInfo: CacheUpdateInfo<T>): CacheChange
|
||||
cache[prop]._changed = equal ? !equal(curr, value) : curr !== value;
|
||||
};
|
||||
|
||||
const flush = (force?: boolean): CacheChanged<T> => {
|
||||
const result: CacheChanged<T> = {} as CacheChanged<T>;
|
||||
const flush = (force?: boolean): CacheUpdated<T> => {
|
||||
const result: CacheUpdated<T> = {} as CacheUpdated<T>;
|
||||
|
||||
each(allProps, (prop: keyof T) => {
|
||||
if (cache[prop]._changed || force) {
|
||||
|
||||
@@ -8,8 +8,8 @@ describe('Environment', () => {
|
||||
|
||||
it('should be titled "Environment"', async () => {
|
||||
// @ts-ignore
|
||||
const a: Environment = await page.evaluate(() => window.Environment.envInstance);
|
||||
const a: Environment = await page.evaluate(() => window.environment.envInstance);
|
||||
console.log(a);
|
||||
await expect(page.title()).resolves.toMatch('Environment');
|
||||
await expect(page.title()).resolves.toMatch('environment');
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import 'overlayscrollbars.scss';
|
||||
import './index.scss';
|
||||
import { createStructureLifecycle } from 'overlayscrollbars/lifecycles/StructureLifecycle';
|
||||
import { createStructureLifecycle } from 'lifecycles/structureLifecycle';
|
||||
|
||||
const targetElm = document.querySelector('#target') as HTMLElement;
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ describe('StructureLifecycle', () => {
|
||||
|
||||
it('should be titled "Environment"', async () => {
|
||||
// @ts-ignore
|
||||
const a: Environment = await page.evaluate(() => window.Environment.envInstance);
|
||||
const a: Environment = await page.evaluate(() => window.structureLifecycle.envInstance);
|
||||
console.log(a);
|
||||
await expect(page.title()).resolves.toMatch('Environment');
|
||||
await expect(page.title()).resolves.toMatch('structureLifecycle');
|
||||
});
|
||||
});
|
||||
+1
-1
@@ -6,7 +6,7 @@ import { generateSelectCallback, iterateSelect } from '@/testing-browser/Select'
|
||||
import { setTestResult } from '@/testing-browser/TestResult';
|
||||
import { hasDimensions, offsetSize, WH, style } from 'support';
|
||||
|
||||
import { createSizeObserver } from 'overlayscrollbars/observers/SizeObserver';
|
||||
import { createSizeObserver } from 'observers/sizeObserver';
|
||||
|
||||
let sizeIterations = 0;
|
||||
let directionIterations = 0;
|
||||
+1
-1
@@ -7,7 +7,7 @@ import { timeout } from '@/testing-browser/timeout';
|
||||
import { setTestResult } from '@/testing-browser/TestResult';
|
||||
import { offsetSize } from 'support';
|
||||
|
||||
import { createTrinsicObserver } from 'overlayscrollbars/observers/TrinsicObserver';
|
||||
import { createTrinsicObserver } from 'observers/trinsicObserver';
|
||||
|
||||
const waitForOptions = {
|
||||
onTimeout(error: Error): Error {
|
||||
@@ -27,7 +27,7 @@ const rollupConfigDefaults = {
|
||||
};
|
||||
|
||||
const legacyBabelConfig = {
|
||||
exclude: isTestEnv ? [/\/core-js\//] : [],
|
||||
exclude: isTestEnv ? [/\/core-js\//, /\/@testing-library\//] : [],
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
|
||||
Reference in New Issue
Block a user