Coder Social home page Coder Social logo

reagent-template's Introduction

reagent-template

A Leiningen template for projects using Reagent.

reagent-template

A Leiningen template for a Clojure/ClojureScript app based on Reagent, with a focus on providing a batteries included setup for development and deployment.

Requires JDK 1.7+

Getting Help

For any questions or discussion please come join us in the #reagent channel on the Clojurians Slack.

Usage

Create a new application project:

lein new reagent <name>

To enable cljs.test and doo use +test flag:

lein new reagent <name> +test

To run the tests using headless chrome first install karma and its plugins npm install -g karma-cli && npm install karma karma-cljs-test karma-chrome-launcher --save-dev, then use lein doo chrome-headless test once. For other environments please check doo's documentation.

To enable speclj with PhantomJS, use +spec flag:

lein new reagent <name> +spec

To run the tests, please use lein cljsbuild test. For installation instructions of PhantomJS, please see this.

To enable DevCards, use the +devcards flag:

lein new reagent <name> +devcards

To add CIDER plugin, use the +cider flag:

lein new reagent <name> +cider

To add less/sass support use +less or +sass flags:

lein new reagent <name> +less

To add figwheel (legacy), use the +figwheel flag:

lein new reagent <name> +figwheel

Development mode with shadow-cljs

To start the shadow-cljs compiler run

npm install
shadow-cljs watch app

Shadow-cljs automatically pushes cljs changes to the browser. The application will now be available at http://localhost:3000.

Development mode with Figwheel

To start the Figwheel compiler (if enabled with +figwheel flag), navigate to the project folder and run the following command in the terminal:

lein figwheel

To start the DevCards (if enabled with +devcards flag) build run

lein figwheel devcards

Figwheel will also automatically push cljs changes to the browser. The server will be available at http://localhost:3449 once Figwheel starts up. To view your devcards, type (switch-to-build devcards) at the Figwheel REPL and navigate to http://localhost:3449/cards.

Figwheel also starts nREPL using the value of the :nrepl-port in the :figwheel config found in project.clj. By default the port is set to 7002.

The figwheel server can have unexpected behaviors in some situations such as when using websockets. In this case it's recommended to run a standalone instance of a web server as follows:

lein do clean, run

The application will now be available at http://localhost:3000.

In case of using +less option you may also want to run

lein less4j auto

to autocompile less files.

In case of using +sass option you may also want to run

lein sass4clj auto

to autocompile sass/scss files.

Optional development tools

Start the browser REPL:

$ lein repl

The Jetty server can be started by running:

(start-server)

and stopped by running:

(stop-server)

Building for release

lein do clean, uberjar

Building for release with shadow-cljs

shadow-cljs release app

Deploying to Heroku

The project generates a system.properties used for Heroku deployments. Make sure you have Git and Heroku toolbelt installed, then simply follow the steps below.

Optionally, test that your application runs locally by running.

lein do clean, uberjar
heroku local

Now, you can initialize your git repo and commit your application.

git init
git add .
git commit -m "init"

create your app on Heroku

heroku create

optionally, create a database for the application

heroku addons:add heroku-postgresql

The connection settings can be found at your Heroku dashboard under the add-ons for the app.

deploy the application

git push heroku master

Your application should now be deployed to Heroku! For further instructions see the official documentation.

Contents

The template packages everything you need to create a production ready ClojureScript application following current best practices. The template uses the following features and libraries:

  • Reagent - ClojureScript interface to Facebook's React
  • reagent-forms - data binding library for Reagent
  • reagent-utils - utilities such as session and cookie management
  • Reitit - Routing, server and client side
  • Accountant - HTML5 history management, enabling href navigation in SPAs
  • Clerk - In page navigation for SPAs. Scroll restoration, anchor targeting, and such.
  • Hiccup - server-side HTML templating
  • Ring - Clojure HTTP interface
  • Prone - better exception reporting middleware for Ring
  • Heroku - the template is setup to work on Heroku out of the box, simply run git push heroku master

Options

The template supports the following options:

  • +test - ClojureScript testing support
  • +spec - use speclj for TDD/BDD
  • +less - use less for compiling Less CSS files
  • +sass - use sass for compiling Sass/Scss CSS files
  • +devcards - add Devcards support
  • +cider - add CIDER support
  • -clerk - do not add Clerk support

