all files / model/ CoordinateAdapter.js

0% Statements 0/12
0% Branches 0/3
0% Functions 0/8
0% Lines 0/12
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                                                                                                             
import { isArrayEqual } from '../util'
import Coordinate from './Coordinate'
 
/*
  Adapter for Coordinate oriented implementations.
  E.g. Coordinate transforms can be applied to update selections
  using OT.
 
  @internal
*/
class CoordinateAdapter extends Coordinate {
 
  constructor(owner, pathProperty, offsetProperty) {
    super('SKIP')
 
    this._owner = owner;
    this._pathProp = pathProperty;
    this._offsetProp = offsetProperty;
    Object.freeze(this);
  }
 
  equals(other) {
    return (other === this ||
      (isArrayEqual(other.path, this.path) && other.offset === this.offset) )
  }
 
  get path() {
    return this._owner[this._pathProp];
  }
 
  set path(path) {
    this._owner[this._pathProp] = path;
  }
 
  get offset() {
    return this._owner[this._offsetProp];
  }
 
  set offset(offset) {
    this._owner[this._offsetProp] = offset;
  }
 
  toJSON() {
    return {
      path: this.path,
      offset: this.offset
    }
  }
 
  toString() {
    return "(" + this.path.join('.') + ", " + this.offset + ")"
  }
}
 
export default CoordinateAdapter