Git Product home page Git Product logo

dom's People

Contributors

bketelsen avatar donmcnamara avatar johanbrandhorst avatar koodimetsa avatar miketonks avatar ricardoseriani avatar smoyer64 avatar sqaki avatar thegrumpylion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dom's Issues

panic when following the instructions in the README

Following the instructions as is, here is the error I'm getting in Chrome 71.0.3578.98 (Official Build) (64-bit) with Go version 1.11.4 darwin/amd64

running
wasm_exec.js:45 panic: invalid character 'd' after top-level value
wasm_exec.js:45 
wasm_exec.js:45 goroutine 1 [running]:
wasm_exec.js:45 main.main()
wasm_exec.js:45 	/Users/mattetti/Code/golang/src/github.com/dennwc/dom/cmd/app/main.go:97 +0x4b
wasm_exec.js:67 exit code: 2

It looks like maybe the data in the storage is bad, but I can't easily debug it, nor do I seem to get a lot of clues from the code:

if err := storage.GetItemJSON(stor, key, &s); err != nil {
				panic(err)
			}

Based on the error, it looks like bad JSON but I have no clue how to properly debug :(

error when following instructions in README

I followed the instructions in the readme and I got this error(?)

element.go:6:2: build constraints exclude all Go files in /usr/local/Cellar/go/1.11.4/libexec/src/syscall/js

when running go get -u github.com/dennwc/dom

this is my first attempt at playing with wasm so IDK if something in my environment is off. does GOOS or GOARCH need to be set for any of these commands?

Getting an element value ?

Trying to do the same thing as this issue => #6 but I think I still miss something ?
In my situation, I have input fields inside a form, can you provide a way to manipulate forms ?
I noticed that looping over the nodeList we got more elements than the actual form ? Any insight on that ?

form := dom.Doc.GetElementById("custom_form")
btn := dom.Doc.GetElementById("btn")
t := document.Call("getElementById", "target")
logger := log.New((*writer)(&t), "", log.LstdFlags)

btn.AddEventListener("click", func(_ dom.Event) {
	nodes := form.ChildNodes()
	for _, element := range nodes {
		logger.Print("ID: " + string(element.Id()) + " Value: " + string(element.JSValue().Get("value").String()))
	}
})

Getting element values?

How does one get element values with this package?

I tried calling myElement.GetAttribute("value"), but that ended up returning an empty value, rather than the value of my input field.

Is this something that needs additional implementation? Happy to PR something if that's the case.

GRPC over WebRTC using WASM

there is a pure webrtc golang impl here:https://github.com/pions/webrtc

SO i was thinking its maybe possible to do GRPC over Webrtc.
This could then allow p2p style architecture.
it woudl be usable for server to server and server to browser, Or server to desktop client.
So sort of one network transport for everything and GRPC for everything.

what do you think ? I am not sure it will work but its a metetr of trying i suspect.

BTW was very easy to get going and everything works immediatly.
I make it all into a Makefile so no reliance on bash files:

LIB=github.com/dennwc/dom
LIB_FSPATH=${GOPATH}/src/$(LIB)

WASM_FILES="$(GOROOT)/misc/wasm"

GRPC=${LIB_FSPATH}/examples/grpc-over-ws

dep:
	go get -u github.com/dennwc/dom
	go install github.com/dennwc/dom/cmd/wasm-server

open:
	code ${LIB_FSPATH}

##


run:
	cd ${GOPATH}/src/github.com/dennwc/dom && wasm-server

run-ex-grpc:
	cd $(GRPC) && GOOS=js GOARCH=wasm go build -o client.wasm ./client.go
	cd $(GRPC) && cp ${WASM_FILES}/wasm_exec.js ./
	cd $(GRPC) && go run ./server.go

Document

Dear

Please document it so easy to use..

Thanks

Change method signature to js.Class(class string, path ...string)

Both JavaScript and TypeScript allow access to global objects via dotted notation. At the same time, many libraries wrap their objects, classes and methods to avoid adding them to the global namespace.

Allowing dotted notation in js.Get() would simplify accessing wrapped types and would automatically supplement both js.Class() and js.New(). The following code works:

mdc := js.Get("mdc")
chips := mdc.Get("chips")
chipset := chips.Get("MDCChipSet")
chipsetEl := dom.Doc.CreateElement("div")
chipsetEl.SetAttribute("class", "mdc-chip-set")
chipset.Call("attachTo", chipsetEl)

But this code is much simpler to write and has the added benefit of using the js.Class() caching:

chipset := chips.Class("mdc.chips.MDCChipSet")
chipsetEl := dom.Doc.CreateElement("div")
chipsetEl.SetAttribute("class", "mdc-chip-set")
chipset.Call("attachTo", chipsetEl)

Avoid conflict with non-json storage content in cmd/app/main.go

When running wasm-server on this project, if storage already has some items which content isn't JSON, it will conflict.

Web Console Log:

running wasm_exec.js:47:6
panic: invalid character 'v' looking for beginning of value wasm_exec.js:47:6
wasm_exec.js:47:6
goroutine 1 [running]: wasm_exec.js:47:6
main.main() wasm_exec.js:47:6
/tmp/go-wasm/dom/cmd/app/main.go:97 +0x6e

Improve WebSocket API

The net.Conn interface doesn't match how WebSockets work as it's not a stream oriented protocol.

See golang/go#18152 (comment) and gopherjs/websocket#29

I think it'd be a good idea to recommend my library instead to avoid duplicate work. It supports compiling to Wasm and provides a more semantically appropriate API (while also providing a net.Conn adapter) or the API in this library should be changed.

Examples in README?

I'd like to start using the library but I'm too lazy to read the whole code so it would be nice to see some simple examples in readme

Simplify signatures in js.go

In PR #41 I talked about simplifying the signatures of several methods in js.go but rejected that as I thought it would be a breaking change. Since then, I've realized that because the first parameter is the same type as the second variadic parameter, the change is not in fact breaking and simplifies the signature of the end-user API.

I'd suggest that the following three method signatures be changed below:

  • From Get(name string, path ...string) to Get(name ...string
  • From Class(class string, path ...string) to Class(class ...string)
  • From (v Value) Get(name string, path ...string) to (v Value) Get(name ...string)

The change to the Class method slightly simplifies the key generation but otherwise the code is pretty much the same. The main benefit is that, having a single parameter, it makes more sense when a nested class is specified. Consider Class("mdc", "chips", "MDCChipSet") as described in my previous example - with the original signature, the class parameter would contain mdc but the actual class (MDCChipSet) being loaded would be the second element of the path slice. With the revised signature, the elements make sense in the order they're provided.

I do realize this is a completely cosmetic change but wanted to present the idea prior to the library reaching 1.0. If it sounds reasonable, I've got a branch I used to test that this could be done simply - assign this to me and I'll clean up that branch and submit a PR.

OneTimeEvent defines boolean 'fired' but never sets it

The CallbackGroup method OneTimeEvent defines a local boolean fired and it is captured in a Callback closure but the Callback never sets the boolean so it looks superfluous. The intent was probably to set the boolean before the fnc local was called.

Promise wrapper not using done channel

Looks like the 'done' variable is created and closed by the Promised method but never waited on. A typo or something subtle going on that I didn't recognize when looking through this code?

I was actually looking for an example of how to marry the idea of the promise's asynchronous calls to onFulfilled and onRejected callbacks with the go-wasm requirement to call Release on the two Callbacks that would have been created, and this wrapper does show that. Each callback is a closure that will release both callbacks once invoked. Nice.

And naively, I was wondering how to slip a call to 'go' in such code to indicate that the callbacks would be done on a separate goroutine but of course it doesn't call go, the javascript Promise will get one of the callbacks invoked on a subsequent trip through the javascript event loop. It was helpful to see this code and have to figure out how to go runtime would handle it without another goroutine being created. A javascript promise is an interesting way to write an asynchronous function without calling go.

Development discussion

Hi @dennwc, many thanks for this awesome library. I have a lot of changes i want to push to this but before i start shipping tons of code, i want to ask if there's a way to contact you to discuss some general concepts i would like to see implemented and some changes i want to have in this.

I can also explain here in a ticket but since the ideas i have touch on some basic structures in the lib i would like some input first. I can always push to my fork of course and file a PR for you to see what i am talking about.

Cannot make it to work with go modules

Hello,
quick note: I'm go newbie and I've never encountered similar error with other go packages.
I'm trying to use this package using go modules (go.mod). Unfortunately, it seems like only color.go file is visible. Here are my project files:

go.mod:

module goasmf

go 1.12

require github.com/dennwc/dom v0.3.0

main.go:

package goasmf

import (
    "fmt"
    "github.com/dennwc/dom"
)

func main() {
    println("Testing WebAsm!")
    var color dom.Color = "red"
    dom.GetWindow()
}

go build output:

tomek$ go build
# goasmf
./main.go:13:2: undefined: dom.GetWindow

Working without modules and downloading dependency using go get -t github.com/dennwc/dom works fine, though

Require(path string) file typing is weak (has work-around)

Problem

The Require(path string) method uses

dom/require.go

Line 37 in 7f87333

if strings.HasSuffix(path, ".css") {
to determine whether a file is CSS simply based on its suffix and defaults all other files loaded to JS. This presents a problem for certain types of CSS files such as any of the fonts provided by fonts.googleapis.com as the URL returns a valid CSS document and properly sets its mime-type to text/css but Require(path string) adds it to the document as a script file.

For instance, the following code:

dom.Require("https://fonts.googleapis.com/icon?family=Material+Icons")

results in the this element in <head>:

<script async="" src="https://fonts.googleapis.com/icon?family=Material+Icons"></script>

A better solution would be to use the Content-Type header returned by the server to decide whether the provided path is a CSS file or a JS file. An added benefit is that the process can fail before it tries to load the added file to the page if the Content-Type doesn't match a supported type.

Workaround

I've temporarily solved this problem by adding a URL fragment to the end of the url as follows:

dom.Require("https://fonts.googleapis.com/icon?family=Material+Icons#.css")

This portion of the URL is not sent to the server but does match the prefix that Require(path string) expects and results in the expected HTML element:

<link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons#.css">

compile failure with go 1.13

If compiling with Go 1.13, a compiling error comes up:

github.com/dennwc/dom/js

../../../../go/pkg/mod/github.com/dennwc/[email protected]/js/bytes.go:20:2: undefined: js.TypedArray
../../../../go/pkg/mod/github.com/dennwc/[email protected]/js/bytes.go:30:7: undefined: js.TypedArrayOf

The change log (https://golang.org/doc/go1.13#syscall/js) states that the types have been changed: "TypedArrayOf has been replaced by CopyBytesToGo and CopyBytesToJS for copying bytes between a byte slice and a Uint8Array."

Is this project dead?

There are now two forks on Github that have on-going maintenance while there's not really any activity here ... should I switch to one of the maintained projects? As you've seen from my previous PRs, I'm not afraid to help with this project but you'd need to be around to at least merge (or reject) the PRs.

Replace syscall/js with gopherwasm

Replace syscall/js with gopherwasm/js.

GopherWasm is a wrapper for GopherJS (gopherjs/js) and Wasm (syscall/js). With this, you can make your application work with both GopherJS and Wasm.
GopherWasm's API emulates syscall/js, so please refer syscall/js API document to know how to use API of GopherWasm.

This will allow to compile the programs for wasm and gopherjs without any changes.

Possibly add instructions for getting autocomplete working in vscode?

After a little struggle I was able to get autocomplete working in VS code by setting some workspace level environment variables. I'm not sure how well known that is. Do you think it is worth adding to the README in this project?

I will gladly open a PR, but if you don't think this is the right place that is understandable.

Confusion regarding the Get & Set functions for js.go

Hi! I saw Value{global} being used and global being used for the get & set function. Are they interchangeable?

// Get is a shorthand for Global().Get().
func Get(name string, path ...string) Value {
	return Value{global}.Get(name, path...)
}

// Set is a shorthand for Global().Set().
func Set(name string, v interface{}) {
	global.Set(name, toJS(v))
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.