Contributing & Customizing

Take a look at the open issues, especially ones marked as help wanted. If you see one you'd like to address don't hesitate to start a discussion or submit a pull request.

If the template isn't doing quite what you're looking for, it's easy to create a local copy of your own following these simple steps:

git clone https://github.com/reagent-project/reagent-template.git
cd reagent-template
lein install

If you feel that your customizations are general enough to be useful for others then please consider making a pull request.

Requirements

  • JDK 1.7+
  • Leiningen 2.x

License

Copyright © 2015 Dmitri Sotnikov

Distributed under the The MIT License (MIT).

reagent-template's People

Contributors

aardvark avatar anders-e avatar deraen avatar devth avatar ducky427 avatar edvorg avatar frozenlock avatar gadfly361 avatar harleqin avatar hura avatar joseluisdacruz avatar kix avatar lvh avatar mikavilpas avatar mswift42 avatar p-b-west avatar paulbutcher avatar petrvolny avatar pez avatar pmlarocque avatar prestancedesign avatar r6eve avatar teodorlu avatar thheller avatar thiagofm avatar uhnuser avatar vnctaing avatar ykarikos avatar yogthos avatar zjhmale 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

reagent-template's Issues

unable to run tests (compiling fails)

Hi,

I created a new project using lein new reagent hello-world +test. (The below is on a virgin project created using the template).

When I run lein cljsbuild test unit it throws the following error while compiling test.js -

Compiling ClojureScript.
Compiling "target/test.js" from ["src/cljs"]...
Compiling "target/test.js" failed.
java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:301)
at cljs.closure$load_externs$load_js__3229$fn__3230.invoke(closure.clj:223)

I get the same error while even doing a lein cljsbuild once. However lein fighweel compiles the code and does not throw an error.

Is some figwheel dependency causing a problem ? Can you please help, this is driving me crazy. Is there an alternate way to just run my tests ?

force-update-all needed to re-render after changing non-core ns

If you change a component in a namespace other than core, it won't be re-rendered by the call to core/init! in the jsload-callback in dev/cljs/reagent/dev.cljs. In order to make re-rendering work, I had to replace it by a call to force-update-all.

I would create a pull request, but since force-update-all was introduced in holmsand/reagent@ba995c2 and reagent-template uses reagent v0.4.2, it won't work until a more recent version of reagent is used. In any case, I am not sure if it is the best approach, but at least it works.

browser-repl does not work

I found I had to require foo.dev and then call foo.dev/browser-repl for it to work.

So either the docs need to reflect that, or there's a bit of namespace magic that could be done to make it work as advertised.

production build includes source maps

It appears that if I build an uberjar using lein ring uberjar, my build will still include source maps. I think this is a problem because the source map file is actually larger than app.js.

Not connecting on ws://localhost:9001

I generate a brand new project with
$ lein new reagent rt

After
$ lein cljsbuild once
$ lein ring server
...somewhere else...
$ lein repl
(browser repl)

I cannot connect using ws://localhost:9001

I get, on Chrome,
This webpage is not available
The webpage at ws://localhost:9001/ might be temporarily down or it may have moved permanently to a new web address.
Error code: ERR_DISALLOWED_URL_SCHEME

If I try http://localhost:9001, I get
Please connect with a web socket!
which comes directly from weasel, so there is a server listening.

Any idea what I'm doing wrong.

OS X 10.10.1 (Yosemite.)

Use x CSS preprocessing language

I noticed there is a way to get Less running but I'd like to use Stylus or SCSS.

I'd love to contribute if you can give me a starting point.

Cheers!

App deployed to Heroku cannot start in 60 seconds

I am having difficulties deploying an app built with the template to Heroku. The generated Procfile tries to run the following task in a web worker:

 web: lein with-profile production trampoline ring server

When executing this task Leiningen begins downloading a gazillion of dependencies including the ones unnecessary for production (e.g figwheel), in spite of the fact that the standalone .jar file had already been built by the slug compiler. This results in the following error:

2014-12-29T00:58:50.506270+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2014-12-29T00:58:50.506504+00:00 heroku[web.1]: Stopping process with SIGKILL
2014-12-29T00:58:51.285273+00:00 heroku[web.1]: Process exited with status 137
2014-12-29T00:58:51.290057+00:00 heroku[web.1]: State changed from starting to crashed

