Skip to content

Commit

Permalink
fix(breakpoints): Using .update() breaks breakpoints functionality (#244
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jedrzejchalubek committed Jul 22, 2018
1 parent 9bab3c8 commit ccf66b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 6 additions & 10 deletions src/components/breakpoints.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { warn } from '../utils/log'
import { throttle } from '../utils/wait'
import { isObject } from '../utils/unit'
import { sortKeys } from '../utils/object'
import { sortKeys, mergeOptions } from '../utils/object'

import EventsBinder from '../core/event/events-binder'

Expand Down Expand Up @@ -37,17 +37,13 @@ export default function (Glide, Components, Events) {
let settings = Glide.settings

/**
* Holds reference to breakpoints object in settings
* Holds reference to breakpoints object in settings. Sorts breakpoints
* from smaller to larger. It is required in order to proper
* matching currently active breakpoint settings.
*
* @type {Object}
*/
let points = settings.breakpoints

/**
* Sort breakpoints from smaller to larger. It is required in order
* to proper matching currently active breakpoint settings.
*/
points = sortBreakpoints(points)
let points = sortBreakpoints(settings.breakpoints)

/**
* Cache initial settings before overwritting.
Expand Down Expand Up @@ -89,7 +85,7 @@ export default function (Glide, Components, Events) {
* - window resize to update slider
*/
Binder.on('resize', window, throttle(() => {
Object.assign(settings, Breakpoints.match(points))
Glide.settings = mergeOptions(settings, Breakpoints.match(points))
}, Glide.settings.throttle))

/**
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class Glide {
* @return {Glide}
*/
update (settings = {}) {
this.settings = Object.assign({}, this.settings, settings)
this.settings = mergeOptions(this.settings, settings)

if (settings.hasOwnProperty('startAt')) {
this.index = settings.startAt
Expand Down
4 changes: 4 additions & 0 deletions src/utils/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ export function mergeOptions (defaults, settings) {
}
}

if (settings.hasOwnProperty('breakpoints')) {
options.breakpoints = Object.assign({}, defaults.breakpoints, settings.breakpoints)
}

return options
}

0 comments on commit ccf66b3

Please sign in to comment.