Skip to content

Commit

Permalink
fix: options passed in a function are overriding global options
Browse files Browse the repository at this point in the history
  • Loading branch information
valmisson committed Mar 4, 2024
1 parent 0766716 commit 79f948e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/functions/scrolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -76,7 +76,7 @@ export const scrollElement = async (
export const scrollTop = async (
options?: Partial<GlobalOptions>
): Promise<void> => {
const opts = Object.assign(globalOptions, options)
const opts = Object.assign({}, globalOptions, options)
const endPosition = { x: 0, y: 0 }

await scrollPosition(endPosition, opts)
Expand All @@ -91,7 +91,7 @@ export const scrollTop = async (
export const scrollBottom = async (
options?: Partial<GlobalOptions>
): Promise<void> => {
const opts = Object.assign(globalOptions, options)
const opts = Object.assign({}, globalOptions, options)

const body = document.body
const html = document.documentElement
Expand Down Expand Up @@ -119,7 +119,7 @@ export const scrollBottom = async (
export const scrollLeft = async (
options?: Partial<GlobalOptions>
): Promise<void> => {
const opts = Object.assign(globalOptions, options)
const opts = Object.assign({}, globalOptions, options)
const endPosition = { x: 0, y: 0 }

await scrollPosition(endPosition, opts)
Expand All @@ -134,7 +134,7 @@ export const scrollLeft = async (
export const scrollRight = async (
options?: Partial<GlobalOptions>
): Promise<void> => {
const opts = Object.assign(globalOptions, options)
const opts = Object.assign({}, globalOptions, options)

const body = document.body
const html = document.documentElement
Expand Down
7 changes: 2 additions & 5 deletions src/shared/scrolling.ts
Original file line number Diff line number Diff line change
@@ -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<void> => {
const { duration, easing, offset } = Object.assign(globalOptions, opts)
const { duration, easing, offset } = options

const startY = window.pageYOffset
const startX = window.pageXOffset
Expand Down

0 comments on commit 79f948e

Please sign in to comment.