all files / model/ Range.js

28.57% Statements 8/28
17.65% Branches 3/17
20% Functions 1/5
30.77% Lines 8/26
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                                                                           
import { isPlainObject } from '../util'
 
class Range {
 
  constructor(start, end, reverse, containerId, surfaceId) {
    // HACK: to allow this class be inherited but without calling this ctor
    Iif (arguments[0] === 'SKIP') return
    Iif (arguments.length === 1 && isPlainObject(arguments[0])) {
      let data = arguments[0]
      this.start = data.start
      this.end = data.end
      this.reverse = Boolean(data.reverse)
      this.containerId = data.containerId
      this.surfaceId = data.surfaceId
    } else {
      this.start = start
      this.end = end
      this.reverse = Boolean(reverse)
      this.containerId = containerId
      this.surfaceId = surfaceId
    }
  }
 
  isCollapsed() {
    return this.start.equals(this.end)
  }
 
  equals(other) {
    if (this === other) return true
    else {
      return (
        this.containerId === other.containerId &&
        this.start.equals(other.start) &&
        this.end.equals(other.end)
      )
    }
  }
 
  isReverse() {
    return this.reverse
  }
 
  toString() {
    let str = [this.start.toString(), '->', this.end.toString()]
    if (this.isReverse()) {
      str.push('[reverse]')
    }
    if (this.containerId) {
      str.push('[container='+this.containerId+']')
    }
    if (this.surfaceId) {
      str.push('[surface='+this.surfaceId+']')
    }
    return str.join('')
  }
 
}
 
Range.prototype._isRange = true
 
export default Range