Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaffans committed Mar 7, 2016
1 parent c5daa5e commit 8e30c49
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions _posts/2016-03-06-freq-words-2.markdown
Expand Up @@ -2,7 +2,7 @@
layout: post
title: Learn to read with ClojureScript, part 2
date: 2016-03-06
tags: [clojurescript, reagent, boot]
tags: [clojurescript, reagent, re-frame, boot, figwheel]
---

Almost a year ago, I [wrote about implementing a learning aid for children in elementary school using ClojureScript] [1].
Expand Down Expand Up @@ -47,8 +47,8 @@ of groups of words that the user can select for practice:

```
To keep track of the current words to show, I could have put the entire word array into the app state
and maybe pushed the currently selected group via a subscription to the view component. But as that constitutes
just static data, I instead just used a `:current-group` key and did a lookup in the view component of the actual
and pushed the currently selected group via a subscription to the view component. But as the actual words constitute
just static data, I instead just pushed a `:current-group` key to the view and let the view component do a lookup of the actual
words to show based on that. Re-frame stresses to keep view components dumb; I think a a simple lookup is dumb enough!

### Figwheel
Expand All @@ -57,7 +57,22 @@ I had some problems with Figwheel reloading at first. I used [secretary] [5] for
the root page reloads fine, reloading while on a route (`/#/group/4` for example) would result in a blank
page. I could fix that by removing the Fighweel reloading configuration from the Leiningen project file and
putting it in a `dev` namespace instead - it turns out that you shouldn't let Figwheel reset the whole app,
just re-mount the root node:
just re-mount the root node.

The `core` namespace has a function that performs initialisation of the app and mounts the root node:

```clojure
(defn mount-root
[]
(reagent/render [freq-words-2.views/app] (.getElementById js/document "app")))

(defn ^:export main []
(dispatch [:initialise-db])
(routes/init)
(mount-root))
```

The project file had this setting:

```clojure
;; project.clj:
Expand All @@ -66,6 +81,8 @@ just re-mount the root node:
:figwheel {:on-jsload "freq-words-2.core/main"}
```

The replacement for the above:

```clojure
;; dev.cljs:

Expand All @@ -75,6 +92,8 @@ just re-mount the root node:
:jsload-callback mount-root)
```

Check out the [sources] [9] to see the whole setup.

### Devtools, REPL

Another gem that I discovered during the development of this application was [cljs-devtools] [6].
Expand Down

0 comments on commit 8e30c49

Please sign in to comment.