Fork me on GitHub
#hoplon
<
2015-10-22
>
esp113:10:49

hi @alandipert, here’s how to reproduce a simple example to show reload not working for dependent namespaces:

esp113:10:04

lein new hoplon reload-test

esp113:10:42

create a new file

src/some/other.cljs.hl
with this content:

esp113:10:34

`(ns some.other) (defelem thing [ ] (h1 “hi”))`

esp113:10:58

oops let me try to format that better:

(ns some.other)

(defelem thing [_ _]
 (h1 “hi”))

esp113:10:15

then edit src/index.cljs.hl to look like:

(page “index.html”
  (:require [some.other :refer [thing]]))

(html
  (body
    (thing)))

esp113:10:38

then run

boot dev
and after loading the page in a browser, change the some.other/thing to return (h1 “somethingelse”)

esp113:10:43

what i see is that boot recompiles everything, the little cljs bauble pops up in the bottom corner of the browser page to indicate that reload has happened, but the dom content on the page does not change

esp119:10:53

i noticed when i only make changes to the thing defelem in the some.other namespace, the js console reports that index.html.out/some/other.js is reloaded, but the web page content does not change. it looks like what is happening is that the definition of the thing elem is updated, but since the top level index.html.out/hoplon/app_pages/_index_DOT_html.js where it is used is not updated, the dom content is not changed.

esp119:10:12

while this may make sense, this isn’t what i want - is there a way to have the top level page content be updated when dependencies change in other namespaces?

micha20:10:44

@esp1: you can use the with-page-load macro to trigger some action when things are reloaded

micha20:10:50

(with-page-load (.. js/location reload))

micha20:10:54

for instance

esp120:10:29

oh cool, thx!

esp120:10:21

i was looking at the on-jsload option on the boot-reload task, but i couldn’t figure out what entrypoint to use to reload the hoplon page. calling js directly works tho

micha20:10:41

you can use the local-storage function (https://github.com/hoplon/hoplon/blob/master/src/hoplon/storage_atom.cljs#L40-L42) to preserve state between reloads

micha20:10:53

that will make cells persistent

micha20:10:31

so like if you have a cell that holds some local stat like if you're filling out a form or drilling down in menus or something

micha20:10:51

you can just wrap it in that and when the page reloads the cell will have the same value

micha20:10:01

so you don't need to click on a bunch of things to get back where you were

micha20:10:07

after the reload