bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 210 forks source link

Using Figwheel system with other dependency libraries #623

Open ignorabilis opened 6 years ago

ignorabilis commented 6 years ago

Hi,

I can see that currently Figwheel has a nice integration with component. However since the usage of other dependency libraries like mount is rising I think some mechanism should come in place so that they can be supported as well. Of course integrating with each and every library wouldn't be possible, so I went briefly through the code and the following thing occurred to me: I think it is possible to untangle Figwheel's components start and stop logic from the component library. This start/stop logic should be then usable with any other dependency library or even manually, if that's your cup of tea.

benalbrecht commented 6 years ago

why not just wrap them? i.e. for integrant, just do something like this:

(defmethod ig/init-key ::figwheel [_ options]
  (component/start (figwheel/figwheel-system options)))
(defmethod ig/halt-key! ::figwheel [_ system]
  (component/stop system))
(defmethod ig/suspend-key! ::figwheel [_ system]
  (suspendable/suspend-system system))
(defmethod ig/resume-key ::figwheel [key opts old-opts old-impl]
  (if (= opts old-opts)
    (suspendable/resume-system old-impl)
    (do (ig/halt-key! key old-impl)
        (ig/init-key key opts))))

something similar should be possible with mount as well.

ignorabilis commented 6 years ago

Currently we are wrapping the whole figwheel system in a mount state. The thing is that this is not a clean solution - in dev mode we need to maintain both mount and component lifecycles. We are creating a fake dev component system and adding figwheel to it, then we are initializing component, etc. All this is done only for figwheel. It is not straightforward to hook up everything together & it feels very hacky to have two systems with different paradigms starting and stopping each other, etc.

I admit though that it can be made to work. It's just not the experience that a newbie would expect and he/she will either end up using figwheel + lein + component or mount + boot because it is hard to properly configure figwheel + mount.