8

I'd like to use figwheel to reload the frontend of an all-clojure project I'm playing with.

The backend serves a REST api and is organized as a bunch of components from which I create a system in my main function (I use duct to create the handler component). I want to pass state to my handlers using closures, but the only means of configuring figwheel to use my handler seems to be setting the ring-handler key in project.clj, and this requires that I pass a handler that is defined in a namespace at lein startup time.

So - is there a way to configure figwheel when I am doing my component startup? I'm still very new at Closure so it's likely I'm missing something in plain sight.

Passing state as parameter to a ring handler? is a similar question, but the answer there involves binding the handler a var at the top-level of a namespace, which I'm trying to avoid.

Community
  • 1
  • 1
Tom Dunham
  • 5,779
  • 2
  • 30
  • 27

2 Answers2

2

Figwheel doesn't need to be a handler. You can wrap a component that autobuilds while your server is up and running by dissecting this code into a component, a dependency to your server component so that it starts first. Note that this isn't officially supported. Running lein figwheel from the shell to boot a seperate JVM is the conventional usage.

If you are using Stuarts component lib I'd recommend to wrapping the ring handler from within a server component rather than via project.clj. Use this project or adapt the code snippet for a jetty component.

Notice that figwheel is devtooling, so in production you most likely want to serve a compiled js file built with e. g. lein-cljsbuild.

Leon Grapenthin
  • 9,246
  • 24
  • 37
0

James Reeves made a component for figwheel here

Duct-Figwheel-Component A component for the Figwheel development tool, designed to be used in the Duct framework (but can be used in any component-based system).

Installation

Add the following dependency to your project.clj:

[duct/figwheel-component "0.3.3"]

manandearth
  • 804
  • 1
  • 9
  • 25