all files / model/ ContainerAnnotationIndex.js

100% Statements 11/11
100% Branches 2/2
100% Functions 7/7
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43            725× 725×       5830×       725× 725×       521× 521×   521×       29×                          
import { isString, filter, map, TreeIndex } from '../util'
import DocumentIndex from './DocumentIndex'
 
class ContainerAnnotationIndex extends DocumentIndex {
 
  constructor() {
    super()
    this.byId = new TreeIndex()
  }
 
  select(node) {
    return Boolean(node._isContainerAnnotation)
  }
 
  reset(data) {
    this.byId.clear()
    this._initialize(data)
  }
 
  get(containerId, type) {
    var annotations = map(this.byId.get(containerId))
    if (isString(type)) {
      annotations = filter(annotations, DocumentIndex.filterByType)
    }
    return annotations
  }
 
  create(anno) {
    this.byId.set([anno.containerId, anno.id], anno)
  }
 
  delete(anno) {
    this.byId.delete([anno.containerId, anno.id])
  }
 
  update(node, path, newValue, oldValue) { // eslint-disable-line
    // TODO should we support moving a container anno from one container to another?
  }
 
}
 
export default ContainerAnnotationIndex