mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
js,vfmt: fix formatting for JS types; add fetch API (#12608)
This commit is contained in:
@ -271,6 +271,11 @@ pub interface JS.Document {
|
||||
queryCommandState(commandId JS.String) JS.String
|
||||
write(text ...JS.Any)
|
||||
writeln(text ...JS.Any)
|
||||
exitFullscreen() JS.Promise
|
||||
exitPictureInPicture() JS.Promise
|
||||
exitPointerLock()
|
||||
requestPointerLock()
|
||||
requestFullScreen() JS.Promise
|
||||
mut:
|
||||
bgColor JS.String
|
||||
fgColor JS.String
|
||||
|
33
vlib/js/js.js.v
Normal file
33
vlib/js/js.js.v
Normal file
@ -0,0 +1,33 @@
|
||||
module js
|
||||
|
||||
import js.promise
|
||||
|
||||
pub fn JS.fetch(input JS.String, init JS.Object) JS.Promise
|
||||
|
||||
pub interface JS.Body {
|
||||
body JS.Uint8Array
|
||||
bodyUse JS.Boolean
|
||||
blob() JS.Promise
|
||||
json() JS.Promise
|
||||
text() JS.Promise
|
||||
}
|
||||
|
||||
pub interface JS.Response {
|
||||
JS.Body
|
||||
ok JS.Boolean
|
||||
redirected JS.Boolean
|
||||
status JS.Number
|
||||
statusText JS.String
|
||||
url JS.String
|
||||
clone() JS.Response
|
||||
}
|
||||
|
||||
pub fn fetch(input string, init map[string]JS.Any) promise.Promise<JS.Response, JS.String> {
|
||||
p_init := JS.Any(voidptr(0))
|
||||
p := promise.Promise<JS.Response,String>{p_init}
|
||||
|
||||
#let obj = {}; for (let [key,val] of init.map) { obj[key] = val; }
|
||||
#p.promise = fetch(input.str,obj);
|
||||
|
||||
return p
|
||||
}
|
@ -68,12 +68,14 @@ pub fn JS.Promise.all(JS.Array) JS.Promise
|
||||
pub fn JS.Promise.allSettled(JS.Array) JS.Promise
|
||||
|
||||
/*
|
||||
pub type JsAny = JS.Any
|
||||
|
||||
// all takes an iterable of promises as an input, and returns a single Promise that resolves to an array of
|
||||
// the results of the input promises
|
||||
pub fn all(array []JS.Promise) Promise<JS.Array, JS.Any> {
|
||||
pub fn all(array []JS.Promise) Promise<JS.Array, js.promise.JsAny> {
|
||||
mut promise := JS.Promise(JS.Any(voidptr(0)))
|
||||
#promise = Promise.all(array.arr.arr);
|
||||
|
||||
return Promise<Array,Any>{promise}
|
||||
return Promise<JS.Array,JsAny>{promise}
|
||||
}
|
||||
*/
|
||||
|
@ -1,7 +1,9 @@
|
||||
module promise
|
||||
|
||||
fn test_promise() {
|
||||
// TODO: For some reason compiler errors: "error: unknown function: js.promise.new", fix this
|
||||
/*
|
||||
p := promise.new<int, f64>(fn (resolve_ fn (x int), reject_ fn (x f64)) {
|
||||
p := new<int, f64>(fn (resolve_ fn (x int), reject_ fn (x f64)) {
|
||||
println('Promise code')
|
||||
assert true
|
||||
resolve_(42)
|
||||
|
Reference in New Issue
Block a user