From 79f948e3a7b7ae42f276eb0f34b2fccdbeb7056e Mon Sep 17 00:00:00 2001 From: Valmisson Grizorte Date: Mon, 4 Mar 2024 05:40:40 -0300 Subject: [PATCH] fix: options passed in a function are overriding global options --- src/functions/scrolling.ts | 12 ++++++------ src/shared/scrolling.ts | 7 ++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/functions/scrolling.ts b/src/functions/scrolling.ts index 2d0efe0..b93ff49 100644 --- a/src/functions/scrolling.ts +++ b/src/functions/scrolling.ts @@ -26,7 +26,7 @@ export const scrollPosition = async ( position = { x: 0, y: position } } - const opts = Object.assign(globalOptions, options) + const opts = Object.assign({}, globalOptions, options) const endPosition = position const { duration, offset, onStart, onDone } = opts @@ -52,7 +52,7 @@ export const scrollElement = async ( throw new Error('scrollElement require a reference valid') } - const opts = Object.assign(globalOptions, options) + const opts = Object.assign({}, globalOptions, options) const ref = sanitize(reference) const elementsList = get(elements) @@ -76,7 +76,7 @@ export const scrollElement = async ( export const scrollTop = async ( options?: Partial ): Promise => { - const opts = Object.assign(globalOptions, options) + const opts = Object.assign({}, globalOptions, options) const endPosition = { x: 0, y: 0 } await scrollPosition(endPosition, opts) @@ -91,7 +91,7 @@ export const scrollTop = async ( export const scrollBottom = async ( options?: Partial ): Promise => { - const opts = Object.assign(globalOptions, options) + const opts = Object.assign({}, globalOptions, options) const body = document.body const html = document.documentElement @@ -119,7 +119,7 @@ export const scrollBottom = async ( export const scrollLeft = async ( options?: Partial ): Promise => { - const opts = Object.assign(globalOptions, options) + const opts = Object.assign({}, globalOptions, options) const endPosition = { x: 0, y: 0 } await scrollPosition(endPosition, opts) @@ -134,7 +134,7 @@ export const scrollLeft = async ( export const scrollRight = async ( options?: Partial ): Promise => { - const opts = Object.assign(globalOptions, options) + const opts = Object.assign({}, globalOptions, options) const body = document.body const html = document.documentElement diff --git a/src/shared/scrolling.ts b/src/shared/scrolling.ts index 9af1168..805305b 100644 --- a/src/shared/scrolling.ts +++ b/src/shared/scrolling.ts @@ -1,14 +1,11 @@ import smoothScroll from './smoothScroll' -import { getGlobalOptions } from '../internal/globalOptions' import type { Coord, GlobalOptions } from '../types/options' -const globalOptions = getGlobalOptions() - const scrolling = async ( coord: Coord, - opts: GlobalOptions + options: GlobalOptions ): Promise => { - const { duration, easing, offset } = Object.assign(globalOptions, opts) + const { duration, easing, offset } = options const startY = window.pageYOffset const startX = window.pageXOffset