I tried changing the Procfile so that the jar file is executed directly:

web: java $JVM_OPTS -jar target/myapp.jar 

But this doesn't work either, as the ring handler namespace does not include the -main method, and for some reason, lein uberjar does not generate a self-executable ring server.

What's the right way to run the app on Heroku and to avoid fetching dependencies in the web worker?

circular dependency detected

sorry for the characters, thats just how it shows up in windows. project.clj below

Focusing on build ids: app
?[0mCompiling "resources/public/js/app.js" from ["src/cljs" "env/dev/cljs"]...
?[31mCompiling "resources/public/js/app.js" failed.?[0m
clojure.lang.ExceptionInfo: failed compiling file:src\cljs\reagent\core.cljs
 at clojure.core$ex_info.invoke (core.clj:4403)
Caused by: clojure.lang.ExceptionInfo: Assert failed: Circular dependency detected [reagent.core]
(every? (fn* [p1__1802#] (not (contains? *cljs-dep-set* p1__1802#))) deps) at line 2 src\cljs\reagent\core.cljs
 at clojure.core$ex_info.invoke (core.clj:4403)
Caused by: java.lang.AssertionError: Assert failed: Circular dependency detected [reagent.core]
(every? (fn* [p1__1802#] (not (contains? *cljs-dep-set* p1__1802#))) deps)
 at cljs.analyzer$analyze_deps.invoke (analyzer.clj:1254)
?[0m

(defproject reagent "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}

  :source-paths ["src/clj" "src/cljs"]

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [ring-server "0.4.0"]
                 [cljsjs/react "0.13.1-0"]
                 [reagent "0.5.0"]
                 [reagent-forms "0.5.0"]
                 [reagent-utils "0.1.4"]
                 [org.clojure/clojurescript "0.0-3196" :scope "provided"]
                 [ring "1.3.2"]
                 [ring/ring-defaults "0.1.4"]
                 [prone "0.8.1"]
                 [compojure "1.3.3"]
                 [selmer "0.8.2"]
                 [environ "1.0.0"]
                 [secretary "1.2.3"]]

  :plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]
            [lein-cljsbuild "1.0.4"]
            [lein-environ "1.0.0"]
            [lein-ring "0.9.1"]
            [lein-asset-minifier "0.2.2"]]

  :ring {:handler reagent.handler/app
         :uberwar-name "reagent.war"}

  :min-lein-version "2.5.0"

  :uberjar-name "reagent.jar"

  :main reagent.server

  :clean-targets ^{:protect false} ["resources/public/js"]

  :minify-assets
  {:assets
    {"resources/public/css/site.min.css" "resources/public/css/site.css"}}

  :cljsbuild {:builds {:app {:source-paths ["src/cljs"]
                             :compiler {:output-to     "resources/public/js/app.js"
                                        :output-dir    "resources/public/js/out"
                                        :asset-path   "js/out"
                                        :optimizations :none
                                        :pretty-print  true}}}}

  :profiles {:dev {:repl-options {:init-ns reagent.repl
                                  :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}

                   :dependencies [[ring-mock "0.1.5"]
                                  [ring/ring-devel "1.3.2"]
                                  [leiningen "2.5.1"]
                                  [figwheel "0.2.6"]
                                  [weasel "0.6.0"]
                                  [com.cemerick/piggieback "0.2.0"]
                                  [org.clojure/tools.nrepl "0.2.10"]
                                  [pjstadig/humane-test-output "0.7.0"]]

                   :source-paths ["env/dev/clj"]
                   :plugins [[lein-figwheel "0.2.5"]]

                   :injections [(require 'pjstadig.humane-test-output)
                                (pjstadig.humane-test-output/activate!)]

                   :figwheel {:http-server-root "public"
                              :server-port 3449
                              :css-dirs ["resources/public/css"]
                              :ring-handler reagent.handler/app}

                   :env {:dev? true}

                   :cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"]
                                              :compiler {:main "reagent.dev"
                                                         :source-map true}}
}
}}

             :uberjar {:hooks [leiningen.cljsbuild minify-assets.plugin/hooks]
                       :env {:production true}
                       :aot :all
                       :omit-source true
                       :cljsbuild {:jar true
                                   :builds {:app
                                             {:source-paths ["env/prod/cljs"]
                                              :compiler
                                              {:optimizations :advanced
                                               :pretty-print false}}}}}})

Tinkering with template for cljs > 2755

I've been tinkering with reagent-template to try to create projects which depend on the most recent facilities in clojurescript. This is tricky, because of my very limited understanding of the whole ecosystem, and the fact that it keeps changing.

Reagent itself has been updated to accommodate these changes, but, according to this message
nrepl/weasel#44
the set of necessary changes will not be complete until the next release of clojurescript (somewhere beyond 2779), at which time weasel will also be updated.

Given my poor initial understanding, the chances I will sort this out are slim. However, I would appreciate being able to ask questions in this issue thread about puzzles I encounter.

println in development must be removed in production

I've left comments in for debugging and production will fail since the enable-console-print! is not called in production. Is it proper just to remove them? I find them useful to keep sometimes between versions and I'd rather silently ignore them than have to outright remove them.

Component from other ns doesn't see figwheel updates if it is stored in state atom

This isn't strictly about the template, but it appears to be caused by some weird intersection between how figwheel and reagent work, so asking here - happy to ask elsewhere if there's a more appropriate place.

I've been trying to get figwheel working with my reagent project based on this template, and have been bitten by a strange edge case which I've finally managed to narrow down. I have an example project to demonstrate it here: https://github.com/rsslldnphy/reagent-figwheel-issue (apologies for the weird naming in it, I've been struggling with this all day and it's sent me a bit round the bend) but I'll do my best to describe it here too:

It happens when your page components are defined in separate namespaces. You import them into the main namespace and set up the routes to assoc them into the app-state as :current-page - which works as expected. However, when you make changes to the page component and save the file, although figwheel successfully sends the updated file to the browser, you don't see your changes.

I think this is because the var in the app-state is still the old function - it's never looked up again so the new code isn't seen. If the page component is in the namespace that is reloaded then it works no problem. If you define a component that simply wraps the page component in the other namespace, and put THAT into the app-state, then it works. But a component from another namespace, directly in the app-state, doesn't see updates.

In the example project I've linked above, I have two lines that describe the smallest change I could find to manifest the problem. Comment in the first one and you'll won't see updates to the bar/fish component. Comment in the second one and you will.

(defn barfish [] [bar/fish])
(secretary/defroute "/" []
  ;;(put! :current-page bar/fish)) ;;<--- doesn't update when contents of bar/fish changed
  (put! :current-page barfish))    ;;<--- does update when contents of bar/fish changed

This might just be my limited experience with Reagent and Figwheel - but should this be something that should work or could be made to work?

:cljsbuild :test-commands "unit" has keyword in it

                   :cljsbuild {:builds {:app {:source-paths ["env/dev/cljs"]
                                              :compiler {:main "shrieker.dev"
                                                         :source-map true}}
                                        :test {:source-paths ["src/cljs"  "test/cljs"]
                                               :compiler {:output-to "target/test.js"
                                                          :optimizations :whitespace
                                                          :pretty-print true
                                                          :preamble ["react/react.js"]}}}
                               :test-commands {"unit" ["phantomjs" :runner
                                                       "test/vendor/es5-shim.js"
                                                       "test/vendor/es5-sham.js"
                                                       "test/vendor/console-polyfill.js"
                                                       "target/test.js"]}}}

... resulting in following complaint:

➜  shrieker git:(master) ✗ lein cljsbuild test unit                                                                                                                       18:44:09
Compiling ClojureScript.
Invalid :test-command, contains non-string value: [phantomjs :runner test/vendor/es5-shim.js test/vendor/es5-sham.js test/vendor/console-polyfill.js target/test.js]

I'm not sure what that key means or how this is supposed to work.

lein new reagent foo doesn't work

Borkdude@fina000 /tmp $ lein new reagent foo
Failed to resolve version for reagent:lein-template:jar:RELEASE: Could not find metadata reagent:lein-template/maven-metadata.xml in local (/Users/Borkdude/.m2/repository)
This could be due to a typo in :dependencies or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.
Could not find template reagent on the classpath.

Missing figwheel dependency

After creating a new project with lein new reagent ... I discovered that the cljs side wouldn't build, because of this error:

Caused by: clojure.lang.ExceptionInfo: No such namespace: figwheel.client, could not locate figwheel/client.cljs or figwheel/client.clj at line 1 env\dev\cljs\wunderprojectj\dev.cljs

It seems dev.cljs makes use of the figwheel library, but it's not actually included in the template's project.clj.

Adding [figwheel "0.3.1"] to the cljs portion of the project.clj fixed the issue.

How do I run tests inside figwheel with the given setup?

I've been trying to discover that lately.

Running lein cljsbuild test takes too much time, so you don't get a fast feedback and can't TDD.

I know it's a bit of stackoverflow question, but this should also be added to the project documentation. I can add it with all the pleasure in the world if I get an answer(or discover that).

browser fails to load fresh figwheel created javascript

When making a change in a cljs file figwheel compiles it, states notifying browser that file changed: ... but the browser ignores the latest and throws a warning: Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

Steps to reproduce:

  • lein new reagent reagent-test
  • cd reagent-test
  • lein ring server
  • lein repl
  • (in repl) (start-figwheel)
  • (once figwheel has finished compiling) start a browser
  • edit src/cljs/reagent-test/core.cljs (e.g. add a space) and save
  • wait for figwheel to compile
  • boom

The behaviour is the same regardless of whether the browser-repl is started and attached to the browser.

Tested in latest Chromium and Firefox.

Unable to open up a repl with lein repl

I have created a new reagent project based on the instructions in the Readme lein new reagent testr When I type lein repl in the project directory I receive the following error

<CompilerException java.io.FileNotFoundException: Could not locate cemerick/piggieback__init.class or cemerick/piggieback.clj on classpath: , compiling:(testr/dev.clj:1:1)> Error loading cemerick.piggieback: Could not locate cemerick/piggieback__init.class or cemerick/piggieback.clj on classpath: Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: cemerick.piggieback/wrap-cljs-repl in this context, compiling:(/private/var/folders/yy/s1hxr1fx0y1561k7h25lrv7c0000gn/T/form-init1127347182220128335.clj:1:2726)

followed by a stacktrace which has

Caused by: java.lang.RuntimeException: Unable to resolve var: cemerick.piggieback/wrap-cljs-repl in this context

near the end

+cljx crashes lein test

It seems that the :prep-tasks "cljx once" in the project.clj is messing with with lein test command.

This is the error I'm getting:

java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.String
 at clojure.core$symbol.invoke (core.clj:547)
    leiningen.core.utils$require_resolve.invoke (utils.clj:71)
    leiningen.core.main$lookup_task_var.invoke (main.clj:60)
    leiningen.core.main$resolve_task.invoke (main.clj:260)
    leiningen.core.main$resolve_task.invoke (main.clj:264)
    leiningen.core.main$apply_task.invoke (main.clj:294)
    lein_environ.plugin$write_env_to_file.invoke (plugin.clj:11)
    clojure.lang.Var.invoke (Var.java:394)
    clojure.lang.AFn.applyToHelper (AFn.java:165)
    clojure.lang.Var.applyTo (Var.java:700)
    clojure.core$apply.invoke (core.clj:626)
    robert.hooke$compose_hooks$fn__11692.doInvoke (hooke.clj:40)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.core$apply.invoke (core.clj:624)
    robert.hooke$run_hooks.invoke (hooke.clj:46)

If I remove the :prep-tasks, everything runs fine.

index.html file is missing.

With commit 1d405d6 the index.html file in resources/templates was removed.

How am I supposed to add static resources now (bootstrap, material design, ...) ?

Changing cljs code produces WebSocket error

I created a new project with lein new reagent reagenttmp. Then I do a:

lein repl
(require 'reagenttmp.dev)
(in-ns 'reagenttmp.dev)
(start-figwheel)
(browser-repl)

When I connect to http://localhost:3449 all works fine. I see the example page an the Weasel repl is hooked up.

After changing some code in core.cljs (like :h2 into :h3), the code reloads in the browser, but I also see this error output in the browser console:

Figwheel: trying to open cljs reload socket
utils.js:49 Figwheel: socket connection established
repl.js:135 Opened Websocket REPL connection
utils.js:49 Figwheel: notified of file changes
history.js:237 Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
repl.js:135 Opened Websocket REPL connection
repl.js:21 Websocket REPL error :occupied
websocket.js:279 WebSocket connection to 'ws://localhost:9001/' failed: Close received after close
repl.js:178 WebSocket error goog.net.WebSocket.ErrorEvent {type: "error_1", target: goog.net.WebSocket, currentTarget: goog.net.WebSocket, propagationStopped_: false, defaultPrevented: false…}
repl.js:163 Closed Websocket REPL connection
utils.js:49 Figwheel: loaded these files
utils.js:62 ("reagenttmp/core.js" "reagenttmp/dev.js")

Is it ok that dev.js is reloaded? That seems to cause a rewiring of the WebSocket connection. I tried to compare that with a chestnut project. On the chestnut side it would only reload the core.js file. But apart from different library versions I can't seem to find the difference.

Thanks,
Torsten.

core.cljs is overwritten by core.cljx

I scratched my head for quite a while trying to understand why the compiled js wasn't the one in core.clj. Turns out there's a default core.cljx that's overwriting the file when generating the cljs version.

app-state & page to render function and Multi-methods

In {{project-ns}}.core, instead of storing the function to render itself like page1, page2 in app-state, wouldn't it be better to just store the identifier in app-state, like :page1, :page2 and then we can convert page1 and page2 to multimethods.

I just felt its more transparent on what is happening.

My two cents.

cheers

PatternSyntaxException

When running lein do clean, figwheel I get this error:

Caused by: java.util.regex.PatternSyntaxException: Unknown inline modifier near index 2
(?U)^[\p{Alpha}_$]

Using:

Leiningen 2.5.1 on Java 1.6.0_65 Java HotSpot(TM) 64-Bit Server VM

Does this require a certain version of Java maybe?

Refer dev namespace functions with repl init when using the dev profile

This is related to #38.

Haven't kept up with the recent changes so I haven't been aware of the switch to preferring lein-figwheel. I recently tried out the latest template and was lost on how to go about starting figwheel and the browser-repl.

My preferred workflow before was to use cider to jack-in from emacs and then starting figwheel from there as well as running the browser-repl with cider. Back then, the dev namespace functions were referred directly by the handler namespace. I have yet to figure out how to connect cider instead to the repl run by lein-figwheel.

Now that the dev functions are separate from the handler, I suggest referring them back instead through :repl-options with :init to save the trouble of having to refer them back in manually:

{:repl-options {:init-ns {{project-ns}}.handler
                :init (use '{{project-ns}}.dev)
                :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl{{{nrepl-middleware}}}]}

lein repl not working when template is used wiht +cljx

I am new to clojure and clojurescript and i have small problems/questions regarding this template.

I am able to make this temlate working with command "lein figwheel" but "lein repl" is not working. In docs it say that (browser-repl) is for optional development tools and i don't understand what optional development tools it actualy support because as i run lein figwheel(and open website) i get repl from which i can iteract with code running in browser. So do i have to run (browser-repl) manualy?

My second problem is i have no idea how to reload server code. As i change something in src/clj/handler.clj only way to reload server i know now is to restart lein figwheel. Probably there's better way and it would be great to mension it in documentation. Best would be to have same autoreload with server code as we have right now with client code but not sure if that is possible.

My third problem is automatic reloading of common code(cljx). I manage to have it live reload in client by running in separete terminal "lein cljx auto" but it would be nice if it would be integrated in some leinigen task together with start of figwheel.

Steps to reproduce problem with lein repl:

terminal_1> lein new reagent bug1 +cljx
terminal_1> cd bug1
terminal_1> lein cljx
terminal_1> lein figwheel
....
This is working ok

terminal_2> lein repl
Rewriting src/cljx to target/generated/clj (clj) with features #{clj} and 0 transformations.
Rewriting src/cljx to target/generated/cljs (cljs) with features #{cljs} and 1 transformations.
Error loading cljx.repl-middleware: Could not locate cljx/repl_middleware__init.class or cljx/repl_middleware.clj on classpath: 
Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: cljx.repl-middleware/wrap-cljx in this context, compiling:(/tmp/form-init8680695657060285587.clj:1:2987)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6651)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.access$100(Compiler.java:38)
    at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6050)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
    at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5217)
    at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3846)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.eval(Compiler.java:6700)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.load(Compiler.java:7130)
    at clojure.lang.Compiler.loadFile(Compiler.java:7086)
    at clojure.main$load_script.invoke(main.clj:274)
    at clojure.main$init_opt.invoke(main.clj:279)
    at clojure.main$initialize.invoke(main.clj:307)
    at clojure.main$null_opt.invoke(main.clj:342)
    at clojure.main$main.doInvoke(main.clj:420)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: cljx.repl-middleware/wrap-cljx in this context
    at clojure.lang.Util.runtimeException(Util.java:221)
    at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:659)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
    ... 34 more

How to run tests?

So, I've create previously a issue asking how, and still didn't managed to.

I've been playing and wrote: https://github.com/thiagofm/smartyper (check it out, should be fun to see one of your babies in action!)

I'm using this reagent template. It's said that I should be able to run clojurescript tests from inside the repl(I need that). Whenever I run lein figwheel, I get:

cljs.user=>

I try to switch to a namespace that contains the test that I want to run, I switch using the function in-ns. I can't call any functions there. But clojure doesn't tell me if this namespace exists or not. Also, I couldn't find a way to check if this namespace is existent.

I promise that once I figure that thing out, I'll contribute back to the community by actually teaching people how to do that.

Can you give me a hand? I currently see a lot of clojure videos in youtube but there's basically no video of somebody working with clojurescript, writing tests and stuff that I usually do in my workflow in another programming language.

Use (core/init!) instead of (force-update-all) for Figwheel reload

I spent a couple of hours trying to get Figwheel to work with my app, which didn't auto-reload even though everything looked just fine in the Figwheel logs and in the dev console. Then I stumbled upon reagent-project/reagent#94. Replacing (r/force-update-all) with (core/init!) in https://github.com/reagent-project/reagent-template/blob/master/src/leiningen/new/reagent/env/dev/cljs/reagent/dev.cljs#L11 solved my problem.

Since force-update-all doesn't re-render the root component and core/init! does, it seems to me that the latter is a safer default.

Run tests with something other than phantom (slimerjs)

I am building a project and utilizing storage-arom to interface with the browsers localStorage. This works as expected in the app. However, running tests with Phantom is not playing nice issue #10. Looking over the readme for clojurescript.test they recommend using slimjerjs. According an issue in the clojurescript.test repo slimerjs is a drop in replacement for phantomjs, but I seem to be missing something with the reagent-template. When I sub in slimerjs I only get the following outout when trying to run tests.

Compiling ClojureScript.
Running ClojureScript test: unit
Subprocess failed

Uncaught ReferenceError: goog is not defined in vanilla project

I get Uncaught ReferenceError: goog is not defined in javascript console for the vanilla project. I am assuming this is related to the:

<script type="text/javascript">goog.require("rproj.dev");</script>

line in the index.html (where rproj is the in "lein new reagent " )

I am new to this so it may be normal? But doesn't seem right.

"No value supplied for key: weasel.repl.websocket..."

I've been trying to get a browser repl working using a fresh "lein new reagent ..." project.

I get the following error whenever the (cemerick.piggieback/cljs-repl :repl-env (weasel.repl.websocket/repl-env)) line is run (manually with options in the repl, or otherwise):

Unhandled java.lang.IllegalArgumentException
   No value supplied for key:
   weasel.repl.websocket.WebsocketEnv@af47e25b

Reproduction:

$ lein new reagent test
$ cd test
$ lein figwheel
; open localhost:3449 and open a new terminal window
$ lein repl
...
test.repl=> (browser-repl)

IllegalArgumentException No value supplied for key: weasel.repl.websocket.WebsocketEnv@af47e25b  clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)

I don't imagine everyone is experiencing this so I am not sure how to track down the problem. Any ideas would be appreciated.

Does not work with IE9

You just see a console error saying "ClojureScript could not load :main, did you forget to specify :asset-path?"

(same installation working with chrome)

error when running template

Hi

I ran 'lein new reagent-template foo' and got the following error:

Could not locate clojure/data/priority_map__init.class or clojure/data/priority_map.clj on classpath

Not sure, if this is an environmental issue on my side or an issue with the template?

Clifford

hook-browser-navigation! not reloadable?

This comment precedes the definition of hook-browser-navigation!
;; History
;; must be called after routes have been defined

I thought this might cause a problem with fig wheel if routes were added to the code. This seems to be the case. Can anyone else confirm this? If so, is there a way to define this so that it will work when routes are added?

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.