From aa5de06a93169a2f27d456ce6b82a2bbc6bced55 Mon Sep 17 00:00:00 2001 From: vuquangpham Date: Fri, 24 Mar 2023 10:43:15 +0700 Subject: [PATCH 1/3] fix(response-navigation): bug with object allocation in memory --- src/helpers.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 13faa67..be2ff2d 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -16,19 +16,21 @@ export function init(el, object, flickityOptions){ return false; } + const options = {...flickityOptions, ...object}; + new MatchMediaScreen({ object, // breakpoint found - onMatched: data => onMatched(el, {...flickityOptions, ...data.object}), + onMatched: () => onMatched(el, options), // window resize with debounce - onUpdate: data => onResize(el, {...flickityOptions, ...data.object}) + onUpdate: () => onResize(el, options) }); // on load - onLoad(el, {...flickityOptions, ...object}); + onLoad(el, options); return true; } From bff9cda34da2e566ce68a6533076daac3e83ce8d Mon Sep 17 00:00:00 2001 From: vuquangpham Date: Wed, 5 Apr 2023 15:30:08 +0700 Subject: [PATCH 2/3] fix(response-navigation): bug with object in MatchMediaScreen library --- src/helpers.js | 5 +++-- src/utils.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index be2ff2d..601d972 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -2,6 +2,7 @@ import {MatchMediaScreen} from "match-media-screen"; import {onMatched} from "./on-matched"; import {onResize} from "./on-resize"; import {onLoad} from "./on-load"; +import {mergeObject} from "@/utils"; /** * Init Flickity Responsive @@ -22,10 +23,10 @@ export function init(el, object, flickityOptions){ object, // breakpoint found - onMatched: () => onMatched(el, options), + onMatched: (data) => onMatched(el, mergeObject(options, data.object)), // window resize with debounce - onUpdate: () => onResize(el, options) + onUpdate: (data) => onResize(el, mergeObject(options, data.object)) }); diff --git a/src/utils.js b/src/utils.js index 2cf90a2..bba91a8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -76,4 +76,18 @@ export function getJSONObjectFromString(string){ */ export function getElement(el){ return isjQueryElement(el) ? el.get()[0] : el; +} + + +/** + * Merge object withou change object memory address + * @param rootObject + * @param subObject + * @returns {object} + */ +export function mergeObject(rootObject, subObject){ + for(const [key, value] of Object.entries(subObject)){ + rootObject[key] = value; + } + return rootObject; } \ No newline at end of file From ba317f0f6acb0af6485adf4a3ddc8ccfd2de8dba Mon Sep 17 00:00:00 2001 From: vuquangpham Date: Wed, 5 Apr 2023 18:39:47 +0700 Subject: [PATCH 3/3] fix(response-navigation): revert code and add customArrow options into instance --- src/custom-arrows.js | 6 +++--- src/helpers.js | 9 +++------ src/responsive-navigation.js | 4 ++-- src/utils.js | 14 -------------- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/custom-arrows.js b/src/custom-arrows.js index bade281..fe5434f 100644 --- a/src/custom-arrows.js +++ b/src/custom-arrows.js @@ -40,7 +40,7 @@ export function initCustomArrows(flkty, options){ }); // save custom arrows - options.customArrows = customArrows; + flkty.options.customArrows = customArrows; // update disable status if(hasCustomArrow){ @@ -72,8 +72,8 @@ function getSlidePosition(flkty){ export function updateCustomArrowsDisableStatus(flkty, options){ // no disabled status if is wrapAround (infinite) if(options.isInfinite) return; - const prevArrow = options.customArrows.prevArrow.el; - const nextArrow = options.customArrows.nextArrow.el; + const prevArrow = flkty.options.customArrows.prevArrow.el; + const nextArrow = flkty.options.customArrows.nextArrow.el; const slidePosition = getSlidePosition(flkty); diff --git a/src/helpers.js b/src/helpers.js index 601d972..13faa67 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -2,7 +2,6 @@ import {MatchMediaScreen} from "match-media-screen"; import {onMatched} from "./on-matched"; import {onResize} from "./on-resize"; import {onLoad} from "./on-load"; -import {mergeObject} from "@/utils"; /** * Init Flickity Responsive @@ -17,21 +16,19 @@ export function init(el, object, flickityOptions){ return false; } - const options = {...flickityOptions, ...object}; - new MatchMediaScreen({ object, // breakpoint found - onMatched: (data) => onMatched(el, mergeObject(options, data.object)), + onMatched: data => onMatched(el, {...flickityOptions, ...data.object}), // window resize with debounce - onUpdate: (data) => onResize(el, mergeObject(options, data.object)) + onUpdate: data => onResize(el, {...flickityOptions, ...data.object}) }); // on load - onLoad(el, options); + onLoad(el, {...flickityOptions, ...object}); return true; } diff --git a/src/responsive-navigation.js b/src/responsive-navigation.js index 20007c6..f48e522 100644 --- a/src/responsive-navigation.js +++ b/src/responsive-navigation.js @@ -10,8 +10,8 @@ export function responsiveNavigation(flkty, options){ flkty.pageDots ? flkty.pageDots.holder : undefined, flkty.prevButton ? flkty.prevButton.element : undefined, flkty.nextButton ? flkty.nextButton.element : undefined, - options.customArrows ? options.customArrows.prevArrow.el : undefined, - options.customArrows ? options.customArrows.nextArrow.el : undefined + flkty.options.customArrows ? flkty.options.customArrows.prevArrow.el : undefined, + flkty.options.customArrows ? flkty.options.customArrows.nextArrow.el : undefined ]; const isSlideable = flkty.slideableWidth > flkty.size.innerWidth; diff --git a/src/utils.js b/src/utils.js index bba91a8..2cf90a2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -76,18 +76,4 @@ export function getJSONObjectFromString(string){ */ export function getElement(el){ return isjQueryElement(el) ? el.get()[0] : el; -} - - -/** - * Merge object withou change object memory address - * @param rootObject - * @param subObject - * @returns {object} - */ -export function mergeObject(rootObject, subObject){ - for(const [key, value] of Object.entries(subObject)){ - rootObject[key] = value; - } - return rootObject; } \ No newline at end of file