Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Return deselected items
Browse files Browse the repository at this point in the history
When setting items where the new iterable is missing previously selected items, return them in `getChangedDeselection`.
  • Loading branch information
hpurmann committed Aug 8, 2016
1 parent 3bff301 commit 9aea932
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/operations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
clone,
curry,
difference,
flow,
includes,
intersection,
Expand All @@ -27,7 +28,7 @@ const setItems = curry((itemsIterable, state) => {
selected: intersection(state.selected, items),
changed: {
selected: [],
deselected: [],
deselected: difference(state.selected, items),
},
anchor: includes(state.anchor, items) ? state.anchor : null,
}
Expand Down
12 changes: 12 additions & 0 deletions test/set-items.ut.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { flow } from 'lodash/fp'
import {
getChangedDeselection,
getSelection,
init,
rangeTo,
Expand All @@ -24,6 +25,17 @@ describe('setItems - updating the list of selectable items', () => {
expectExactlySameMembers(getSelection(newState), ['C'])
})

it('should return previously selected items as newly deselected', () => {
const state = init()

const newState = flow(
setItems(iterable(['A', 'B'])),
setSelection(['B']),
setItems(iterable(['A']))
)(state)

expectExactlySameMembers(getChangedDeselection(newState), ['B'])
})
})

it('should remove item from anchor that doesn\'t exist anymore', () => {
Expand Down

0 comments on commit 9aea932

Please sign in to comment.