1. 44
  1. 5

    After reading the well written language tour, I have decided to give Gleam a try. I wanted to use it to build a single page application. Unfortunately, I was not able to figure out how to create and run a project with only a JavaScript runtime (is it possible?).

    I have searched GitHub issues and discussions. I have found template-gleam-javascript which is archived and understandably does not work. Unfortunately, using Discord requires an account, so I could not ask questions there.

    I think the language documentation is very good. I wish there was a document or an example application for starting with Gleam when you want to target a browser.

    1. 10

      Hello! Thanks for trying Gleam. Unfortunately the documentation is all very fresh at the moment, more in depth tutorials are to come later. That template is no longer needed as we now have JavaScript support in the build tool itself.

      To use the JavaScript target you can either add target = "javascript" to your gleam.toml or add --target javascript to gleam run, gleam test, etc.

      Here is an example SPA written in Gleam https://github.com/gleam-lang/developer-survey/tree/main/frontend

      Other places you can go to talk to the community is the GitHub discussions page or StackOverflow using the gleam tag.

      1. 1

        Do you know of other open-source projects we can study?

        A component I use a lot is the typeahead, like Twitter’s typeahead: async search, custom template for the results, etc. Would it be easy to hook into it or to replicate with Gleam? How would you approach that?

      2. 3

        The Gleam v0.16 release announcement contains a few example HTML+JS widgets written in Gleam and running in the page. Perhaps that code + examining the page source is enough to get started? You’re definitely right that it’s a gap in the docs.

        Most examples define 3 external fns that compile to JS’s document.querySelector, Reflect.get, and Reflect.set(on element, property, to value).

        1. 1

          That looks super neat. I’d love to ditch JS for a dynamic client application. Do we know of bigger code bases we could learn from?

          A UI component I use a lot is a typeahead, like twitter’s typeahead.js: async search, custom template for the results, etc. Would it be easy to hook into it or to replicate with Gleam?

      3. 2

        Great to see improvements here! I’m embarrassed to say that I didn’t know Gleam compiled to JavaScript until now.

        1. 1

          Reporting a typo in this article:

          the excellent Hypefine command

          “Hypefine” should be “Hyperfine”, or “hyperfine” to match the capitalization in the tool’s README.