Skip to content

Commit

Permalink
use findIndex in removeElement(), guard for elements that are not fou…
Browse files Browse the repository at this point in the history
…nd in updateElement()
  • Loading branch information
jscottsmith committed Sep 21, 2017
1 parent a5651ae commit a14cb42
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/libs/ParallaxController.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ function ParallaxController() {
* @param {object} element
*/
this.removeElement = function(element) {
const index = elements.indexOf(element);
// gets the index of the element to update based on id
const index = elements.findIndex(el => el.id === element.id);

if (index !== -1) {
elements.splice(index, 1);
}
Expand All @@ -356,10 +358,12 @@ function ParallaxController() {
const index = elements.findIndex(el => el.id === element.id);

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

// call update to set attributes and positions based on the new options
this.update();
// call update to set attributes and positions based on the new options
this.update();
}
};

/**
Expand Down

0 comments on commit a14cb42

Please sign in to comment.