WIP: documentation + bug fixes for JS / examples #5

Draft
hamza wants to merge 5 commits from hamza/golang-wasm:master into master
There is no content yet.
hamza force-pushed master from 74e9161759 to 6930708b63 2021-03-22 08:10:25 +07:00 Compare
chanbakjsd requested changes 2021-03-22 16:02:40 +07:00
@ -4,3 +4,3 @@
<head>
<meta charset="utf-8" />
<title>Example</title>
<title>Go Mod Wasm Example</title>

WASM capitalization.

WASM capitalization.
@ -7,3 +7,4 @@
</head>
<body>
<h1>This is an example Go Wasm Project.</h1>

WASM capitalization.

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.

Go capitalization.
@ -10,0 +17,4 @@
<h2>Value from Go:</h2>
<h3 id="value">&nbsp;</h3>
<h2>Call function from Go</h2>

Add :

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.

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)

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

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.

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.

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.

Capitalization.
@ -6,4 +5,1 @@
console.log(await hello());
console.log(await helloName("world"));
})()

Semicolons.

Semicolons.
src/bridge.js Outdated
@ -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.

Typo: seconds.
src/bridge.js Outdated
@ -6,2 +12,4 @@
const maxTime = 3 * 1000;
/**
* bridge is an easier way to refer to the Go wasm object.

Capitalization.

Capitalization.
src/bridge.js Outdated
@ -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.

`requestAnimationFrame` never returns. This function does return.
src/bridge.js Outdated
@ -75,5 +79,6 @@ export default function (getBytes) {
}
);
bridge.__proxy__ = proxy

Capitalization.

Capitalization.
src/bridge.js Outdated
@ -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.

WASM instead of web assembly for consistency.
hamza force-pushed master from 6930708b63 to e84d5868fa 2021-03-22 16:38:56 +07:00 Compare
hamza force-pushed master from e84d5868fa to 219682c472 2021-03-22 16:39:31 +07:00 Compare

Reviewers

chanbakjsd requested changes 2021-03-22 16:02:40 +07:00
This pull request has changes conflicting with the target branch.
  • example/basic/dist/index.html
  • example/basic/src/api/main.go
  • package.json
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b hamza-master master
git pull master

Step 2:

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff hamza-master
git push origin master
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Team-Ortix/golang-wasm#5
There is no content yet.