Fork me on GitHub
#hoplon
<
2016-03-16
>
thedavidmeister09:03:33

@dm3: is there a repository of cool defelems somewhere?

dm309:03:00

the only one I know is hoplon/demos

dm309:03:04

in github

thedavidmeister11:03:06

is there a way to do :pre and :post conditions with defelem?

alandipert11:03:28

If it doesn't support them it should imo

thedavidmeister11:03:24

it didn’t seem to work for me

thedavidmeister11:03:37

but i would love for a second opinion simple_smile

thedavidmeister11:03:46

i like that you can get the compiler to remove them if the tests end up affecting performance

alandipert11:03:18

Yeah, doesn't look like it does. You could do it with a wrapper macro, otherwise a patch would be welcome

alandipert11:03:31

I might take a stab at doing it in hoplon this morning

alandipert11:03:47

Always good to limber up for the day with a little macrology

thedavidmeister12:03:10

if you manage to do it that would be awesome

thedavidmeister12:03:44

i wouldn’t even be looking at what i was going to use it for until the weekend

alandipert12:03:25

ok this is more involved than i thought 😅

alandipert12:03:33

definitely doable tho

thedavidmeister13:03:25

geez, if you’re saying that, i have no chance

alandipert13:03:08

aha no it's not that bad

alandipert13:03:14

doing it in hoplon is a little tricky because it needs to still handle not having pre/post

alandipert13:03:26

but you could also do it in a wrapper macro that wraps defelem

alandipert13:03:43

which would be a little easier since you don't need to support the non-pre/post way

thedavidmeister13:03:00

what do you mean handle not having it?

alandipert13:03:15

like, pre/post conditions should be optional

alandipert13:03:30

which means conditional behavior inside at least hoplon.core/elem macro

thedavidmeister13:03:42

oh yeah, that’s true

thedavidmeister13:03:59

but i’d want that too

alandipert13:03:02

maybe it could be called definitelyelem

thedavidmeister13:03:04

hey, maybe this is a simple q, maybe not

thedavidmeister13:03:09

but what does page actually do?

dm313:03:42

also there's an issue of elem functions being called with nil when items are removed from loop-tpl, so the pre conditions will fail (depending on what you check)

alandipert13:03:49

@thedavidmeister: boot-hoplon looks at it to figure what to call the html file, then turns the rest of it into an ns

thedavidmeister13:03:45

hmmm, do you guys normally have different pages

thedavidmeister13:03:56

or one page that changes depending on something in the URL or similar?

thedavidmeister13:03:21

i just noticed that my main page is noticeably slower than my other page that i made

thedavidmeister13:03:14

i think it’s todo with the way i’m doing caches

thedavidmeister13:03:48

i’m wondering if it would be a good idea to do a cell= on the URL fragment

thedavidmeister13:03:58

and turn each thing that is currently a page into a defelem

thedavidmeister13:03:29

and swap between them that way, and just put all of the caches on index.html

alandipert14:03:31

went another way with it - an inline conditions macro:

(defmacro with-conditions
  [conditions & body]
  {:pre [(map? conditions)]}
  (if-not *assert*
    `(do ~@body)
    (let [ret (gensym "ret")]
      `(do ~@(for [pre (:pre conditions)]
               `(when-not ~pre
                  (throw (ex-info "Precondition failed" {:pre '~pre}))))
           (let [~ret (do ~@body)]
             ~@(for [post (:post conditions)]
                 `(when-not (let [~'% ~ret] ~post)
                    (throw (ex-info "Postcondition failed" {:post '~post}))))
             ~ret)))))

(defn foop [x y]
  (with-conditions
    {:pre [(even? x)] :post [(odd? %)]}
    (+ x y)))

alandipert14:03:09

that lil guy respects *assert* and so elides the checks conditionally

thedavidmeister14:03:00

bonus points for showing expected vs. actual

thedavidmeister14:03:05

like what is does in testing 😛

thedavidmeister14:03:22

i think navigation cell is going to work

thedavidmeister14:03:14

(def current-hash (cell (.. js/window -location -hash)))
(cell= (set! (.. js/window -location -hash) current-hash))

thedavidmeister14:03:02

(c/defelem nav-link
  [attributes children]
  (let [{go :data-go href :href} attributes]
    (c/a
      :data-current-path (cell= (= go url/current-hash))
      :target (if href "_blank")
      :click #(reset! url/current-hash go)

      attributes
      children)))

thedavidmeister14:03:31

(cell=
    (if (= url/current-hash "#style-guide")
      (style-guide/style-guide)
      (index/index))))

thedavidmeister15:03:41

can’t believe i only just thought of that lol

thedavidmeister15:03:00

hmmm, making the site sluggish for some reason

thedavidmeister15:03:20

i suppose i’ll have to play around a bit more

symbit16:03:23

Is there a command line option to set BOOT_EMIT_TARGET=no/yes

symbit16:03:08

or better tie to a deftask?

raywillig17:03:48

@symbit: you could probably do something like export BOOT_EMIT_TARGET=no; boot do some tasks

raywillig17:03:17

but you might be better off setting that in your bashrc or .profile or whatever runs when you start a shell

symbit17:03:47

boot dev I need BOOT_EMIT_TARGET=no

symbit17:03:57

boot uberwar I need BOOT_EMIT_TARGET=yes

raywillig17:03:06

the idea with the env var is that automatic target dir is deprecated. so you would always have boot_emit_target set to no. when you make your uberwar you do boot uberwar targt

raywillig17:03:30

the target task is the standard way to emit artifacts to a target dir

symbit17:03:07

On windows when running boot dev for a hoplon app I need 'NO' so that my web page will refresh correctly on source code changes.

symbit17:03:16

When building the uberwar I call target. Are you saying target ignore what the state of BOOT_EMIT_TARGET is?

raywillig17:03:33

right, boot_emit_target is an environment var that when set to no will not automatically generate a target dir. when you explicitly call the target task, it's not automatic because you're telling boot what to do

raywillig17:03:15

i know that there have been certain, um, idiosyncrasies with windows but i don't know if they affect your mileage for this case. maybe check with @laforge49

symbit17:03:34

I test a bit more and let you know. Thank!

symbit17:03:31

@raywillig No dice. I removed BOOT_EMIT_TARGET=yes from boot.properties. The uberwar task runs fine creating the target dir.. But when running boot dev, load the page and make a change, java.nio.file.AccessDeniedException while trying to update \indexDOT_html.js

symbit17:03:17

I attempted to add (set-env! "BOOT_EMIT_TARGET" "no") at the top of the dev task but it doesn't work.

symbit17:03:02

trying one more thing...

raywillig18:03:31

@symbit: BOOT_EMIT_TARGET needs to be set outside of boot. it's an env var

raywillig18:03:07

so if you're using boot.properties (I think) you'll want to set BOOT_EMIT_TARGET=no

raywillig18:03:20

just removing yes is not the same as no

flyboarder18:03:41

@thedavidmeister: i know im a bit late to the convo, but hoplon already has route-cell which returns a formula cell which auto responds to hash change.

symbit19:03:50

sorry, @raywillig had no then changed to yes before 2.5.5 and then target change. So keeping it no works for both, however I see the reload is not working on the browser side.

Scot21:03:18

Thank you!