<commit_before>class Touch3DAdapter extends BaseAdapter{

  constructor(element){
    super(element);
  }

  support(){
    this.add('touchstart', this._dispatch.bind(this));
  }

  _dispatch(event){
    if(event.touches[0].force !== undefined){
      // can't check full support from this info
      Support.didSucceed('3d');
      this.remove('touchstart', this._dispatch.bind(this));
    } else {
      Support.didFail();
      runClosure(this.block, 'unsupported', this.el);
    }
  }

  start(){
    // call 'start' when the touch goes down
    this.add('touchstart', () => {
      if(Support.forPressure){
        runClosure(this.block, 'start', this.el);
      }
    });
  }

  change(){
    this.add('touchstart', (event) =>{
      if(Support.forPressure){
        this._setDown();
        // set touch event
        this.touch = this._selectTouch(event);
        if(this.touch){
          this._fetchForce(event);
        }
      }
    });
  }

  end(){
    // call 'end' when the touch goes up
    this.add('touchend', () => {
      if(Support.forPressure){
        this._setUp();
        runClosure(this.block, 'end', this.el);
      }
    });
  }

  _fetchForce(event){
    if(this.down) {
      this.touch = this._selectTouch(event);
      setTimeout(this._fetchForce.bind(this), 10, event);
      runClosure(this.block, 'change', this.el, this.touch.force, event);
    }
  }

  // link up the touch point to the correct element, this is to support multitouch
  _selectTouch(event){
    if(event.touches.length === 1){
      return event.touches[0];
    }
    for(var i = 0; i < event.touches.length; i++){
      if(event.touches[i].target === this.el){
        console.log(event.touches[i].force);
        return event.touches[i];
      }
    }
  }

}
<commit_msg>Adding deep press support to 3DTouch<commit_after>class Touch3DAdapter extends BaseAdapter{

  constructor(element){
    super(element);
    this._startDeepPressSetEnabled = false;
    this._endDeepPressSetEnabled = false;
    this._inDeepPress = false;
  }

  support(){
    this.add('touchstart', this._dispatch.bind(this));
  }

  _dispatch(event){
    if(event.touches[0].force !== undefined){
      // can't check full support from this info
      Support.didSucceed('3d');
      this.remove('touchstart', this._dispatch.bind(this));
    } else {
      Support.didFail();
      runClosure(this.block, 'unsupported', this.el);
    }
  }

  start(){
    // call 'start' when the touch goes down
    this.add('touchstart', () => {
      if(Support.forPressure){
        runClosure(this.block, 'start', this.el);
      }
    });
  }

  change(){
    this.add('touchstart', (event) =>{
      if(Support.forPressure){
        this._setDown();
        // set touch event
        this.touch = this._selectTouch(event);
        if(this.touch){
          this._fetchForce(event);
        }
      }
    });
  }

  end(){
    // call 'end' when the touch goes up
    this.add('touchend', () => {
      if(Support.forPressure){
        this._setUp();
        runClosure(this.block, 'end', this.el);
      }
    });
  }

  startDeepPress(){
    this._startDeepPressSetEnabled = true;
    // the logic for this runs in the '_callStartDeepPress' method
  }

  endDeepPress(){
    this._endDeepPressSetEnabled = true;
    // the logic for this runs in the '_callEndDeepPress' method
  }

  _callStartDeepPress(){
    if(this._startDeepPressSetEnabled === true){
      if(this._inDeepPress === false){
        runClosure(this.block, 'startDeepPress', this.el);
      } else {
        this._inDeepPress = true;
      }
    }
  }

  _callEndDeepPress(){
    if(this._endDeepPressSetEnabled === true){
      if(this._inDeepPress === true){
        runClosure(this.block, 'endDeepPress', this.el);
      } else {
        this._inDeepPress = false;
      }
    }
  }

  _fetchForce(event){
    if(this.down) {
      this.touch = this._selectTouch(event);
      setTimeout(this._fetchForce.bind(this), 10, event);
      runClosure(this.block, 'change', this.el, this.touch.force, event);
    }
  }

  // link up the touch point to the correct element, this is to support multitouch
  _selectTouch(event){
    if(event.touches.length === 1){
      return event.touches[0];
    }
    for(var i = 0; i < event.touches.length; i++){
      if(event.touches[i].target === this.el){
        // console.log(event.touches[i].force);
        event.touches[i] >= 0.5 ? this._callStartDeepPress() : this._callEndDeepPress();
        return event.touches[i];
      }
    }
  }

}

{'fraction_non_alphanumeric': 0.1524524966858153, 'fraction_numerical': 0.0041979673000441895, 'mean_word_length': 2.487673343605547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3846206', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1480, 'n_words': 277}