   template = getTemplate(element)
   return unless isCheckable(element)
   if check
-    ids = template.collection.find().forEach (doc) -> doc._id
+    ids = template.collection.find().map (doc) -> doc._id
     changedIds = template.check.setIds(ids).added
     handleCheckResult(element, {added: changedIds, removed: []})
   else

  deselectNode: deselectNode
  setSelectedIds: setSelectedIds
  getSelectedIds: getSelectedIds
  deselectAll: deselectAll
  addSelection: addSelection
  removeSelection: removeSelection


deselectAll = (element) ->
  return unless isSelectable(element)
  deselectedIds = getTemplate(element).selection.removeAll()
  handleSelectionResult(element, {added: [], removed: deselectedIds})

selectAll = (element) ->
  return unless isSelectable(element)
  ids = getTemplate(element).collection.find().map (doc) -> doc._id
  result = getTemplate(element).selection.setIds(ids)
  handleSelectionResult(element, result)

toggleSelection = (element, ids) ->
  return unless isSelectable(element)
