-
Notifications
You must be signed in to change notification settings - Fork 570
Any way to get to module.exports
?
#56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
Ok, I've tried that, which generates almost the code that I want:
But I get:
I think this problem is specific to the JavaScript environment of Atom packages.It seems to be similar to Node.js, but it has a few differences. If I add some logging statements to the top section of the javascript: if (typeof window !== "undefined") { /* web page */
console.log("web page")
}
if (typeof self !== "undefined") { /* web worker */
console.log("web worker")
}
if (typeof global !== "undefined") { /* Node.js */
console.log("Node.js")
} Then I see the following output with all 3 if statements being true: So, despite me wanting to do What's strange is even if I modify the detection code manually to get it to use the Node.js path, i.e.: var $global;
if (false && typeof window !== "undefined") { /* web page */
console.log("web page")
$global = window;
} else if (false && typeof self !== "undefined") { /* web worker */
console.log("web worker")
$global = self;
} else if (typeof global !== "undefined") { /* Node.js */
console.log("Node.js")
$global = global;
$global.require = require;
} else {
console.log("warning: no global object found")
} To force
But it does work if I manually change that to:
So it seems for Atom packages, Another change I had to do to make it work was to replace all Any thoughts on whether you'd be willing to make some changes in order to support using gopherjs to convert Go functionality into exportable JavaScript functions that can be
|
I really like the idea of using GopherJS for Atom packages. We can make that work! :-) I am considering doing I'm taking care of the |
Great! :D
I will try and let you know within 20 mins. |
I tried simply setting So I tried keeping Then I changed this:
To:
But it didn't work:
|
I have Atom on my machine. Can you tell me a bit about how I can test this? 2014-06-22 22:23 GMT+02:00 Dmitri Shuralyov notifications@github.com:
|
Sure, let me make a very simple atom package that you can try this out with. You will want to drop it in |
Okay, if you uncompress this zip into your https://dl.dropboxusercontent.com/u/8554242/temp/atom-gopherjs-test.zip I've modified it so whenever you save any file type in Atom, it appends " GopherJS working" at the end. |
Also, before re-regenerating the .js file, take a look at the existing one and search for "// ATOM CHANGE". These are the manual changes I had to do after Note that you can use View -> Reload to reload the package after you make changes to it inside |
Thank you @neelance! That should completely remove the manual steps that I had to do after |
Seems like Node's (function (exports, require, module, __filename, __dirname) {
// your code is here
}); So |
I'm glad I could help. :-) |
For reference, with the 4ececf2 commit of gopherjs, I changed my Go code to: package main
import (
"github.com/gopherjs/gopherjs/js"
)
func ProcessMarkdown(text string) string {
output := ... // do stuff using Go code!
return string(output)
}
func main() {
js.Module.Get("exports").Set("ProcessMarkdown", ProcessMarkdown)
} And running
Confirmed everything working. Thanks again! |
I'm writing atom bindings for gopherjs. https://github.com/JohannWeging/atom is working with a minimal example. The API matches with the official Atom API. |
Hi,
I have very little knowledge about JavaScript/Node.js/Atom packages, so take this question with a grain of salt.
It seems one can currently "export" a Go func to be accessible to the external JavaScript environment, say, on a webpage, by doing this:
The
js.Global.Set("Foo", Foo)
line ends up producing$global.Foo = $externalize(Foo, ($funcType([], [$String], false)));
, and$global
is set towindow
for a web page.However, I am looking to be able to have something equivalent to this in the generated javascript, in order to be able to
require()
it:Is there any way to achieve this with the current GopherJS?
If not, can a
var Module Object
be added togithub.com/gopherjs/gopherjs/js
so that it is possible?The text was updated successfully, but these errors were encountered: