elm-make icon indicating copy to clipboard operation
elm-make copied to clipboard

make Elm variable available on `this` scope.

Open ryan-haskell opened this issue 7 years ago • 3 comments

Heyo Evan

I was trying to use Elm in an Electron app and I ran into a weird error where the Elm variable was not defined.

I followed the tutorial at https://guide.elm-lang.org/interop/javascript.html like a noob.

Changing the generated file from var Elm = {} to this.Elm = {} gave me access to the variable, and my problems were resolved.

Likely, I goofed something up, but it's possible I finally made a contribution to Elm, and "wrote my first line" of Haskell code.

I'll attach a link to the repo so you can easily replicate the error.

ryan-haskell avatar Feb 28 '17 00:02 ryan-haskell

Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot avatar Feb 28 '17 00:02 process-bot

Repo with issue: https://github.com/RyanNHG/first-electron-app

ryan-haskell avatar Feb 28 '17 00:02 ryan-haskell

A workaround is shown here: https://github.com/mdgriffith/elm-electron-todomvc/blob/master/index.html

Where the line window.Elm = require('./elm.js') is used to make the Elm object globally available.

Choose your own adventure:

  • "Adding this.Elm to elm-make!"
  • "Adding window.Elm = require('./elm.js') to the guide for people using electron!"
  • "Neither, you're drunk Ryan, go home!"

Let me know what you think.

ryan-haskell avatar Feb 28 '17 01:02 ryan-haskell