WIP: documentation + bug fixes for JS / examples
#5
Draft
hamza
wants to merge 5 commits from hamza/golang-wasm:master
into master
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "hamza/golang-wasm:master"
Deleting a branch is permanent. It CANNOT be undone. Continue?
74e9161759
to6930708b63
@ -4,3 +4,3 @@
<head>
<meta charset="utf-8" />
<title>Example</title>
<title>Go Mod Wasm Example</title>
WASM capitalization.
@ -7,3 +7,4 @@
</head>
<body>
<h1>This is an example Go Wasm Project.</h1>
WASM capitalization.
@ -10,0 +10,4 @@
<h1>This is an example Go Wasm Project.</h1>
<h3>
<a href="https://gitea.teamortix.com/Team-Ortix/go-mod-wasm/src/branch/master/example/basic/src/api/main.go">
Sample go code
Go capitalization.
@ -10,0 +17,4 @@
<h2>Value from Go:</h2>
<h3 id="value"> </h3>
<h2>Call function from Go</h2>
Add
:
@ -0,0 +14,4 @@
// Wrapper is a simple JS function that when called with a Go Function, will return a new function that will throw
// if the property `error` is an instance of JavaScript's `error`.
//
// All Go functions in the bridgeName proxy are expected to be the result of calling wrapper with the Go function.
Double spaces.
@ -0,0 +39,4 @@
}
// Using this wrapper makes it possible to throw errors in go-fashion.
// This means that all wrapped functions must return error and a value.
A value and error. (Ordering)
@ -0,0 +42,4 @@
// This means that all wrapped functions must return error and a value.
//
// The __wrapper__ function from JS will automatically throw if the returned object has an 'error' property.
// Inversly, it will automatically give the result value if that property exists.
Typo: Inversely
@ -0,0 +43,4 @@
//
// The __wrapper__ function from JS will automatically throw if the returned object has an 'error' property.
// Inversly, it will automatically give the result value if that property exists.
// All go functions directly returned via wasm should keep this in mind.
Capitalization.
@ -0,0 +68,4 @@
// registered, and potentially crashing applications.
func ready() {
bridge.Set("__ready__", true)
<-make(chan bool, 0) // To use anything from Go WASM, the program may not exit.
Just do
select{}
, it's a simpler way to block.@ -20,0 +13,4 @@
// If returning a non-nil error value, the resulting promise will be rejected by API consumers.
// The rejected value will JavaScript's Error, with the message being the go error's message.
//
// See other examples which use the Go wasm bridge api, which show more flexibility and type safety when interacting
Capitalization.
@ -6,4 +5,1 @@
console.log(await hello());
console.log(await helloName("world"));
})()
Semicolons.
@ -6,0 +7,4 @@
/**
* The maximum amount of time that we would expect Wasm to take to initialize.
* If it doesn't initialize after this time, we send a warning to console.
* Most likely something has gone wrong if it takes more than 3 sconds to initialize.
Typo: seconds.
@ -6,2 +12,4 @@
const maxTime = 3 * 1000;
/**
* bridge is an easier way to refer to the Go wasm object.
Capitalization.
@ -30,0 +40,4 @@
/**
* Sleep is used when awaiting for Go Wasm to initialize.
* It uses the lowest possible sane delay time (via requestAnimationFrame).
* However, if the window is not focused, the function never returns.
requestAnimationFrame
never returns. This function does return.@ -75,5 +79,6 @@ export default function (getBytes) {
}
);
bridge.__proxy__ = proxy
Capitalization.
@ -63,1 +98,4 @@
res(bridge[key]);
if (args.length !== 0) {
console.warn("Retrieved value from web assembly returned non-error type, however called with arguments.")
WASM instead of web assembly for consistency.
6930708b63
toe84d5868fa
e84d5868fa
to219682c472
Reviewers
Step 1:
From your project repository, check out a new branch and test the changes.Step 2:
Merge the changes and update on Gitea.