<commit_before>package rww.ui

import japgolly.scalajs.react.extra.OnUnmount
import japgolly.scalajs.react.{ReactElement, BackendScope, ReactComponentB}
import org.w3.banana.PointedGraph
import rww.ontology.Person
import rww.rdf.Named
import rww.store._
import rww.ui.foaf.{Profile, WProps}
import rww.ui.rdf.NPGPath
import rww.ui.util.RxStateObserver
import japgolly.scalajs.react.vdom.prefix_<^._

import scala.util.{Failure, Success}

/**
 * Pointed Named Graph Window
 */
object PNGWindow {
  import rww._


  class Backend(t: BackendScope[WProps[Rdf#URI], Option[RequestState]])
    extends RxStateObserver[RequestState](t)  {
    def mounting(): Unit = observe(Some(t.props.webAgent.fetch(t.props.about)))
  }


  val Window = ReactComponentB[WProps[Rdf#URI]]("Window")
    //todo: would it be better if initial state this was settable by props for testing?
    .initialState[Option[RequestState]](None)
    .backend(new Backend(_))
    .render((P, S, B) => {
      val r: Option[ReactElement] = S map {
        case Ok(_, url, _, _, parsed) => {
          println(s"url=<$url> about=${P.about}")
          parsed match {
            case scala.util.Success(graph) => {
              //here of course one could choose the type of component, depending on the npg
              Profile(
                Person(NPGPath(Named[Rdf, PointedGraph[Rdf]](url, PointedGraph[Rdf](P.about, graph)))),
                P.webAgent
              )
            }
            case scala.util.Failure(e) => <.div()("error: "+e)
          }
        }
        //Downloading(_) | Redirected(_) | HttpError(_, _, _) |
        case  _ => Loading(P.about)
      }
      r.getOrElse(<.div("huh?"))
    })
    .componentWillMount(_.backend.mounting)
    .configure(OnUnmount.install)
    .build

  def apply(pointer: Rdf#URI, ws: WebAgent) =
    Window(WProps(pointer,ws))
}<commit_msg>change Vars when dynamic components change props<commit_after>package rww.ui

import japgolly.scalajs.react.extra.OnUnmount
import japgolly.scalajs.react.{ReactElement, BackendScope, ReactComponentB}
import org.w3.banana.PointedGraph
import rww.ontology.Person
import rww.rdf.Named
import rww.store._
import rww.ui.foaf.{Profile, WProps}
import rww.ui.rdf.NPGPath
import rww.ui.util.RxStateObserver
import japgolly.scalajs.react.vdom.prefix_<^._

import scala.util.{Failure, Success}

/**
 * Pointed Named Graph Window
 */
object PNGWindow {
  import rww._


  class Backend(t: BackendScope[WProps[Rdf#URI], Option[RequestState]])
    extends RxStateObserver[RequestState](t)  {
    def mounting(props: WProps[Rdf#URI]): Unit = observe(Some(props.webAgent.fetch(props.about)))
  }


  val Window = ReactComponentB[WProps[Rdf#URI]]("Window")
    //todo: would it be better if initial state this was settable by props for testing?
    .initialState[Option[RequestState]](None)
    .backend(new Backend(_))
    .render((P, S, B) => {
      val r: Option[ReactElement] = S map {
        case Ok(_, url, _, _, parsed) => {
          println(s"url=<$url> about=${P.about}")
          parsed match {
            case scala.util.Success(graph) => {
              //here of course one could choose the type of component, depending on the npg
              Profile(
                Person(NPGPath(Named[Rdf, PointedGraph[Rdf]](url, PointedGraph[Rdf](P.about, graph)))),
                P.webAgent
              )
            }
            case scala.util.Failure(e) => <.div()("error: "+e)
          }
        }
        //Downloading(_) | Redirected(_) | HttpError(_, _, _) |
        case  _ => Loading(P.about)
      }
      r.getOrElse(<.div("huh?"))
    })
    .componentWillReceiveProps{ (CS,P) => CS.backend.runUnmount(); CS.backend.mounting(P) }
    .componentWillMount(cs => cs.backend.mounting(cs.props))
    .configure(OnUnmount.install)
    .build

  def apply(pointer: Rdf#URI, ws: WebAgent) =
    Window(WProps(pointer,ws))
}
{'fraction_non_alphanumeric': 0.13771839671120248, 'fraction_numerical': 0.0005138746145940391, 'mean_word_length': 2.9482758620689653, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1351359', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1305, 'n_words': 260}