Skip to content

Commit 4bd5a2d

Browse files
committed
Merge branch 'twharmon-goui'
2 parents dafec5c + 5528399 commit 4bd5a2d

File tree

14 files changed

+385
-0
lines changed

14 files changed

+385
-0
lines changed

frameworks/keyed/goui/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# GoUI
2+
3+
The production build assets are tracked and no build is required to run the benchmarks.
4+
5+
If you want to build from source, install `go` and `gouix`:
6+
7+
```
8+
go install github.com/twharmon/gouix@latest
9+
```
10+
11+
Install goui dependency:
12+
13+
```
14+
go get ./src
15+
```
16+
17+
Run the development server:
18+
```
19+
gouix serve
20+
```
21+
22+
Build for production:
23+
```
24+
gouix build
25+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!doctype html><html lang=en><meta name=viewport content="width=device-width,initial-scale=1"><title>GoUI</title>
2+
<link href=/css/currentStyle.css rel=stylesheet><div id=root></div><script>(()=>{if(typeof global!="undefined");else if(typeof window!="undefined")window.global=window;else if(typeof self!="undefined")self.global=self;else throw new Error("cannot export Go (neither global, window nor self is defined)");!global.require&&typeof require!="undefined"&&(global.require=require),!global.fs&&global.require&&(global.fs=require("fs"));const e=()=>{const e=new Error("not implemented");return e.code="ENOSYS",e};if(!global.fs){let t="";global.fs={constants:{O_WRONLY:-1,O_RDWR:-1,O_CREAT:-1,O_TRUNC:-1,O_APPEND:-1,O_EXCL:-1},writeSync(e,s){t+=n.decode(s);const o=t.lastIndexOf(`
3+
`);return o!=-1&&(console.log(t.substr(0,o)),t=t.substr(o+1)),s.length},write(t,n,s,o,i,a){if(s!==0||o!==n.length||i!==null){a(e());return}const r=this.writeSync(t,n);a(null,r)},chmod(t,n,s){s(e())},chown(t,n,s,o){o(e())},close(t,n){n(e())},fchmod(t,n,s){s(e())},fchown(t,n,s,o){o(e())},fstat(t,n){n(e())},fsync(e,t){t(null)},ftruncate(t,n,s){s(e())},lchown(t,n,s,o){o(e())},link(t,n,s){s(e())},lstat(t,n){n(e())},mkdir(t,n,s){s(e())},open(t,n,s,o){o(e())},read(t,n,s,o,i,a){a(e())},readdir(t,n){n(e())},readlink(t,n){n(e())},rename(t,n,s){s(e())},rmdir(t,n){n(e())},stat(t,n){n(e())},symlink(t,n,s){s(e())},truncate(t,n,s){s(e())},unlink(t,n){n(e())},utimes(t,n,s,o){o(e())}}}if(global.process||(global.process={getuid(){return-1},getgid(){return-1},geteuid(){return-1},getegid(){return-1},getgroups(){throw e()},pid:-1,ppid:-1,umask(){throw e()},cwd(){throw e()},chdir(){throw e()}}),!global.crypto){const e=require("crypto");global.crypto={getRandomValues(t){e.randomFillSync(t)}}}global.performance||(global.performance={now(){const[e,t]=process.hrtime();return e*1e3+t/1e6}}),global.TextEncoder||(global.TextEncoder=require("util").TextEncoder),global.TextDecoder||(global.TextDecoder=require("util").TextDecoder);const o=new TextEncoder("utf-8"),n=new TextDecoder("utf-8");let t=new DataView(new ArrayBuffer(8));var s=[];if(global.Go=class{constructor(){this._callbackTimeouts=new Map,this._nextCallbackTimeoutID=1;const e=()=>new DataView(this._inst.exports.memory.buffer),i=e=>{t.setBigInt64(0,e,!0);const n=t.getFloat64(0,!0);if(n===0)return void 0;if(!isNaN(n))return n;const s=e&4294967295n;return this._values[s]},u=t=>{let n=e().getBigUint64(t,!0);return i(n)},c=e=>{const s=2146959360n;if(typeof e=="number")return isNaN(e)?s<<32n:e===0?s<<32n|1n:(t.setFloat64(0,e,!0),t.getBigInt64(0,!0));switch(e){case void 0:return 0n;case null:return s<<32n|2n;case!0:return s<<32n|3n;case!1:return s<<32n|4n}let n=this._ids.get(e);n===void 0&&(n=this._idPool.pop(),n===void 0&&(n=BigInt(this._values.length)),this._values[n]=e,this._goRefCounts[n]=0,this._ids.set(e,n)),this._goRefCounts[n]++;let o=1n;switch(typeof e){case"string":o=2n;break;case"symbol":o=3n;break;case"function":o=4n;break}return n|(s|o)<<32n},a=(t,n)=>{let s=c(n);e().setBigUint64(t,s,!0)},l=(e,t)=>new Uint8Array(this._inst.exports.memory.buffer,e,t),d=(e,t)=>{const s=new Array(t);for(let n=0;n<t;n++)s[n]=u(e+n*8);return s},r=(e,t)=>n.decode(new DataView(this._inst.exports.memory.buffer,e,t)),h=Date.now()-performance.now();this.importObject={wasi_snapshot_preview1:{fd_write:function(t,o,i,a){let r=0;if(t==1)for(let t=0;t<i;t++){let a=o+t*8,l=e().getUint32(a+0,!0),c=e().getUint32(a+4,!0);r+=c;for(let t=0;t<c;t++){let o=e().getUint8(l+t);if(o==13);else if(o==10){let e=n.decode(new Uint8Array(s));s=[],console.log(e)}else s.push(o)}}else console.error("invalid file descriptor:",t);return e().setUint32(a,r,!0),0},fd_close:()=>0,fd_fdstat_get:()=>0,fd_seek:()=>0,proc_exit:e=>{if(global.process)process.exit(e);else throw"trying to exit with code "+e},random_get:(e,t)=>(crypto.getRandomValues(l(e,t)),0)},gojs:{"runtime.ticks":()=>h+performance.now(),"runtime.sleepTicks":e=>{setTimeout(this._inst.exports.go_scheduler,e)},"syscall/js.finalizeRef":e=>{console.error("syscall/js.finalizeRef not implemented")},"syscall/js.stringVal":(e,t)=>{const n=r(e,t);return c(n)},"syscall/js.valueGet":(e,t,n)=>{let s=r(t,n),o=i(e),a=Reflect.get(o,s);return c(a)},"syscall/js.valueSet":(e,t,n,s)=>{const o=i(e),a=r(t,n),c=i(s);Reflect.set(o,a,c)},"syscall/js.valueDelete":(e,t,n)=>{const s=i(e),o=r(t,n);Reflect.deleteProperty(s,o)},"syscall/js.valueIndex":(e,t)=>c(Reflect.get(i(e),t)),"syscall/js.valueSetIndex":(e,t,n)=>{Reflect.set(i(e),t,i(n))},"syscall/js.valueCall":(t,n,s,o,c,l,u)=>{const h=i(n),m=r(s,o),f=d(c,l,u);try{const n=Reflect.get(h,m);a(t,Reflect.apply(n,h,f)),e().setUint8(t+8,1)}catch(n){a(t,n),e().setUint8(t+8,0)}},"syscall/js.valueInvoke":(t,n,s,o,r)=>{try{const c=i(n),l=d(s,o,r);a(t,Reflect.apply(c,void 0,l)),e().setUint8(t+8,1)}catch(n){a(t,n),e().setUint8(t+8,0)}},"syscall/js.valueNew":(t,n,s,o,r)=>{const c=i(n),l=d(s,o,r);try{a(t,Reflect.construct(c,l)),e().setUint8(t+8,1)}catch(n){a(t,n),e().setUint8(t+8,0)}},"syscall/js.valueLength":e=>i(e).length,"syscall/js.valuePrepareString":(t,n)=>{const r=String(i(n)),s=o.encode(r);a(t,s),e().setInt32(t+8,s.length,!0)},"syscall/js.valueLoadString":(e,t,n,s)=>{const o=i(e);l(t,n,s).set(o)},"syscall/js.valueInstanceOf":(e,t)=>i(e)instanceof i(t),"syscall/js.copyBytesToGo":(t,n,s,o,a)=>{let h=t,c=t+4;const d=l(n,s),r=i(a);if(!(r instanceof Uint8Array||r instanceof Uint8ClampedArray)){e().setUint8(c,0);return}const u=r.subarray(0,d.length);d.set(u),e().setUint32(h,u.length,!0),e().setUint8(c,1)},"syscall/js.copyBytesToJS":(t,n,s,o)=>{let u=t,c=t+4;const r=i(n),h=l(s,o);if(!(r instanceof Uint8Array||r instanceof Uint8ClampedArray)){e().setUint8(c,0);return}const d=h.subarray(0,r.length);r.set(d),e().setUint32(u,d.length,!0),e().setUint8(c,1)}}},this.importObject.env=this.importObject.gojs}async run(e){this._inst=e,this._values=[NaN,0,null,!0,!1,global,this],this._goRefCounts=[],this._ids=new Map,this._idPool=[],this.exited=!1;const t=new DataView(this._inst.exports.memory.buffer);for(;!0;){const e=new Promise(e=>{this._resolveCallbackPromise=()=>{if(this.exited)throw new Error("bad callback: Go program has already exited");setTimeout(e,0)}});if(this._inst.exports._start(),this.exited)break;await e}}_resume(){if(this.exited)throw new Error("Go program has already exited");this._inst.exports.resume(),this.exited&&this._resolveExitPromise()}_makeFuncWrapper(e){const t=this;return function(){const n={id:e,this:this,args:arguments};return t._pendingEvent=n,t._resume(),n.result}}},global.require&&global.require.main===module&&global.process&&global.process.versions&&!global.process.versions.electron){process.argv.length!=3&&(console.error("usage: go_js_wasm_exec [wasm binary] [arguments]"),process.exit(1));const e=new Go;WebAssembly.instantiate(fs.readFileSync(process.argv[2]),e.importObject).then(t=>e.run(t.instance)).catch(e=>{console.error(e),process.exit(1)})}})();const go=new Go,fetched=fetch("main.wasm");"instantiateStreaming"in WebAssembly?WebAssembly.instantiateStreaming(fetched,go.importObject).then(e=>go.run(e.instance)):fetched.then(e=>e.arrayBuffer()).then(e=>WebAssembly.instantiate(e,go.importObject).then(e=>go.run(e.instance)))</script>

frameworks/keyed/goui/build/main.wasm

125 KB
Binary file not shown.

frameworks/keyed/goui/go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module main
2+
3+
go 1.20
4+
5+
require github.com/twharmon/goui v0.1.2
6+
7+
// replace github.com/twharmon/goui v0.1.2 => ../../../../goui

frameworks/keyed/goui/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/twharmon/goui v0.1.2 h1:aYU4iGy4ME85PFcVPTMIIvPa30GmqCTFDZw0HU3aPAw=
2+
github.com/twharmon/goui v0.1.2/go.mod h1:Z2CGgcOPuRhYamMA5sNrscZCdo8nm8xQcXa+RwQDnZ4=

frameworks/keyed/goui/goui.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
server:
2+
port: 5000
3+
proxy: http://localhost:8080
4+
build:
5+
compiler: tinygo
6+
wasm_opt: true
7+
no_traps: true

frameworks/keyed/goui/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/keyed/goui/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "js-framework-benchmark-goui",
3+
"version": "0.0.1",
4+
"scripts": {
5+
"dev": "echo This is a no-op.",
6+
"build-prod": "echo This is a no-op. && echo The production build assets are tracked."
7+
},
8+
"js-framework-benchmark": {
9+
"customURL": "/build",
10+
"frameworkVersion": "0.1.2",
11+
"frameworkHomeURL": "https://github.com/twharmon/goui"
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1" />
5+
<title>GoUI</title>
6+
<link href="/css/currentStyle.css" rel="stylesheet" />
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
</body>
11+
</html>

frameworks/keyed/goui/src/app/app.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package app
2+
3+
import (
4+
"main/src/data"
5+
6+
"github.com/twharmon/goui"
7+
)
8+
9+
type AppState struct {
10+
Items []*data.Item
11+
Selected int
12+
}
13+
14+
var preload = goui.Element("span", &goui.Attributes{
15+
Class: "preloadicon glyphicon glyphicon-remove",
16+
AriaHidden: true,
17+
})
18+
19+
func App(goui.NoProps) *goui.Node {
20+
state, setState := goui.UseState(&AppState{})
21+
22+
return goui.Element("div", &goui.Attributes{
23+
Class: "container",
24+
Children: goui.Children{
25+
goui.Component(Jumbotron, JumbotronProps{SetState: setState}),
26+
goui.Element("table", &goui.Attributes{
27+
Class: "table table-hover table-striped test-data",
28+
Children: goui.Children{goui.Element("tbody", &goui.Attributes{
29+
Children: goui.Map(state.Items, func(item *data.Item) *goui.Node {
30+
return goui.Component(Row, RowProps{
31+
Selected: item.ID == state.Selected,
32+
Item: item,
33+
SetState: setState,
34+
})
35+
}),
36+
})},
37+
}),
38+
preload,
39+
},
40+
})
41+
}

0 commit comments

Comments
 (0)