all files / model/ CustomSelection.js

15.79% Statements 3/19
0% Branches 0/7
0% Functions 0/9
15.79% Lines 3/19
1 statement Ignored     
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 63 64 65 66 67 68 69 70 71 72                                                                                                                                         
import { cloneDeep, isEqual } from '../util'
import Selection from './Selection'
 
class CustomSelection extends Selection {
 
  constructor(customType, data, surfaceId) {
    super()
 
    if (arguments.length === 1) {
      let _data = arguments[0]
      customType = _data.customType
      data = _data.data
      surfaceId = _data.surfaceId
    }
 
    this.customType = customType;
    this.data = data || {};
    this.surfaceId = surfaceId;
  }
 
  isCustomSelection() {
    return true;
  }
 
  getType() {
    return 'custom';
  }
 
  getCustomType() {
    return this.customType;
  }
 
  toJSON() {
    return {
      type: 'custom',
      customType: this.customType,
      data: cloneDeep(this.data),
      surfaceId: this.surfaceId
    };
  }
 
  toString() {
    /* istanbul ignore next */
    return [
      'CustomSelection(',
      this.customType,', ',
      JSON.stringify(this.data),
      ")"
    ].join('');
  }
 
  equals(other) {
    return (
      Selection.prototype.equals.call(this, other) &&
      other.isCustomSelection() &&
      isEqual(this.data, other.data)
    );
  }
 
  _clone() {
    return new CustomSelection(this)
  }
}
 
CustomSelection.prototype._isCustomSelection = true
 
CustomSelection.fromJSON = function(json) {
  return new CustomSelection(json);
}
 
export default CustomSelection