<commit_before>package net.liftmodules.ng

import net.liftweb._
import http._
import common._
import util._
import http.js._
import JE._
import JsCmds._
import json.Serialization._
import json.DefaultFormats
import scala.xml.NodeSeq
import net.liftweb.json.JsonAST.JString

private [ng] trait LiftNgJsHelpers extends Loggable {
  protected val id:String = Angular.rand

  /** Interval between tries to unload our early-arrival event queue */
  private val interval = Props.getInt("net.liftmodules.ng.AngularActor.retryInterval", 100)

  /** Variable assignment for \$scope */
  private val varScope = JsCrVar("e", AnonFunc("id",
    JsRaw(
      "if(typeof angular==='undefined'||typeof angular.element==='undefined')return void 0;else " +
        "return angular.element(document.querySelector('#'+id))"
    )
  )) & JsCrVar("s", AnonFunc("id",
    JsRaw(
      "if(typeof e(id)==='undefined')return void 0;else " +
        "return e(id).scope()"
    )
  ))
  /** Variable assignment for \$rootScope */
  private val varRoot  = JsCrVar("r", AnonFunc("id", JsReturn(JsRaw("(typeof s(id)==='undefined')?void 0:s(id).$root"))))

  /** Sends any of our commands with all of the early-arrival retry mechanism packaged up */
  protected def buildCmd(root:Boolean, f:JsCmd):JsCmd = {
    val scopeFn = if(root) "r('"+id+"')" else "s('"+id+"')"
    val vars = varScope & (if(root) varRoot else Noop)
    val ready = JsCrVar("t", AnonFunc(JsReturn(JsRaw("typeof " + scopeFn + "!=='undefined'"))))
    val fn = JsCrVar("f", AnonFunc(Call(scopeFn+".$apply", AnonFunc(f))))
    val dequeue = "var d=function(){" +
      "if(net_liftmodules_ng_q[0].t()){"+
      "for(i=0;i<net_liftmodules_ng_q.length;i++){" +
      "net_liftmodules_ng_q[i].f();"+
      "}"+
      "net_liftmodules_ng_q=void 0;"+
      "}else{"+
      "setTimeout(function(){d();},"+interval+");"+
      "}"+
      "};"
    val enqueue = "if(typeof net_liftmodules_ng_q==='undefined'){net_liftmodules_ng_q=[];setTimeout(function(){d();},"+interval+");}" +
      "net_liftmodules_ng_q.push({t:t,f:f});"
    val cmds = vars & ready & fn & JsRaw(dequeue+"if(typeof net_liftmodules_ng_q==='undefined'&&t()){f();}else{"+enqueue+"}")
    logger.trace(cmds)
    cmds
  }

  private implicit val formats = DefaultFormats + new LAFutureSerializer
  protected def stringify(obj:AnyRef):String = obj match {
    case s:String => StringHelpers.encJs(s)
    case _ => write(obj)
  }
}

/** A comet actor for Angular action */
trait AngularActor extends CometActor with LiftNgJsHelpers {
<commit_msg>Wrapping up our junk that's polluting global name space<commit_after>package net.liftmodules.ng

import net.liftweb._
import http._
import common._
import util._
import http.js._
import JE._
import JsCmds._
import json.Serialization._
import json.DefaultFormats
import scala.xml.NodeSeq
import net.liftweb.json.JsonAST.JString

private [ng] trait LiftNgJsHelpers extends Loggable {
  protected val id:String = Angular.rand

  /** Interval between tries to unload our early-arrival event queue */
  private val interval = Props.getInt("net.liftmodules.ng.AngularActor.retryInterval", 100)

  /** Variable assignment for \$scope */
  private val varScope = JsCrVar("e", AnonFunc("id",
    JsRaw(
      "if(typeof angular==='undefined'||typeof angular.element==='undefined')return void 0;else " +
        "return angular.element(document.querySelector('#'+id))"
    )
  )) & JsCrVar("s", AnonFunc("id",
    JsRaw(
      "if(typeof e(id)==='undefined')return void 0;else " +
        "return e(id).scope()"
    )
  ))
  /** Variable assignment for \$rootScope */
  private val varRoot  = JsCrVar("r", AnonFunc("id", JsReturn(JsRaw("(typeof s(id)==='undefined')?void 0:s(id).$root"))))

  /** Sends any of our commands with all of the early-arrival retry mechanism packaged up */
  protected def buildCmd(root:Boolean, f:JsCmd):JsCmd = {
    val scopeFn = if(root) "r('"+id+"')" else "s('"+id+"')"
    val vars = varScope & (if(root) varRoot else Noop)
    val ready = JsCrVar("t", AnonFunc(JsReturn(JsRaw("typeof " + scopeFn + "!=='undefined'"))))
    val fn = JsCrVar("f", AnonFunc(Call(scopeFn+".$apply", AnonFunc(f))))
    val dequeue = "var d=function(){" +
      "if(net_liftmodules_ng_q[0].t()){"+
      "for(i=0;i<net_liftmodules_ng_q.length;i++){" +
      "net_liftmodules_ng_q[i].f();"+
      "}"+
      "net_liftmodules_ng_q=void 0;"+
      "}else{"+
      "setTimeout(function(){d();},"+interval+");"+
      "}"+
      "};"
    val enqueue = "if(typeof net_liftmodules_ng_q==='undefined'){net_liftmodules_ng_q=[];setTimeout(function(){d();},"+interval+");}" +
      "net_liftmodules_ng_q.push({t:t,f:f});"
    val cmds = vars & ready & fn & JsRaw(dequeue+"if(typeof net_liftmodules_ng_q==='undefined'&&t()){f();}else{"+enqueue+"}")
    logger.trace(cmds)
    JsRaw("(function(){"+cmds.toJsCmd+"}).call(this)")
  }

  private implicit val formats = DefaultFormats + new LAFutureSerializer
  protected def stringify(obj:AnyRef):String = obj match {
    case s:String => StringHelpers.encJs(s)
    case _ => write(obj)
  }
}

/** A comet actor for Angular action */
trait AngularActor extends CometActor with LiftNgJsHelpers {

{'fraction_non_alphanumeric': 0.17304717710750192, 'fraction_numerical': 0.0034802784222737818, 'mean_word_length': 4.360621761658031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1785995', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1782, 'n_words': 372}