Skip to content

Commit e4d2562

Browse files
committed
Add first pass of qry-web crate for JS consumption
1 parent 092844d commit e4d2562

12 files changed

+6133
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
**/*.rs.bk
3+
node_modules/

Cargo.lock

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[workspace]
22
members = [
33
"qry",
4+
"qry-web",
45
"cli",
56
]

qry-web/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "qry-web"
3+
version = "0.1.0"
4+
authors = ["Ruan Pearce-Authers <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
crate-type = ["cdylib", "rlib"]
9+
10+
[dependencies]
11+
qry = { path = "../qry" }
12+
wasm-bindgen = "0.2.63"

qry-web/src/lib.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use qry::lang::parse;
2+
use qry::runtime::{eval_multi, EvalContext};
3+
use wasm_bindgen::prelude::*;
4+
5+
#[wasm_bindgen]
6+
extern "C" {
7+
fn alert(s: &str);
8+
}
9+
10+
#[wasm_bindgen]
11+
pub fn run(src: &str) {
12+
let ctx = EvalContext::new_with_stdlib();
13+
let syntax = parse(src, "<web>").unwrap();
14+
let result = eval_multi(&ctx, &syntax).unwrap();
15+
alert(&format!("got value: {:?}", result));
16+
}

qry-web/www/bootstrap.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// A dependency graph that contains any wasm must all be imported
2+
// asynchronously. This `bootstrap.js` file does the single async import, so
3+
// that no one else needs to worry about it again.
4+
import("./index.js")
5+
.catch(e => console.error("Error importing `index.js`:", e));

qry-web/www/index.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Hello qry!</title>
7+
</head>
8+
9+
<body>
10+
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
11+
<script src="./bootstrap.js"></script>
12+
</body>
13+
14+
</html>

qry-web/www/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as qry from 'qry-web';
2+
qry.run('data::intvec(1, 2, 3) |> data::sum()')

0 commit comments

Comments
 (0)