Skip to content

Commit a14cb42

Browse files
committed
use findIndex in removeElement(), guard for elements that are not found in updateElement()
1 parent a5651ae commit a14cb42

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/libs/ParallaxController.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ function ParallaxController() {
340340
* @param {object} element
341341
*/
342342
this.removeElement = function(element) {
343-
const index = elements.indexOf(element);
343+
// gets the index of the element to update based on id
344+
const index = elements.findIndex(el => el.id === element.id);
345+
344346
if (index !== -1) {
345347
elements.splice(index, 1);
346348
}
@@ -356,10 +358,12 @@ function ParallaxController() {
356358
const index = elements.findIndex(el => el.id === element.id);
357359

358360
// create new element with options and replaces the old
359-
elements[index] = Object.assign({}, elements[index], options);
361+
if (index !== -1) {
362+
elements[index] = Object.assign({}, elements[index], options);
360363

361-
// call update to set attributes and positions based on the new options
362-
this.update();
364+
// call update to set attributes and positions based on the new options
365+
this.update();
366+
}
363367
};
364368

365369
/**

0 commit comments

Comments
 (0)