-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #167: Add Fetch API + Streams API #177
Conversation
note: I am quite sure there will be improvements needed to the formatting. But before going through all that, I thought I'd first check if this is of interest. Btw. is there a script to get the formatting just right for this repo? |
* @tparam A | ||
*/ | ||
@js.native | ||
trait JSIterable[A] extends js.Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure actually where this should go. But it has proven useful in my code to be able to iterate through the headers.
Not sure what the travis failures are related to. |
|
yes but when I add > compile
[info] Compiling 6 Scala sources to /Volumes/Dev/Programming/ScalaJS/scala-js-dom/target/scala-2.11/classes...
[error] /Volumes/Dev/Programming/ScalaJS/scala-js-dom/src/main/scala/org/scalajs/dom/experimental/package.scala:13: expected start of definition
[error] package object experimental extends js.GlobalScope {
[error] ^
[error] one error found what I don't understand is that my own code seems to compile. |
Yep, native package objects are sort of deprecated (scala-js/scala-js#1892). This build fails because we have |
What do you recommend I do instead? It looks like the documentation on facade-types needs to be changed. It allows |
Yes, we should change it. Use a named object, like |
If you absolutely want the |
Ok, it compiles now. I did not add fetch to the package object because I am not sure how useful that is and how much thought I had put into that. |
/** | ||
* The locked getter returns whether or not the readable stream is locked to a reader. | ||
* throws scala.scalajs.js.TypeError if the stream is not readable | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would not publishLocal
with @throws
I tried to get as close to the preferred formatting of this project in the last commit. I also took out some classes related to streaming to a separate file. I worked on this before my previous commits, so the code may not be as good as my last one. But it is quite a lot of code. |
I don't have the bandwidth to process this these days. Could someone else review this? @mseddon? @nicolasstucki? |
trait JSIterator[+A] extends js.Object { | ||
def next(): JSIterator.Entry[A] = js.native | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this one is for @sjrd . I added this here as there is none available yet in the standard library. Is that ok?
See scala-js/scala-js#1141
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to submit this as a PR to scala-js/scala-js.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll do that too. Is there a package in which it should be placed there?
* | ||
* bblfish: not clear from the definition if this is a number of traits that | ||
* may be implemented by the Response or not | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear what you mean by this- certainly body is a trait that is implemented by Response with this signature.
* method is intentionally generic; it does not require that its this | ||
* value be a ReadableStream object. | ||
*/ | ||
def tee(): js.Array[ReadableStream[T]] = js.native |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc mentions a "given writable" stream", but the signature doesn't. That's suspicious.
I fixed a few of the points with |
What makes you think that? |
trait Entry[+A] extends js.Object { | ||
def done: Boolean = js.native | ||
def value: A = js.native | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value
and done
are two js.native functions, so Entry
can't be @ScalaJSDefined
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps not. I suppose it's such a basic class...
Is that better? |
|
||
def integrity: js.UndefOr[String] | ||
|
||
def window: js.UndefOr[Null] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
js.UndefOr[Null]
looks suspicious ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but it's actually what they seem to say in the docs. "can only be null" .
That's apparently to allow you to use it like ServiceWorkers from a window.
The idea is you can say you don't want to have a window. Don't really understand it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol. OK, then.
No more comments left in the code tab. Ready to go? |
* branches. (Let us know if you think we should add an option to tee that | ||
* creates structured clones of the chunks for each branch.) | ||
*/ | ||
def tee(): js.Array[ReadableStream[T]] = js.native |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see this was blocking the covariant thing.
Would js.Array[_ <: ReadableStream[T]]
allow you to make T
covariant?
Ideally this should even be a js.Tuple2[ReadableStream[T], ReadableStream[T]]
, which would also solve the covariant issue.
done. |
Good! Last step: could you squash all the commits, please? |
commits squashed. I learned a lot with the PR. :-) |
LGTM, thanks! |
Fix #167: Add Fetch API + Streams API
I have been using the Fetch API for my rww-scala-js akka branch. The code that I have tested and used works. So I thought I'd push this over before someone goes through the same work again.
Probably still a lot to be improved.
This would close #167