Giter VIP home page Giter VIP logo

Comments (3)

abhi18av avatar abhi18av commented on June 15, 2024

Whoops, I've debugged this one. The solution was simply to add the proper relative file name in the index.html. But then arises a different problem with the release compiled javascript and it throws the following error in the browser.

TypeError: snake.core.init is not a function

Perhaps, this is another quick fix but nothing strikes my mind as of now.

from learn-reagent-course-files.

jacekschae avatar jacekschae commented on June 15, 2024

Seems like you are exporting main and not init

defn init []
  ;; init is called ONCE when the page loads
  ;; this is called in the index.html and must be exported
  ;; so it is available even in :advanced release builds
 ;(js/console.log "init")



 ;; Resize canvas object
 (resize-canvas)
  ;; Remove all listen events
 (events/removeAll js/document)
  ;; Register event listener `on-keydown` event
 (events/listen js/document goog.events.EventType.KEYDOWN on-keydown)
  ;; Start the game loop
(game-loop))

(defn ^:export main
  []
  (r/render
    [app]
    (.getElementById js/document "app")))

When you don't add ^:export before init, or any function name that you want to access from html file it will be shortened by the google closure compiler and might end up as - let's say c - in this way it cannot find the init function. Therefore the error.

You can also change the way you setup shadow-cljs and don't worry about the ^:export - check out learn re-frame setup In this way you have init-fn which takes care of ^:export and the only thing you need to add to index.html is the a script name.

Hope that helps, if you would have any further questions let me know.

from learn-reagent-course-files.

abhi18av avatar abhi18av commented on June 15, 2024

Ahh, yes - that's true! I'll be for sure covering up the re-frame tutorial today itself. Thanks @jacekschae , your course has been one of the best learning experiences for people learning ClojureScript 👍

from learn-reagent-course-files.

Related Issues (20)

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.