Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Andrew Gaydenko
    @gaydenko
    @LukaJCB Are there plans regarding LukaJCB/rxscala-js#19 ? Or - still travelling?
    Luka Jacobowitz
    @LukaJCB
    Hey @gaydenko yeah I'm sorry for the delay, I'm at my family's over easter, but I've been able to spend some time looking at the problem and I'm still not one hundred percent sure how to handle it, because the response depends on the content type
    Andrew Gaydenko
    @gaydenko
    @LukaJCB I guess the aim of OutWatch (well, rxscala-js :smile: ) AJAX wrapper must be just a transforming of upstream code to Observable, that is without dealing with content (or any other smart defaulting) at all. User code must be the only dealing with content.
    Luka Jacobowitz
    @LukaJCB
    Well we could just have the response be js.Dynamic, but that doesn't seem nice
    Andrew Gaydenko
    @gaydenko
    May be to use this one? http://www.scala-js.org/api/scalajs-dom/0.9.0/index.html#org.scalajs.dom.experimental.Body Or, may be, it would be more handy just to have separated dedicated "observabilation" of this or that HTTP client.
    Luka Jacobowitz
    @LukaJCB
    Those don't really work, because of the internal promises that might fail, no? That would mean the user would have to see for themselves which responseType they'd like to parse and convert the inner promise
    and that also leaves the question what you do with application/json besides parsing it to js.Dynamic
    Andrew Gaydenko
    @gaydenko
    I guess it would be sufficient at first to have an opportunity to get a response body as bytes and as UTF8 string. Yes, I guess, API's client wants to decide how to treat response herself - as image, JSON, html, text, XML or anything else. JSON format isn't special in any sense, to my taste.
    At my use cases I use circe for serde on both sides. But it is just a single use case among infinite ones :smile:
    Luka Jacobowitz
    @LukaJCB
    Yeah I use circe as well
    So i'd just like a string either way
    And it works fine for application/Jason
    Andrew Gaydenko
    @gaydenko
    Well, JSON is one of hundreds content types, agree? :smile:
    Luka Jacobowitz
    @LukaJCB
    Yes :D
    RxJS parses anything that's application/json into a js Object already
    Andrew Gaydenko
    @gaydenko
    And sometimes we want something else. Say, text/plain.
    Luka Jacobowitz
    @LukaJCB
    Yeah
    It should be available as responseText, but for some reason sometimes it's not
    And then we get a string of json, that's then parsed into json again
    And we end up with double quotes
    Andrew Gaydenko
    @gaydenko
    ...and sometimes we want octet streams
    Luka Jacobowitz
    @LukaJCB
    Yeah or multipart images...
    Andrew Gaydenko
    @gaydenko
    Exactly! :fire: So it explains my suggestion: starting form body representation as bytes array ans as UTF8 string will cover most of use cases (not all). Limiting to JSON only is too narrow to be acceptable, I guess.
    Luka Jacobowitz
    @LukaJCB
    I think I'm just going to have the json parsing only when the response type is json
    And then you can form a byte array of of the utf-8 string
    Andrew Gaydenko
    @gaydenko
    The issue clarify text/html was used. And, well, as for octet stream , it can not be encoded as UTF8 string. It must be passed as is.
    Luka Jacobowitz
    @LukaJCB
    So it should probably be an Option[Array[Byte]]?
    I'm not sure how to deal with that, maybe you'd want to create a PR?
    Andrew Gaydenko
    @gaydenko
    In fact I agree bytes isn't too common on the client side, and it would be sufficient to get a body as a string as is only. So, resuming, it would be great if response contains (probably also contains) body as text as is.
    That is HTTP client must not hide raw string body even it decides to decode JSON.
    Luka Jacobowitz
    @LukaJCB
    I'll also include the original XMLHttpRequest
    Andrew Gaydenko
    @gaydenko
    As the way to responseText? Yes, it would be handy.
    Luka Jacobowitz
    @LukaJCB
    The problem is that responseText isn't set 80% of the time
    Andrew Gaydenko
    @gaydenko
    Is it set at the moment an obsrervable notifies subscribers?
    Then it can be copied to Response field.
    Luka Jacobowitz
    @LukaJCB
    It is
    Luka Jacobowitz
    @LukaJCB
    i just pushed a couple of commits
    Andrew Gaydenko
    @gaydenko
    Aha, I see, if (response.responseType == "json") and + .xhr, great, thanks!
    Are you going to publish it?
    Aha, and a body as dynamic...
    Luka Jacobowitz
    @LukaJCB
    Yes will do (:
    Andrew Gaydenko
    @gaydenko

    @LukaJCB To better understand Observable used in OutWatch I'm reading RxJs scala documentation, and it is interesting reading :smile: As far as rxscala-js is facade, I can hope that documentation is, in fact, rxscala-js' documentation also. Is it true?
    Or - are you going to make OutWatch Monix-based? :smile: In fact, rxscala-js as OutWatch base move me to some doubt (as well as not-scala vdom implementation).

    Probably I must dig in Monix documentation already...

    Luka Jacobowitz
    @LukaJCB
    I'm not sure I completly understand your question, you're asking if RxScala documentation also applies to rxscala-js? (:
    I'd like to make it Monix based, or at least add as an option, if someone could figure out to add it in a backwards compatible way, I'd do it in a heartbeat!
    Andrew Gaydenko
    @gaydenko
    Sorry, typo ("RxJ scala " must be just "RxJs"). I'm asking if RxJs documentations also applies to rxscala-js.
    Luka Jacobowitz
    @LukaJCB
    it does!
    Rx is mostly the same across platforms
    which is one of the reasons I chose it
    Andrew Gaydenko
    @gaydenko
    @LukaJCB How to create Observable from window event (say, hashchange/popstate)? fromEvent wants Element rather Window.
    Andrew Gaydenko
    @gaydenko
    It seems this one does work:
      val hashes = Observable.create { observer: Observer[String] =>
        dom.window.onhashchange = { e =>
          val url = e.asInstanceOf[HashChangeEvent].newURL
          val idx = url.indexOf("#")
          val hash = if (idx >= 0) url.substring(idx + 1) else ""
          observer.next(hash)
        }
      }
    Luka Jacobowitz
    @LukaJCB
    Yup, that's the way, I'd go as well!