<commit_before>import { Injectable } from '@angular/core'
import { BehaviorSubject, Observable } from 'rxjs'

import { NetworkService } from '../core/network/network.service'

import * as MuteStructs  from 'mute-structs'

@Injectable()
export class DocService {

  private doc: any
  private network: NetworkService
  private remoteTextOperationsStream: Observable<any[]>
  private docSubject: BehaviorSubject<MuteStructs.LogootSRopes>
  private initEditorSubject: BehaviorSubject<string>

  constructor(network: NetworkService) {
    this.doc = new MuteStructs.LogootSRopes(0)
    log.debug('MUTE STRUCTS: ', this.doc)
    this.network = network

    this.initEditorSubject = new BehaviorSubject<string>('')

    this.network.onJoin.subscribe( (id: number) => {
      this.doc = new MuteStructs.LogootSRopes(id)
      // Emit initial value
      this.docSubject = new BehaviorSubject<MuteStructs.LogootSRopes>(this.doc)
      this.network.setDocStream(this.docSubject.asObservable())
    })

    this.network.onJoinDoc
	// Check to filter null values
    .filter( (doc: MuteStructs.LogootSRopes) => doc instanceof MuteStructs.LogootSRopes )
    .subscribe( (doc: MuteStructs.LogootSRopes) => {
      this.doc = doc
      this.initEditorSubject.next(doc.str)
    })

    this.remoteTextOperationsStream = this.network.onRemoteOperations.map( (logootSOperation: any) => {
      return this.handleRemoteOperation(logootSOperation)
    })
  }

  setLocalTextOperationsStream(textOperationsStream: Observable<any[]>) {
    textOperationsStream.subscribe( (array: any[][]) => {
      this.handleTextOperations(array)
    })
  }

  getInitEditorStream(): Observable<string> {
    return this.initEditorSubject.asObservable()
  }

  getRemoteTextOperationsStream(): Observable<any[]> {
    return this.remoteTextOperationsStream
  }

  handleTextOperations(array: any[][]) {
    array.forEach( (textOperations: any[]) => {
      textOperations.forEach( (textOperation: any) => {
        const logootSOperation: any = textOperation.applyTo(this.doc)
        if (logootSOperation instanceof MuteStructs.LogootSAdd) {
          this.network.sendLogootSAdd(logootSOperation)
        } else {<commit_msg>fix(doc): Update docStream value when joining doc<commit_after>import { Injectable } from '@angular/core'
import { BehaviorSubject, Observable } from 'rxjs'

import { NetworkService } from '../core/network/network.service'

import * as MuteStructs  from 'mute-structs'

@Injectable()
export class DocService {

  private doc: any
  private network: NetworkService
  private remoteTextOperationsStream: Observable<any[]>
  private docSubject: BehaviorSubject<MuteStructs.LogootSRopes>
  private initEditorSubject: BehaviorSubject<string>

  constructor(network: NetworkService) {
    this.doc = new MuteStructs.LogootSRopes(0)
    log.debug('MUTE STRUCTS: ', this.doc)
    this.network = network

    this.initEditorSubject = new BehaviorSubject<string>('')

    this.network.onJoin.subscribe( (id: number) => {
      this.doc = new MuteStructs.LogootSRopes(id)
      // Emit initial value
      this.docSubject = new BehaviorSubject<MuteStructs.LogootSRopes>(this.doc)
      this.network.setDocStream(this.docSubject.asObservable())
    })

    this.network.onJoinDoc
	// Check to filter null values
    .filter( (doc: MuteStructs.LogootSRopes) => doc instanceof MuteStructs.LogootSRopes )
    .subscribe( (doc: MuteStructs.LogootSRopes) => {
      this.doc = doc
      this.docSubject.next(this.doc)
      this.initEditorSubject.next(doc.str)
    })

    this.remoteTextOperationsStream = this.network.onRemoteOperations.map( (logootSOperation: any) => {
      return this.handleRemoteOperation(logootSOperation)
    })
  }

  setLocalTextOperationsStream(textOperationsStream: Observable<any[]>) {
    textOperationsStream.subscribe( (array: any[][]) => {
      this.handleTextOperations(array)
    })
  }

  getInitEditorStream(): Observable<string> {
    return this.initEditorSubject.asObservable()
  }

  getRemoteTextOperationsStream(): Observable<any[]> {
    return this.remoteTextOperationsStream
  }

  handleTextOperations(array: any[][]) {
    array.forEach( (textOperations: any[]) => {
      textOperations.forEach( (textOperation: any) => {
        const logootSOperation: any = textOperation.applyTo(this.doc)
        if (logootSOperation instanceof MuteStructs.LogootSAdd) {
          this.network.sendLogootSAdd(logootSOperation)
        } else {
{'fraction_non_alphanumeric': 0.11263181512227956, 'fraction_numerical': 0.0004487323311644604, 'mean_word_length': 4.141868512110727, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, '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': '2198074', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1349, 'n_words': 245}