Skip to content

Commit

Permalink
Only notify of selection change for events triggered from this librar…
Browse files Browse the repository at this point in the history
…y to avoid recursive crazyness
  • Loading branch information
gidztech committed May 9, 2017
1 parent 61e5225 commit fd06aca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions demo/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/simple-list-item-range-selector.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-list-item-range-selector",
"version": "1.0.4",
"version": "1.0.5",
"description": "Small UI library that allows you to take a list of items and attach selection events to it",
"main": "dist/simple-list-item-range-selector.js",
"scripts": {
Expand Down
16 changes: 9 additions & 7 deletions src/js/simple-list-item-range-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ let SimpleListItemRangeSelector = {
}
}

function _updateDOM(selection) {
function _updateDOM(selection, notify) {
let selectedItems = [];
let sortedSelection = selection.concat().sort();

Expand All @@ -143,7 +143,9 @@ let SimpleListItemRangeSelector = {
}
}

_onSelectionChanged(selectedItems);
if (notify) {
_onSelectionChanged(selectedItems);
}
}

function _updateSelection(e, updateDOM) {
Expand Down Expand Up @@ -177,7 +179,7 @@ let SimpleListItemRangeSelector = {
// first item selected had shift modified applied so just select it normally
_newSelection.push(selectedItemIndex);
_lastClickedIndexWithoutShift = selectedItemIndex;
updateDOM(_newSelection);
updateDOM(_newSelection, true);
return;
}

Expand Down Expand Up @@ -231,7 +233,7 @@ let SimpleListItemRangeSelector = {
}
}

updateDOM(_newSelection);
updateDOM(_newSelection, true);
}

function _selectItemsWithinRange({start, end}) {
Expand Down Expand Up @@ -273,7 +275,7 @@ let SimpleListItemRangeSelector = {

function _clearAllSelectionsHandler() {
_newSelection = [];
_updateDOM(_newSelection);
_updateDOM(_newSelection, false);
}

function _preventDefaultHandler(e) {
Expand Down Expand Up @@ -316,7 +318,7 @@ let SimpleListItemRangeSelector = {
_newSelection.push(index);
}

_updateDOM(_newSelection);
_updateDOM(_newSelection, false);
}

function _unselectItem(item) {
Expand All @@ -325,7 +327,7 @@ let SimpleListItemRangeSelector = {
_unselectItemAtIndex(index);
}

_updateDOM(_newSelection);
_updateDOM(_newSelection, false);
}

function _disableRangeSelection() {
Expand Down

0 comments on commit fd06aca

Please sign in to comment.